Open mechatroner opened 4 years ago
The output of gsutil retention get
is particularly useless without json. There's no clean way to create the matching retention set
command from the output of retention get
.
[Workaround]
For my automation script, I need to fetch some metadata(Content-Length
) from gsutil stat
command. Since the output is in yaml format, I am using yq
to parse whatever I need.
Eg:
OBJECT_PATH=gs://example-bucket/test.txt
gsutil stat $OBJECT_PATH | yq e ".\"$OBJECT_PATH\".Content-Length"
If you need it in JSON use yq -o=json
, also works for gsutil ls
command.
I would encourage giving gcloud storage
a try. It has the ls
command which is equivalent to the gsutil ls
command and provides a --json
flag for JSON output.
https://cloud.google.com/sdk/gcloud/reference/storage/ls
Please, consider adding support for json output which can be enabled with a CLI option or an environment variable. It would be especially beneficial for 'gsutil ls -L gs://bucket/object/path' command which currently produces output in a custom format which is hard to parse. BTW
aws
cli tool which provides similar functionality can produce JSON output inaws s3api list-objects
mode (and probably does this by default)