Skip to content

Commit 257ae37

Browse files
docs(iam): Update comments and terminology in IAM samples (#9887)
* Update Quickstart.java comments Includes changing "member" to "principal" and linking to principal identifiers page instead of specifying recommended format. * Update AddMember.java comments (#9886) Includes changing "member" to "principal" and linking to principal identifiers page instead of specifying recommended format. * Update AddBinding.java Includes changing "member" to "principal" and linking to principal identifiers page instead of specifying recommended format. melaniedejong-patch-1 (#4895) * Update RemoveMember.java comments Includes changing "member" to "principal" and linking to principal identifiers page instead of specifying recommended format. * Update Quickstart.java * Update AddMember.java
1 parent b0b638a commit 257ae37

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

iam/snippets/src/main/java/AddBinding.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ public static void main(String[] args) {
2727
Policy policy = Policy.newBuilder().build();
2828
// TODO: Replace with your role.
2929
String role = "roles/role-to-add";
30-
// TODO: Replace with your members.
31-
List<String> members = Collections.singletonList("user:member-to-add@example.com");
30+
// TODO: Replace with your principals.
31+
// For examples, see https://cloud.google.com/iam/docs/principal-identifiers
32+
List<String> members = Collections.singletonList("principal-id");
3233

3334
addBinding(policy, role, members);
3435
}
3536

36-
// Adds a member to a role.
37+
// Adds a principals to a role.
3738
public static Policy addBinding(Policy policy, String role, List<String> members) {
3839
Binding binding = Binding.newBuilder()
3940
.setRole(role)

iam/snippets/src/main/java/AddMember.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ public static void main(String[] args) {
2626
Policy policy = Policy.newBuilder().build();
2727
// TODO: Replace with your role.
2828
String role = "roles/existing-role";
29-
// TODO: Replace with your member.
30-
String member = "user:member-to-add@example.com";
29+
// TODO: Replace with your principal.
30+
// For examples, see https://cloud.google.com/iam/docs/principal-identifiers
31+
String member = "principal-id";
3132

3233
addMember(policy, role, member);
3334
}
3435

35-
// Adds a member to a pre-existing role.
36+
// Adds a principal to a pre-existing role.
3637
public static Policy addMember(Policy policy, String role, String member) {
3738
List<Binding> newBindingsList = new ArrayList<>();
3839

@@ -44,13 +45,13 @@ public static Policy addMember(Policy policy, String role, String member) {
4445
}
4546
}
4647

47-
// Update the policy to add the member.
48+
// Update the policy to add the principal.
4849
Policy updatedPolicy = policy.toBuilder()
4950
.clearBindings()
5051
.addAllBindings(newBindingsList)
5152
.build();
5253

53-
System.out.println("Added member: " + updatedPolicy.getBindingsList());
54+
System.out.println("Added principal: " + updatedPolicy.getBindingsList());
5455

5556
return updatedPolicy;
5657
}

iam/snippets/src/main/java/Quickstart.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ public static void main(String[] args) throws IOException {
3434
String projectId = "your-project";
3535
// TODO: Replace with your service account name.
3636
String serviceAccount = "your-service-account";
37-
// TODO: Replace with the ID of your member in the form "user:member@example.com"
38-
String member = "your-member";
37+
// TODO: Replace with the ID of your principal.
38+
// For examples, see https://cloud.google.com/iam/docs/principal-identifiers
39+
String member = "your-principal";
3940
// The role to be granted.
4041
String role = "roles/logging.logWriter";
4142

@@ -56,10 +57,10 @@ public static void quickstart(String projectId, String serviceAccount,
5657
// This client only needs to be created once, and can be reused for multiple requests.
5758
try (IAMClient iamClient = IAMClient.create()) {
5859

59-
// Grants your member the "Log writer" role for your project.
60+
// Grants your principal the "Log writer" role for your project.
6061
addBinding(iamClient, projectId, serviceAccount, member, role);
6162

62-
// Get the project's policy and print all members with the "Log Writer" role
63+
// Get the project's policy and print all principals with the "Log Writer" role
6364
Policy policy = getPolicy(iamClient, projectId, serviceAccount);
6465

6566
Binding binding = null;
@@ -73,14 +74,14 @@ public static void quickstart(String projectId, String serviceAccount,
7374
}
7475

7576
System.out.println("Role: " + binding.getRole());
76-
System.out.print("Members: ");
77+
System.out.print("Principals: ");
7778

7879
for (String m : binding.getMembersList()) {
7980
System.out.print("[" + m + "] ");
8081
}
8182
System.out.println();
8283

83-
// Removes member from the "Log writer" role.
84+
// Removes principal from the "Log writer" role.
8485
removeMember(iamClient, projectId, serviceAccount, member, role);
8586
}
8687
}
@@ -107,7 +108,7 @@ public static void addBinding(IAMClient iamClient, String projectId, String serv
107108
}
108109

109110
if (binding != null) {
110-
// If binding already exists, adds member to binding.
111+
// If binding already exists, adds principal to binding.
111112
binding.getMembersList().add(member);
112113
} else {
113114
// If binding does not exist, adds binding to policy.
@@ -127,7 +128,7 @@ public static void removeMember(IAMClient iamClient, String projectId, String se
127128
// Gets the project's policy.
128129
Policy.Builder policy = getPolicy(iamClient, projectId, serviceAccount).toBuilder();
129130

130-
// Removes the member from the role.
131+
// Removes the principal from the role.
131132
Binding binding = null;
132133
for (Binding b : policy.getBindingsList()) {
133134
if (b.getRole().equals(role)) {

iam/snippets/src/main/java/RemoveMember.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ public static void main(String[] args) throws IOException {
2727
Policy policy = Policy.newBuilder().build();
2828
// TODO: Replace with your role.
2929
String role = "roles/existing-role";
30-
// TODO: Replace with your member.
31-
String member = "user:member-to-add@example.com";
30+
// TODO: Replace with your principal.
31+
// For examples, see https://cloud.google.com/iam/docs/principal-identifiers
32+
String member = "principal-id";
3233

3334
removeMember(policy, role, member);
3435
}
3536

36-
// Removes member from a role; removes binding if binding contains no members.
37+
// Removes principal from a role; removes binding if binding contains no members.
3738
public static Policy removeMember(Policy policy, String role, String member) {
3839
// Creating new builder with all values copied from origin policy
3940
Policy.Builder policyBuilder = policy.toBuilder();
@@ -49,12 +50,12 @@ public static Policy removeMember(Policy policy, String role, String member) {
4950

5051
if (binding != null && binding.getMembersList().contains(member)) {
5152
List<String> newMemberList = new ArrayList<>(binding.getMembersList());
52-
// Removing member from a role
53+
// Removing principal from the role
5354
newMemberList.remove(member);
5455

5556
System.out.println("Member " + member + " removed from " + role);
5657

57-
// Adding all remaining members to create new binding
58+
// Adding all remaining principals to create new binding
5859
Binding newBinding = binding.toBuilder()
5960
.clearMembers()
6061
.addAllMembers(newMemberList)
@@ -70,14 +71,14 @@ public static Policy removeMember(Policy policy, String role, String member) {
7071
newBindingList.add(newBinding);
7172
}
7273

73-
// Update the policy to remove the member.
74+
// Update the policy to remove the principal.
7475
policyBuilder.clearBindings()
7576
.addAllBindings(newBindingList);
7677
}
7778

7879
Policy updatedPolicy = policyBuilder.build();
7980

80-
System.out.println("Exising members: " + updatedPolicy.getBindingsList());
81+
System.out.println("Exising principals: " + updatedPolicy.getBindingsList());
8182

8283
return updatedPolicy;
8384
}

0 commit comments

Comments
 (0)