-
Notifications
You must be signed in to change notification settings - Fork 6.6k
storage: Add Boto3 List Objects in GCS #2041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
storage/s3-sdk/list_gcs_objects.py
Outdated
|
||
# Print object names | ||
print("Objects:") | ||
for bucket in response["Contents"]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is listing objects in a bucket, it would be clearer for this to say for object in ...
instead of for bucket in ...
. (Or another word for object, just not bucket.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or "blobs". That's a word I like.
@@ -78,8 +78,10 @@ def generate_signed_url(service_account_file, bucket_name, object_name, | ||
ordered_headers = collections.OrderedDict(sorted(headers.items())) | ||
for k, v in ordered_headers.items(): | ||
lower_k = str(k).lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lower_k and strip_v? name and value would be better variable name.
canonical_headers += '{}:{}\n'.format(lower_k, strip_v) | ||
canonical_headers = "host:storage.googleapis.com\nx-goog-encryption-algorithm:AES56\n" # "x-goog-encryption-key:AAryxNglNkXQY0Wa+h9+7BLSFMhCzPo22MtXUWjOBbI=\nx-goog-encryption-key-sha256:QlCdVONb17U1aCTAjrFvMbnxW/Oul8VAvnG1875WJ3k=\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this comment here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be += instead of =? Otherwise earlier values are lost.
@@ -88,6 +90,7 @@ def generate_signed_url(service_account_file, bucket_name, object_name, | ||
lower_k = str(k).lower() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar issue with names. Also, these aren't signed_headers, they're names of the headers that need to be signed, so a different name would be more clear. And no need to use items() since you just want the keys, no values.
@@ -88,6 +90,7 @@ def generate_signed_url(service_account_file, bucket_name, object_name, | ||
lower_k = str(k).lower() | ||
signed_headers += '{};'.format(lower_k) | ||
signed_headers = signed_headers[:-1] # remove trailing ';' | ||
signed_headers = 'host;x-goog-encryption-algorithm' #;x-goog-encryption-key;x-goog-encryption-key-sha256' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, why the comment? If not used, shouldn't they be removed?
@@ -105,7 +108,7 @@ def generate_signed_url(service_account_file, bucket_name, object_name, | ||
for k, v in ordered_query_parameters.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable names. Something like safe_name, safe_value would be clearer than encoded_k and encoded_v
@@ -159,9 +164,21 @@ def generate_signed_url(service_account_file, bucket_name, object_name, | ||
parser.add_argument('expiration', help='Expiration Time.') | ||
|
||
args = parser.parse_args() | ||
headers = {'X-Goog-Encryption-Key': 'AAryxNglNkXQY0Wa+h9+7BLSFMhCzPo22MtXUWjOBbI=', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't usually include secrets in samples, instead using a placeholder or getting them from command line arguments or environment variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi @engelke,
Sample to list objects in GCS using S3 SDK.