-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Storage: HMAC service account support #5284
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
Changes from 2 commits
11ffccc
fe560aa
2375c85
42569aa
a09334c
89d165b
7be7c2b
4bb6b44
91287cd
82259e4
46f4e29
df99b6d
ab32675
9e185bb
6d6fd4b
46fc073
cefd5ea
6dc9627
6998a83
0a8abee
16a3c60
af8bfd6
584015f
8760589
55f1ef4
5cfdea5
61187df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2709,17 +2709,117 @@ Blob create( | |
| */ | ||
| List<Acl> listAcls(BlobId blob); | ||
|
|
||
| /** | ||
| * Creates a new HMAC Key for the provided service account, including the secret key. Note that | ||
| * the secret key is only returned upon creation via this method. | ||
| * | ||
| * <p>Example of creating a new HMAC Key. | ||
| * | ||
| * <pre>{@code | ||
| * ServiceAccount serviceAccount = ServiceAccount.of("my-service-account@google.com"); | ||
| * | ||
| * HmacKey hmacKey = storage.createHmacKey(serviceAccount); | ||
| * | ||
| * String secretKey = hmacKey.getSecretKey(); | ||
| * HmacKey.HmacKeyMetadata metadata = hmacKey.getMetadata(); | ||
| * }</pre> | ||
| * | ||
| * @throws StorageException upon failure | ||
| */ | ||
| HmacKey createHmacKey(ServiceAccount serviceAccount); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include options for |
||
|
|
||
| /** | ||
| * Lists HMAC keys for a given service account. Note this returns {@code HmacKeyMetadata} objects, | ||
| * which do not contain secret keys. | ||
| * | ||
| * <p>Example of listing HMAC keys, specifying max results. | ||
| * | ||
| * <pre>{@code | ||
| * ServiceAccount serviceAccount = ServiceAccount.of("my-service-account@google.com"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. serviceAccount isn't used. |
||
| * | ||
| * Page<HmacKey.HmacKeyMetadata> metadataPage = storage.listHmacKeys(serviceAccount, null, 10); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add the boolean value of true for Deleted keys? |
||
| * for (HmacKey.HmacKeyMetadata hmacKeyMetadata : metadataPage.getValues()) { | ||
| * //do something with the metadata | ||
| * } | ||
| * }</pre> | ||
| * | ||
| * @param serviceAccount the service account whose HMAC keys to list | ||
| * @param pageToken the page from which to start results | ||
| * @param maxResults the maximum amount of results that can be returned by this request | ||
| * @param showDeletedKeys whether to show keys with the DELETED state in the result | ||
| * @throws StorageException upon failure | ||
| */ | ||
| Page<HmacKeyMetadata> listHmacKeys( | ||
| ServiceAccount serviceAccount, String pageToken, Long maxResults); | ||
| ServiceAccount serviceAccount, String pageToken, Long maxResults, boolean showDeletedKeys); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of curiosity, why the overload for showDeletedKeys?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My reasoning here is that the most common use case is going to be listHmacKeys(serviceAccount), so offering that along with one other signature to be more precise would meet most needs
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha that makes sense. What about defaulting to not showing deleted keys?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is already the default I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API defaults to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks @jkwlui and @JesseLovelace!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on other RPCs the Storage library has, the following parameters: Other HmacKey RPCs should have a similar Options parameter for the value userProject. At the moment it's ignored by the service but it's expected to be available. Given it would change the signature of the method I thought it'd be best to do it now rather than wait until later. (I'm open to opinions here). |
||
|
|
||
| /** | ||
| * Lists HMAC keys for a given service account. Note this returns {@code HmacKeyMetadata} objects, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lists active HMAC keys for a given service account. |
||
| * which do not contain secret keys. This is the same as calling {@code | ||
| * listHmacKeys(serviceAccount, null, null, false)}. | ||
| * | ||
| * <p>Example of listing HMAC keys. | ||
| * | ||
| * <pre>{@code | ||
| * ServiceAccount serviceAccount = ServiceAccount.of("my-service-account@google.com"); | ||
| * | ||
| * Page<HmacKey.HmacKeyMetadata> metadataPage = storage.listHmacKeys(serviceAccount); | ||
| * for (HmacKey.HmacKeyMetadata hmacKeyMetadata : metadataPage.getValues()) { | ||
| * //do something with the metadata | ||
| * } | ||
|
frankyn marked this conversation as resolved.
|
||
| * }</pre> | ||
| * | ||
| * @throws StorageException upon failure | ||
| */ | ||
| Page<HmacKeyMetadata> listHmacKeys(ServiceAccount serviceAccount); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Listing keys from all accounts can be accomplished by calling this with serviceAccount=null. I'll add a note about it in the documentation There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. That would really help, thank you! |
||
|
|
||
| /** | ||
| * Gets an HMAC key given its access id. Note that this returns a {@code HmacKeyMetadata} object, | ||
| * which does not contain the secret key. | ||
| * | ||
| * <p>Example of getting an HMAC key. | ||
| * | ||
| * <pre>{@code | ||
| * String hmacKeyAccessId = "my-access-id"; | ||
| * HmacKey.HmackeyMetadata hmacKeyMetadata = storage.getHmacKey(hmacKeyAccessId); | ||
|
frankyn marked this conversation as resolved.
|
||
| * }</pre> | ||
| * | ||
| * @throws StorageException upon failure | ||
| */ | ||
| HmacKeyMetadata getHmacKey(String accessId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include options for |
||
|
|
||
| /** | ||
| * Deletes an HMAC key given its access ID. Note that only an {@code INACTIVE} key can be deleted. | ||
| * Attempting to delete a key whose {@code HmacKey.HmacKeyState} is anything other than {@code | ||
| * INACTIVE} will fail. | ||
| * | ||
| * <p>Example of updating an HMAC key's state to INACTIVE and then deleting it. | ||
| * | ||
| * <pre>{@code | ||
| * String hmacKeyAccessId = "my-access-id"; | ||
| * HmacKey.HmacKeyMetadata hmacKeyMetadata = storage.getHmacKey(hmacKeyAccessId); | ||
| * | ||
| * storage.updateHmacKeyState(hmacKeyMetadata, HmacKey.HmacKeyState.INACTIVE); | ||
| * storage.deleteHmacKey(hmacKeyMetadata.getAccessId()); | ||
| * }</pre> | ||
| * | ||
| * @throws StorageException upon failure | ||
| */ | ||
| void deleteHmacKey(String accessId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include options for |
||
|
|
||
| /** | ||
| * Updates the state of an HMAC key and returns the updated metadata. | ||
| * | ||
| * <p>Example of updating the state of a newly created HMAC key. | ||
| * | ||
| * <pre>{@code | ||
| * ServiceAccount serviceAccount = ServiceAccount.of("my-service-account@google.com"); | ||
| * HmacKey key = storage.createHmacKey(serviceAccount); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perform a Get request instead of a create. |
||
| * | ||
| * storage.updateHmacKeyState(hmacKey.getMetadata(), HmacKey.HmacKeyState.INACTIVE); | ||
| * }</pre> | ||
| * | ||
| * @throws StorageException upon failure | ||
| */ | ||
| HmacKeyMetadata updateHmacKeyState( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice helper method! (no action required). |
||
| final HmacKeyMetadata hmacKeyMetadata, final HmacKey.HmacKeyState state); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Include options for |
||
| /** | ||
|
|
||
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.
Not super familiar with documenting Java code, but can we add a note saying the
secretis only available on creation?Uh oh!
There was an error while loading. Please reload this page.
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.
Yeah--I'm planning to add the documentation once the code is otherwise approved