GeezerVison is showing github.com — Add factory methods for primitive roles, other minor fixes · googleapis/google-cloud-java@b3c94f6
File treeExpand file treeCollapse file tree Open diff view settings main/java/com/google/cloud test/java/com/google/cloud
google-cloud-examples/src/main/java/com/google/cloud/examples/resourcemanager/snippets google-cloud-resourcemanager main/java/com/google/cloud/resourcemanager test/java/com/google/cloud/resourcemanager
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: google-cloud-core/src/main/java/com/google/cloud/Policy.java +9-9Lines changed: 9 additions & 9 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 39 | 39 | import java.util.Set; | 40 | 40 |
| 41 | 41 | /** | 42 | | - * Base class for Identity and Access Management (IAM) policies. IAM policies are used to specify | 43 | | - * access settings for Cloud Platform resources. A policy is a map of bindings. A binding assigns | 44 | | - * a set of identities to a role, where the identities can be user accounts, Google groups, Google | 45 | | - * domains, and service accounts. A role is a named list of permissions defined by IAM. | | 42 | + * Class for Identity and Access Management (IAM) policies. IAM policies are used to specify access | | 43 | + * settings for Cloud Platform resources. A policy is a map of bindings. A binding assigns a set of | | 44 | + * identities to a role, where the identities can be user accounts, Google groups, Google domains, | | 45 | + * and service accounts. A role is a named list of permissions defined by IAM. | 46 | 46 | * | 47 | 47 | * @see <a href="https://cloud.google.com/iam/reference/rest/v1/Policy">Policy</a> | 48 | 48 | */ | @@ -88,7 +88,7 @@ protected Policy fromPb(com.google.iam.v1.Policy policyPb) { | 88 | 88 | } | 89 | 89 | return builder() | 90 | 90 | .bindings(bindings) | 91 | | - .etag(policyPb.getEtag().size() == 0 ? null : policyPb.getEtag().toStringUtf8()) | | 91 | + .etag(policyPb.getEtag().isEmpty() ? null : policyPb.getEtag().toStringUtf8()) | 92 | 92 | .version(policyPb.getVersion()) | 93 | 93 | .build(); | 94 | 94 | } | @@ -250,14 +250,14 @@ public Builder toBuilder() { | 250 | 250 | } | 251 | 251 |
| 252 | 252 | /** | 253 | | - * The map of bindings that comprises the policy. | | 253 | + * Returns the map of bindings that comprises the policy. | 254 | 254 | */ | 255 | 255 | public Map<Role, Set<Identity>> bindings() { | 256 | 256 | return bindings; | 257 | 257 | } | 258 | 258 |
| 259 | 259 | /** | 260 | | - * The policy's etag. | | 260 | + * Returns the policy's etag. | 261 | 261 | * | 262 | 262 | * <p>Etags are used for optimistic concurrency control as a way to help prevent simultaneous | 263 | 263 | * updates of a policy from overwriting each other. It is strongly suggested that systems make | @@ -272,8 +272,8 @@ public String etag() { | 272 | 272 | } | 273 | 273 |
| 274 | 274 | /** | 275 | | - * Sets the version of the policy. The default version is 0, meaning only the "owner", "editor", | 276 | | - * and "viewer" roles are permitted. If the version is 1, you may also use other roles. | | 275 | + * Returns the version of the policy. The default version is 0, meaning only the "owner", | | 276 | + * "editor", and "viewer" roles are permitted. If the version is 1, you may also use other roles. | 277 | 277 | */ | 278 | 278 | public int version() { | 279 | 279 | return version; | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-core/src/main/java/com/google/cloud/Role.java +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 27 | 27 | * | 28 | 28 | * @see <a href="https://cloud.google.com/iam/docs/viewing-grantable-roles">Viewing the Grantable | 29 | 29 | * Roles on Resources</a> | | 30 | + * @see <a href="https://cloud.google.com/iam/docs/understanding-roles">Understanding Roles</a> | 30 | 31 | */ | 31 | 32 | public final class Role implements Serializable { | 32 | 33 |
| @@ -47,6 +48,36 @@ public String value() { | 47 | 48 | return value; | 48 | 49 | } | 49 | 50 |
| | 51 | + /** | | 52 | + * Returns the viewer role. Encapsulates the permission for read-only actions that preserve state | | 53 | + * of a resource. | | 54 | + * | | 55 | + * @see <a href="https://cloud.google.com/iam/docs/understanding-roles">Understanding Roles</a> | | 56 | + */ | | 57 | + public static Role viewer() { | | 58 | + return of("viewer"); | | 59 | + } | | 60 | + | | 61 | + /** | | 62 | + * Returns the editor role. Encapsulates all viewer's permissions and permissions for actions that | | 63 | + * modify the state of a resource. | | 64 | + * | | 65 | + * @see <a href="https://cloud.google.com/iam/docs/understanding-roles">Understanding Roles</a> | | 66 | + */ | | 67 | + public static Role editor() { | | 68 | + return of("editor"); | | 69 | + } | | 70 | + | | 71 | + /** | | 72 | + * Returns the owner role. Encapsulates all editor's permissions and permissions to manage access | | 73 | + * control for a resource or manage the billing options for a project. | | 74 | + * | | 75 | + * @see <a href="https://cloud.google.com/iam/docs/understanding-roles">Understanding Roles</a> | | 76 | + */ | | 77 | + public static Role owner() { | | 78 | + return of("owner"); | | 79 | + } | | 80 | + | 50 | 81 | /** | 51 | 82 | * Returns a new role given its string value. | 52 | 83 | * | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -43,9 +43,9 @@ public class PolicyTest { | 43 | 43 | | 44 | 44 | | 45 | 45 | private static final Identity DOMAIN = Identity.domain("google.com"); | 46 | | - private static final Role VIEWER = Role.of("viewer"); | 47 | | - private static final Role EDITOR = Role.of("editor"); | 48 | | - private static final Role OWNER = Role.of("owner"); | | 46 | + private static final Role VIEWER = Role.viewer(); | | 47 | + private static final Role EDITOR = Role.editor(); | | 48 | + private static final Role OWNER = Role.owner(); | 49 | 49 | private static final Map<Role, ImmutableSet<Identity>> BINDINGS = ImmutableMap.of( | 50 | 50 | VIEWER, | 51 | 51 | ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS), | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-core/src/test/java/com/google/cloud/RoleTest.java +15Lines changed: 15 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -36,6 +36,21 @@ public void testOf() { | 36 | 36 | compareRoles(OWNER, Role.of("roles/owner")); | 37 | 37 | } | 38 | 38 |
| | 39 | + @Test | | 40 | + public void testViewer() { | | 41 | + assertEquals("roles/viewer", Role.viewer().value()); | | 42 | + } | | 43 | + | | 44 | + @Test | | 45 | + public void testEditor() { | | 46 | + assertEquals("roles/editor", Role.editor().value()); | | 47 | + } | | 48 | + | | 49 | + @Test | | 50 | + public void testOwner() { | | 51 | + assertEquals("roles/owner", Role.owner().value()); | | 52 | + } | | 53 | + | 39 | 54 | @Test(expected = NullPointerException.class) | 40 | 55 | public void testOfNullValue() { | 41 | 56 | Role.of(null); | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -39,7 +39,7 @@ public class SerializationTest extends BaseSerializationTest { | 39 | 39 | private static final SigningException SIGNING_EXCEPTION = | 40 | 40 | new SigningException("message", BASE_SERVICE_EXCEPTION); | 41 | 41 | private static final RetryParams RETRY_PARAMS = RetryParams.defaultInstance(); | 42 | | - private static final Role SOME_ROLE = Role.of("viewer"); | | 42 | + private static final Role SOME_ROLE = Role.viewer(); | 43 | 43 | private static final Policy SOME_IAM_POLICY = Policy.builder().build(); | 44 | 44 | private static final WaitForOption CHECKING_PERIOD = | 45 | 45 | WaitForOption.checkEvery(42, TimeUnit.SECONDS); | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-examples/src/main/java/com/google/cloud/examples/resourcemanager/snippets/ModifyPolicy.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -49,7 +49,7 @@ public static void main(String... args) { | 49 | 49 | // Add a viewer | 50 | 50 | Policy.Builder modifiedPolicy = policy.toBuilder(); | 51 | 51 | Identity newViewer = Identity.user("<insert user's email address here>"); | 52 | | - modifiedPolicy.addIdentity(Role.of("roles/viewer"), newViewer); | | 52 | + modifiedPolicy.addIdentity(Role.viewer(), newViewer); | 53 | 53 |
| 54 | 54 | // Write policy | 55 | 55 | Policy updatedPolicy = project.replacePolicy(modifiedPolicy.build()); | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-resourcemanager/README.md +1-1Lines changed: 1 addition & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -186,7 +186,7 @@ Policy policy = project.getPolicy(); | 186 | 186 | // Add a viewer | 187 | 187 | Policy.Builder modifiedPolicy = policy.toBuilder(); | 188 | 188 | Identity newViewer = Identity.user("<insert user's email address here>"); | 189 | | -modifiedPolicy.addIdentity(Role.of("roles/viewer"), newViewer); | | 189 | +modifiedPolicy.addIdentity(Role.viewer(), newViewer); | 190 | 190 |
| 191 | 191 | // Write policy | 192 | 192 | Policy updatedPolicy = project.replacePolicy(modifiedPolicy.build()); | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -303,7 +303,7 @@ public static ProjectListOption fields(ProjectField... fields) { | 303 | 303 | * <pre> {@code | 304 | 304 | * Policy currentPolicy = resourceManager.getPolicy("my-project-id"); | 305 | 305 | * Policy modifiedPolicy = current.toBuilder() | 306 | | - | | 306 | + | 307 | 307 | * .build(); | 308 | 308 | * Policy newPolicy = resourceManager.replacePolicy("my-project-id", modified); | 309 | 309 | * } | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-resourcemanager/src/test/java/com/google/cloud/resourcemanager/PolicyMarshallerTest.java +3-3Lines changed: 3 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -35,9 +35,9 @@ public class PolicyMarshallerTest { | 35 | 35 | | 36 | 36 | | 37 | 37 | private static final Identity DOMAIN = Identity.domain("google.com"); | 38 | | - private static final Role VIEWER = Role.of("viewer"); | 39 | | - private static final Role EDITOR = Role.of("editor"); | 40 | | - private static final Role OWNER = Role.of("owner"); | | 38 | + private static final Role VIEWER = Role.viewer(); | | 39 | + private static final Role EDITOR = Role.editor(); | | 40 | + private static final Role OWNER = Role.owner(); | 41 | 41 | private static final Role SOME_ROLE = Role.of("roles/some-role"); | 42 | 42 | private static final Policy SIMPLE_POLICY = Policy.builder() | 43 | 43 | .addIdentity(OWNER, USER) | |
Collapse file Copy file name to clipboardExpand all lines: google-cloud-resourcemanager/src/test/java/com/google/cloud/resourcemanager/ProjectTest.java +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -57,8 +57,8 @@ public class ProjectTest { | 57 | 57 | private static final Identity SERVICE_ACCOUNT = | 58 | 58 | | 59 | 59 | private static final Policy POLICY = Policy.builder() | 60 | | - .addIdentity(Role.of("roles/owner"), USER) | 61 | | - .addIdentity(Role.of("roles/editor"), SERVICE_ACCOUNT) | | 60 | + .addIdentity(Role.owner(), USER) | | 61 | + .addIdentity(Role.editor(), SERVICE_ACCOUNT) | 62 | 62 | .build(); | 63 | 63 |
| 64 | 64 | private ResourceManager serviceMockReturnsOptions = createStrictMock(ResourceManager.class); | |
|