GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add factory methods for primitive roles, other minor fixes · googleapis/google-cloud-java@b3c94f6

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • google-cloud-core/src
    • main/java/com/google/cloud
      • Policy.java
      • Role.java
    • test/java/com/google/cloud
      • PolicyTest.java
      • RoleTest.java
      • SerializationTest.java
  • google-cloud-examples/src/main/java/com/google/cloud/examples/resourcemanager/snippets
    • ModifyPolicy.java
  • google-cloud-resourcemanager
    • README.md
    • src
      • main/java/com/google/cloud/resourcemanager
        • ResourceManager.java
      • test/java/com/google/cloud/resourcemanager
        • PolicyMarshallerTest.java
        • ProjectTest.java
        • ResourceManagerImplTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎google-cloud-core/src/main/java/com/google/cloud/Policy.java‎

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 numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
import java.util.Set;
4040

4141
/**
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.
4646
*
4747
* @see <a href="https://cloud.google.com/iam/reference/rest/v1/Policy">Policy</a>
4848
*/
@@ -88,7 +88,7 @@ protected Policy fromPb(com.google.iam.v1.Policy policyPb) {
8888
}
8989
return builder()
9090
.bindings(bindings)
91-
.etag(policyPb.getEtag().size() == 0 ? null : policyPb.getEtag().toStringUtf8())
91+
.etag(policyPb.getEtag().isEmpty() ? null : policyPb.getEtag().toStringUtf8())
9292
.version(policyPb.getVersion())
9393
.build();
9494
}
@@ -250,14 +250,14 @@ public Builder toBuilder() {
250250
}
251251

252252
/**
253-
* The map of bindings that comprises the policy.
253+
* Returns the map of bindings that comprises the policy.
254254
*/
255255
public Map<Role, Set<Identity>> bindings() {
256256
return bindings;
257257
}
258258

259259
/**
260-
* The policy's etag.
260+
* Returns the policy's etag.
261261
*
262262
* <p>Etags are used for optimistic concurrency control as a way to help prevent simultaneous
263263
* updates of a policy from overwriting each other. It is strongly suggested that systems make
@@ -272,8 +272,8 @@ public String etag() {
272272
}
273273

274274
/**
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.
277277
*/
278278
public int version() {
279279
return version;
Collapse file

‎google-cloud-core/src/main/java/com/google/cloud/Role.java‎

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 numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*
2828
* @see <a href="https://cloud.google.com/iam/docs/viewing-grantable-roles">Viewing the Grantable
2929
* Roles on Resources</a>
30+
* @see <a href="https://cloud.google.com/iam/docs/understanding-roles">Understanding Roles</a>
3031
*/
3132
public final class Role implements Serializable {
3233

@@ -47,6 +48,36 @@ public String value() {
4748
return value;
4849
}
4950

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+
5081
/**
5182
* Returns a new role given its string value.
5283
*
Collapse file

‎google-cloud-core/src/test/java/com/google/cloud/PolicyTest.java‎

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 numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public class PolicyTest {
4343
Identity.serviceAccount("[email protected]");
4444
private static final Identity GROUP = Identity.group("[email protected]");
4545
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();
4949
private static final Map<Role, ImmutableSet<Identity>> BINDINGS = ImmutableMap.of(
5050
VIEWER,
5151
ImmutableSet.of(USER, SERVICE_ACCOUNT, ALL_USERS),
Collapse file

‎google-cloud-core/src/test/java/com/google/cloud/RoleTest.java‎

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 numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ public void testOf() {
3636
compareRoles(OWNER, Role.of("roles/owner"));
3737
}
3838

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+
3954
@Test(expected = NullPointerException.class)
4055
public void testOfNullValue() {
4156
Role.of(null);
Collapse file

‎google-cloud-core/src/test/java/com/google/cloud/SerializationTest.java‎

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 numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class SerializationTest extends BaseSerializationTest {
3939
private static final SigningException SIGNING_EXCEPTION =
4040
new SigningException("message", BASE_SERVICE_EXCEPTION);
4141
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();
4343
private static final Policy SOME_IAM_POLICY = Policy.builder().build();
4444
private static final WaitForOption CHECKING_PERIOD =
4545
WaitForOption.checkEvery(42, TimeUnit.SECONDS);
Collapse file

‎google-cloud-examples/src/main/java/com/google/cloud/examples/resourcemanager/snippets/ModifyPolicy.java‎

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 numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static void main(String... args) {
4949
// Add a viewer
5050
Policy.Builder modifiedPolicy = policy.toBuilder();
5151
Identity newViewer = Identity.user("<insert user's email address here>");
52-
modifiedPolicy.addIdentity(Role.of("roles/viewer"), newViewer);
52+
modifiedPolicy.addIdentity(Role.viewer(), newViewer);
5353

5454
// Write policy
5555
Policy updatedPolicy = project.replacePolicy(modifiedPolicy.build());
Collapse file

‎google-cloud-resourcemanager/README.md‎

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 numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ Policy policy = project.getPolicy();
186186
// Add a viewer
187187
Policy.Builder modifiedPolicy = policy.toBuilder();
188188
Identity newViewer = Identity.user("<insert user's email address here>");
189-
modifiedPolicy.addIdentity(Role.of("roles/viewer"), newViewer);
189+
modifiedPolicy.addIdentity(Role.viewer(), newViewer);
190190

191191
// Write policy
192192
Policy updatedPolicy = project.replacePolicy(modifiedPolicy.build());
Collapse file

‎google-cloud-resourcemanager/src/main/java/com/google/cloud/resourcemanager/ResourceManager.java‎

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 numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public static ProjectListOption fields(ProjectField... fields) {
303303
* <pre> {@code
304304
* Policy currentPolicy = resourceManager.getPolicy("my-project-id");
305305
* Policy modifiedPolicy = current.toBuilder()
306-
* .removeIdentity(Role.of("roles/viewer"), Identity.user("[email protected]"))
306+
* .removeIdentity(Role.viewer(), Identity.user("[email protected]"))
307307
* .build();
308308
* Policy newPolicy = resourceManager.replacePolicy("my-project-id", modified);
309309
* }
Collapse file

‎google-cloud-resourcemanager/src/test/java/com/google/cloud/resourcemanager/PolicyMarshallerTest.java‎

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 numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ public class PolicyMarshallerTest {
3535
Identity.serviceAccount("[email protected]");
3636
private static final Identity GROUP = Identity.group("[email protected]");
3737
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();
4141
private static final Role SOME_ROLE = Role.of("roles/some-role");
4242
private static final Policy SIMPLE_POLICY = Policy.builder()
4343
.addIdentity(OWNER, USER)
Collapse file

‎google-cloud-resourcemanager/src/test/java/com/google/cloud/resourcemanager/ProjectTest.java‎

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 numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public class ProjectTest {
5757
private static final Identity SERVICE_ACCOUNT =
5858
Identity.serviceAccount("[email protected]");
5959
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)
6262
.build();
6363

6464
private ResourceManager serviceMockReturnsOptions = createStrictMock(ResourceManager.class);

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.