-
Notifications
You must be signed in to change notification settings - Fork 1.1k
storage: hmac service account snippets #6088
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
|
|
||
| /** Example of creating an HMAC key for a service account * */ | ||
| public HmacKey createHmacKey(String serviceAccountEmail) throws StorageException { | ||
| // [START storage_create_hmac_key] |
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.
I'm guessing this is part of some doc set somewhere? (A filed issue explaining all this would be helpful.) Is there documentation for how the example inclusion works?
| Storage storage = StorageOptions.getDefaultInstance().getService(); | ||
|
|
||
| // The service account email for which the new HMAC key will be created. | ||
| // String serviceAccountEmail = "service-account@iam.gserviceaccount.com"; |
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 commented out?
...cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java
Outdated
Show resolved
Hide resolved
...cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java
Outdated
Show resolved
Hide resolved
| Storage storage = StorageOptions.getDefaultInstance().getService(); | ||
|
|
||
| // The access ID of the HMAC key, e.g. "GOOG0234230X00" | ||
| // String accessId = "GOOG0234230X00"; |
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 commented out?
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.
The code section between the START and END region tags are extracted and put on the doc site. When copy and pasting the sample into their own project, the developer is expected to uncomment the variable declaration and replace the value with their own.
...mples/src/test/java/com/google/cloud/examples/storage/snippets/ITStorageHmacKeySnippets.java
Show resolved
Hide resolved
...mples/src/test/java/com/google/cloud/examples/storage/snippets/ITStorageHmacKeySnippets.java
Show resolved
Hide resolved
...mples/src/test/java/com/google/cloud/examples/storage/snippets/ITStorageHmacKeySnippets.java
Outdated
Show resolved
Hide resolved
...mples/src/test/java/com/google/cloud/examples/storage/snippets/ITStorageHmacKeySnippets.java
Outdated
Show resolved
Hide resolved
...mples/src/test/java/com/google/cloud/examples/storage/snippets/ITStorageHmacKeySnippets.java
Outdated
Show resolved
Hide resolved
Codecov Report
@@ Coverage Diff @@
## master #6088 +/- ##
============================================
+ Coverage 47.38% 47.4% +0.01%
+ Complexity 27182 27123 -59
============================================
Files 2523 2501 -22
Lines 274581 273249 -1332
Branches 31380 31185 -195
============================================
- Hits 130123 129544 -579
+ Misses 134850 134174 -676
+ Partials 9608 9531 -77
Continue to review full report at Codecov.
|
frankyn
left a comment
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.
Overall LGTM.
Please add service account for samples IT to kokoro builds in case they are re-enabled. Marking that as a requested change.
...cloud-examples/src/main/java/com/google/cloud/examples/storage/snippets/StorageSnippets.java
Outdated
Show resolved
Hide resolved
|
@frankyn I reverted the commit to add the env var for integration tests since it's not whitelisted in the Kokoro configs in the backend. This will not block this, we just need an action item for when we add sample test running on Kokoro. Please take another look :) |
frankyn
left a comment
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.
Small nits. Overall LGTM.
| } | ||
|
|
||
| /** Example of retrieving the metadata of an existing HMAC key. * */ | ||
| public HmacKeyMetadata getHmacKey(String accessId) throws StorageException { |
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.
pass in projectId in this example and the others as well. It's a small level of detail but it keeps consistency.
| return newMetadata; | ||
| } | ||
|
|
||
| public Page<HmacKeyMetadata> listHmacKeys(String serviceAccountEmail) throws StorageException { |
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.
use projectId instead of serviceAccountEmail.
|
I couldn't find an option to provide |
frankyn
left a comment
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.
Thanks @jkwlui two nits.
| // | ||
| // The ID of the project to which the service account belongs. | ||
| // String projectId = "project-id"; | ||
| HmacKeyMetadata metadata = storage.getHmacKey(accessId); |
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.
set projectId here.
| Storage storage = StorageOptions.getDefaultInstance().getService(); | ||
|
|
||
| // The service account to list HMAC keys for. | ||
| // String serviceAccountEmail = "service-account@iam.gserviceaccount.com"; |
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.
This deviates a bit from other samples.
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.
in what way?
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.
Node.js: https://github.com/googleapis/nodejs-storage/blob/master/samples/hmacKeysList.js#L24
Ruby: https://github.com/GoogleCloudPlatform/ruby-docs-samples/blob/master/storage/hmac.rb#L15
Python: https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/storage/cloud-client/hmac.py#L22
Service account parameter isn't set.
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.
Gotcha! Nice catch.
|
I don't think the test failure is due to this PR. Can someone with admin privileges add |
Uh oh!
There was an error while loading. Please reload this page.