-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
11ffccc
Storage: HMAC service account support
JesseLovelace fe560aa
Storage: HMAC service account support
JesseLovelace 2375c85
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 42569aa
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace a09334c
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 89d165b
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 7be7c2b
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 4bb6b44
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 91287cd
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 82259e4
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 46f4e29
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace df99b6d
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace ab32675
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 9e185bb
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 6d6fd4b
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 46fc073
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace cefd5ea
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 6dc9627
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 6998a83
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 0a8abee
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 16a3c60
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace af8bfd6
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 584015f
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 8760589
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 55f1ef4
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 5cfdea5
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace 61187df
Merge branch 'hmacsa' of github.com:googleapis/google-cloud-java into…
JesseLovelace File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,3 +25,8 @@ env_vars: { | |
| key: "GOOGLE_APPLICATION_CREDENTIALS" | ||
| value: "keystore/73713_java_it_service_account" | ||
| } | ||
|
|
||
| env_vars: { | ||
| key: "IT_SERVICE_ACCOUNT_EMAIL" | ||
| value: "[email protected]" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
326 changes: 326 additions & 0 deletions
326
...le-cloud-clients/google-cloud-storage/src/main/java/com/google/cloud/storage/HmacKey.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,326 @@ | ||
| /* | ||
| * Copyright 2019 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage; | ||
|
|
||
| import com.google.api.client.util.DateTime; | ||
| import java.io.Serializable; | ||
| import java.util.Objects; | ||
|
|
||
| /** HMAC key for a service account. */ | ||
| public class HmacKey implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = -1809610424373783062L; | ||
| private final String secretKey; | ||
| private final HmacKeyMetadata metadata; | ||
|
|
||
| private HmacKey(Builder builder) { | ||
| this.secretKey = builder.secretKey; | ||
| this.metadata = builder.metadata; | ||
| } | ||
|
|
||
| public static Builder newBuilder(String secretKey) { | ||
| return new Builder(secretKey); | ||
| } | ||
|
|
||
| /** Builder for {@code HmacKey} objects. * */ | ||
| public static class Builder { | ||
| private String secretKey; | ||
| private HmacKeyMetadata metadata; | ||
|
|
||
| private Builder(String secretKey) { | ||
| this.secretKey = secretKey; | ||
| } | ||
|
|
||
| public Builder setSecretKey(String secretKey) { | ||
| this.secretKey = secretKey; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setMetadata(HmacKeyMetadata metadata) { | ||
| this.metadata = metadata; | ||
| return this; | ||
| } | ||
|
|
||
| /** Creates an {@code HmacKey} object from this builder. * */ | ||
| public HmacKey build() { | ||
| return new HmacKey(this); | ||
| } | ||
| } | ||
|
|
||
| /** Returns the secret key associated with this HMAC key. * */ | ||
| public String getSecretKey() { | ||
| return secretKey; | ||
| } | ||
|
|
||
| /** Returns the metadata associated with this HMAC key. * */ | ||
| public HmacKeyMetadata getMetadata() { | ||
| return metadata; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(secretKey, metadata); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| final HmacKeyMetadata other = (HmacKeyMetadata) obj; | ||
| return Objects.equals(this.secretKey, secretKey) && Objects.equals(this.metadata, metadata); | ||
| } | ||
|
|
||
| com.google.api.services.storage.model.HmacKey toPb() { | ||
| com.google.api.services.storage.model.HmacKey hmacKey = | ||
| new com.google.api.services.storage.model.HmacKey(); | ||
| hmacKey.setSecret(this.secretKey); | ||
|
|
||
| if (metadata != null) { | ||
| hmacKey.setMetadata(metadata.toPb()); | ||
| } | ||
|
|
||
| return hmacKey; | ||
| } | ||
|
|
||
| static HmacKey fromPb(com.google.api.services.storage.model.HmacKey hmacKey) { | ||
| return HmacKey.newBuilder(hmacKey.getSecret()) | ||
| .setMetadata(HmacKeyMetadata.fromPb(hmacKey.getMetadata())) | ||
| .build(); | ||
| } | ||
|
|
||
| public enum HmacKeyState { | ||
| ACTIVE("ACTIVE"), | ||
| INACTIVE("INACTIVE"), | ||
| DELETED("DELETED"); | ||
|
|
||
| private final String state; | ||
|
|
||
| HmacKeyState(String state) { | ||
| this.state = state; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The metadata for a service account HMAC key. This class holds all data associated with an HMAC | ||
| * key other than the secret key. | ||
| */ | ||
| public static class HmacKeyMetadata implements Serializable { | ||
|
|
||
| private static final long serialVersionUID = 4571684785352640737L; | ||
| private final String accessId; | ||
| private final String etag; | ||
| private final String id; | ||
| private final String projectId; | ||
| private final ServiceAccount serviceAccount; | ||
| private final HmacKeyState state; | ||
| private final Long createTime; | ||
| private final Long updateTime; | ||
|
|
||
| private HmacKeyMetadata(Builder builder) { | ||
| this.accessId = builder.accessId; | ||
| this.etag = builder.etag; | ||
| this.id = builder.id; | ||
| this.projectId = builder.projectId; | ||
| this.serviceAccount = builder.serviceAccount; | ||
| this.state = builder.state; | ||
| this.createTime = builder.createTime; | ||
| this.updateTime = builder.updateTime; | ||
| } | ||
|
|
||
| public static Builder newBuilder(ServiceAccount serviceAccount) { | ||
| return new Builder(serviceAccount); | ||
| } | ||
|
|
||
| public Builder toBuilder() { | ||
| return new Builder(this); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(accessId, projectId); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| if (this == obj) { | ||
| return true; | ||
| } | ||
| if (obj == null || getClass() != obj.getClass()) { | ||
| return false; | ||
| } | ||
| final HmacKeyMetadata other = (HmacKeyMetadata) obj; | ||
| return Objects.equals(this.accessId, other.accessId) | ||
| && Objects.equals(this.etag, other.etag) | ||
| && Objects.equals(this.id, other.id) | ||
| && Objects.equals(this.projectId, other.projectId) | ||
| && Objects.equals(this.serviceAccount, other.serviceAccount) | ||
| && Objects.equals(this.state, other.state) | ||
| && Objects.equals(this.createTime, other.createTime) | ||
| && Objects.equals(this.updateTime, other.updateTime); | ||
| } | ||
|
|
||
| public com.google.api.services.storage.model.HmacKeyMetadata toPb() { | ||
| com.google.api.services.storage.model.HmacKeyMetadata metadata = | ||
| new com.google.api.services.storage.model.HmacKeyMetadata(); | ||
| metadata.setAccessId(this.accessId); | ||
| metadata.setEtag(this.etag); | ||
| metadata.setId(this.id); | ||
| metadata.setProjectId(this.projectId); | ||
| metadata.setServiceAccountEmail( | ||
| this.serviceAccount == null ? null : this.serviceAccount.getEmail()); | ||
| metadata.setState(this.state == null ? null : this.state.toString()); | ||
| metadata.setTimeCreated(this.createTime == null ? null : new DateTime(this.createTime)); | ||
| metadata.setUpdated(this.updateTime == null ? null : new DateTime(this.updateTime)); | ||
|
|
||
| return metadata; | ||
| } | ||
|
|
||
| static HmacKeyMetadata fromPb(com.google.api.services.storage.model.HmacKeyMetadata metadata) { | ||
| return newBuilder(ServiceAccount.of(metadata.getServiceAccountEmail())) | ||
| .setAccessId(metadata.getAccessId()) | ||
| .setCreateTime(metadata.getTimeCreated().getValue()) | ||
| .setEtag(metadata.getEtag()) | ||
| .setId(metadata.getId()) | ||
| .setProjectId(metadata.getProjectId()) | ||
| .setState(HmacKeyState.valueOf(metadata.getState())) | ||
| .setUpdateTime(metadata.getUpdated().getValue()) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the access id for this HMAC key. This is the id needed to get or delete the key. * | ||
| */ | ||
| public String getAccessId() { | ||
| return accessId; | ||
| } | ||
|
|
||
| /** | ||
| * Returns HTTP 1.1 Entity tag for this HMAC key. | ||
| * | ||
| * @see <a href="http://tools.ietf.org/html/rfc2616#section-3.11">Entity Tags</a> | ||
| */ | ||
| public String getEtag() { | ||
| return etag; | ||
| } | ||
|
|
||
| /** Returns the resource name of this HMAC key. * */ | ||
| public String getId() { | ||
| return id; | ||
| } | ||
|
|
||
| /** Returns the project id associated with this HMAC key. * */ | ||
| public String getProjectId() { | ||
| return projectId; | ||
| } | ||
|
|
||
| /** Returns the service account associated with this HMAC key. * */ | ||
| public ServiceAccount getServiceAccount() { | ||
| return serviceAccount; | ||
| } | ||
|
|
||
| /** Returns the current state of this HMAC key. * */ | ||
| public HmacKeyState getState() { | ||
| return state; | ||
| } | ||
|
|
||
| /** Returns the creation time of this HMAC key. * */ | ||
| public Long getCreateTime() { | ||
| return createTime; | ||
| } | ||
|
|
||
| /** Returns the last updated time of this HMAC key. * */ | ||
| public Long getUpdateTime() { | ||
| return updateTime; | ||
| } | ||
|
|
||
| /** Builder for {@code HmacKeyMetadata} objects. * */ | ||
| public static class Builder { | ||
| private String accessId; | ||
| private String etag; | ||
| private String id; | ||
| private String projectId; | ||
| private ServiceAccount serviceAccount; | ||
| private HmacKeyState state; | ||
| private Long createTime; | ||
| private Long updateTime; | ||
|
|
||
| private Builder(ServiceAccount serviceAccount) { | ||
| this.serviceAccount = serviceAccount; | ||
| } | ||
|
|
||
| private Builder(HmacKeyMetadata metadata) { | ||
| this.accessId = metadata.accessId; | ||
| this.etag = metadata.etag; | ||
| this.id = metadata.id; | ||
| this.projectId = metadata.projectId; | ||
| this.serviceAccount = metadata.serviceAccount; | ||
| this.state = metadata.state; | ||
| this.createTime = metadata.createTime; | ||
| this.updateTime = metadata.updateTime; | ||
| } | ||
|
|
||
| public Builder setAccessId(String accessId) { | ||
| this.accessId = accessId; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setEtag(String etag) { | ||
| this.etag = etag; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setId(String id) { | ||
| this.id = id; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setServiceAccount(ServiceAccount serviceAccount) { | ||
| this.serviceAccount = serviceAccount; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setState(HmacKeyState state) { | ||
| this.state = state; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setCreateTime(long createTime) { | ||
| this.createTime = createTime; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setProjectId(String projectId) { | ||
| this.projectId = projectId; | ||
| return this; | ||
| } | ||
|
|
||
| /** Creates an {@code HmacKeyMetadata} object from this builder. * */ | ||
| public HmacKeyMetadata build() { | ||
| return new HmacKeyMetadata(this); | ||
| } | ||
|
|
||
| public Builder setUpdateTime(long updateTime) { | ||
| this.updateTime = updateTime; | ||
| return this; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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