Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d48ec7

Browse files
committed
Merge pull request#718 from ajkannan/get-set-test-iam
Add get, replace, and test for IAM
2 parents3b083a6 +c2c6628 commit7d48ec7

File tree

14 files changed

+718
-98
lines changed

14 files changed

+718
-98
lines changed

‎gcloud-java-core/src/main/java/com/google/gcloud/Identity.java‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class Identity implements Serializable {
4444
privatestaticfinallongserialVersionUID = -8181841964597657446L;
4545

4646
privatefinalTypetype;
47-
privatefinalStringid;
47+
privatefinalStringvalue;
4848

4949
/**
5050
* The types of IAM identities.
@@ -82,17 +82,17 @@ public enum Type {
8282
DOMAIN
8383
}
8484

85-
privateIdentity(Typetype,Stringid) {
85+
privateIdentity(Typetype,Stringvalue) {
8686
this.type =type;
87-
this.id =id;
87+
this.value =value;
8888
}
8989

9090
publicTypetype() {
9191
returntype;
9292
}
9393

9494
/**
95-
* Returns the string identifier for this identity. Theid corresponds to:
95+
* Returns the string identifier for this identity. Thevalue corresponds to:
9696
* <ul>
9797
* <li>email address (for identities of type {@code USER}, {@code SERVICE_ACCOUNT}, and
9898
* {@code GROUP})
@@ -101,8 +101,8 @@ public Type type() {
101101
* {@code ALL_AUTHENTICATED_USERS})
102102
* </ul>
103103
*/
104-
publicStringid() {
105-
returnid;
104+
publicStringvalue() {
105+
returnvalue;
106106
}
107107

108108
/**
@@ -163,7 +163,7 @@ public static Identity domain(String domain) {
163163

164164
@Override
165165
publicinthashCode() {
166-
returnObjects.hash(id,type);
166+
returnObjects.hash(value,type);
167167
}
168168

169169
@Override
@@ -172,7 +172,7 @@ public boolean equals(Object obj) {
172172
returnfalse;
173173
}
174174
Identityother = (Identity)obj;
175-
returnObjects.equals(id,other.id()) &&Objects.equals(type,other.type());
175+
returnObjects.equals(value,other.value()) &&Objects.equals(type,other.type());
176176
}
177177

178178
/**
@@ -186,13 +186,13 @@ public String strValue() {
186186
caseALL_AUTHENTICATED_USERS:
187187
return"allAuthenticatedUsers";
188188
caseUSER:
189-
return"user:" +id;
189+
return"user:" +value;
190190
caseSERVICE_ACCOUNT:
191-
return"serviceAccount:" +id;
191+
return"serviceAccount:" +value;
192192
caseGROUP:
193-
return"group:" +id;
193+
return"group:" +value;
194194
caseDOMAIN:
195-
return"domain:" +id;
195+
return"domain:" +value;
196196
default:
197197
thrownewIllegalStateException("Unexpected identity type: " +type);
198198
}

‎gcloud-java-core/src/test/java/com/google/gcloud/IdentityTest.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,19 @@ public class IdentityTest {
3434
@Test
3535
publicvoidtestAllUsers() {
3636
assertEquals(Identity.Type.ALL_USERS,ALL_USERS.type());
37-
assertNull(ALL_USERS.id());
37+
assertNull(ALL_USERS.value());
3838
}
3939

4040
@Test
4141
publicvoidtestAllAuthenticatedUsers() {
4242
assertEquals(Identity.Type.ALL_AUTHENTICATED_USERS,ALL_AUTH_USERS.type());
43-
assertNull(ALL_AUTH_USERS.id());
43+
assertNull(ALL_AUTH_USERS.value());
4444
}
4545

4646
@Test
4747
publicvoidtestUser() {
4848
assertEquals(Identity.Type.USER,USER.type());
49-
assertEquals("abc@gmail.com",USER.id());
49+
assertEquals("abc@gmail.com",USER.value());
5050
}
5151

5252
@Test(expected =NullPointerException.class)
@@ -57,7 +57,7 @@ public void testUserNullEmail() {
5757
@Test
5858
publicvoidtestServiceAccount() {
5959
assertEquals(Identity.Type.SERVICE_ACCOUNT,SERVICE_ACCOUNT.type());
60-
assertEquals("service-account@gmail.com",SERVICE_ACCOUNT.id());
60+
assertEquals("service-account@gmail.com",SERVICE_ACCOUNT.value());
6161
}
6262

6363
@Test(expected =NullPointerException.class)
@@ -68,7 +68,7 @@ public void testServiceAccountNullEmail() {
6868
@Test
6969
publicvoidtestGroup() {
7070
assertEquals(Identity.Type.GROUP,GROUP.type());
71-
assertEquals("group@gmail.com",GROUP.id());
71+
assertEquals("group@gmail.com",GROUP.value());
7272
}
7373

7474
@Test(expected =NullPointerException.class)
@@ -79,7 +79,7 @@ public void testGroupNullEmail() {
7979
@Test
8080
publicvoidtestDomain() {
8181
assertEquals(Identity.Type.DOMAIN,DOMAIN.type());
82-
assertEquals("google.com",DOMAIN.id());
82+
assertEquals("google.com",DOMAIN.value());
8383
}
8484

8585
@Test(expected =NullPointerException.class)
@@ -100,6 +100,6 @@ public void testIdentityToAndFromPb() {
100100
privatevoidcompareIdentities(Identityexpected,Identityactual) {
101101
assertEquals(expected,actual);
102102
assertEquals(expected.type(),actual.type());
103-
assertEquals(expected.id(),actual.id());
103+
assertEquals(expected.value(),actual.value());
104104
}
105105
}

‎gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/Policy.java‎

Lines changed: 82 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,19 @@
1717
packagecom.google.gcloud.resourcemanager;
1818

1919
importcom.google.common.annotations.VisibleForTesting;
20-
importcom.google.common.base.CaseFormat;
2120
importcom.google.common.base.Function;
2221
importcom.google.common.collect.ImmutableSet;
2322
importcom.google.common.collect.Lists;
2423
importcom.google.gcloud.IamPolicy;
2524
importcom.google.gcloud.Identity;
2625

26+
importjava.io.Serializable;
2727
importjava.util.ArrayList;
2828
importjava.util.HashMap;
2929
importjava.util.LinkedList;
3030
importjava.util.List;
3131
importjava.util.Map;
32+
importjava.util.Objects;
3233
importjava.util.Set;
3334

3435
/**
@@ -48,40 +49,101 @@ public class Policy extends IamPolicy<Policy.Role> {
4849
/**
4950
* Represents legacy roles in an IAM Policy.
5051
*/
51-
publicenumRole {
52+
publicstaticclassRoleimplementsSerializable {
5253

5354
/**
54-
*Permissions for read-only actions that preserve state.
55+
*The recognized roles in a Project's IAM policy.
5556
*/
56-
VIEWER("roles/viewer"),
57+
publicenumType {
58+
59+
/**
60+
* Permissions for read-only actions that preserve state.
61+
*/
62+
VIEWER,
63+
64+
/**
65+
* All viewer permissions and permissions for actions that modify state.
66+
*/
67+
EDITOR,
68+
69+
/**
70+
* All editor permissions and permissions for the following actions:
71+
* <ul>
72+
* <li>Manage access control for a resource.
73+
* <li>Set up billing (for a project).
74+
* </ul>
75+
*/
76+
OWNER
77+
}
78+
79+
privatestaticfinallongserialVersionUID =2421978909244287488L;
80+
81+
privatefinalStringvalue;
82+
privatefinalTypetype;
83+
84+
privateRole(Stringvalue,Typetype) {
85+
this.value =value;
86+
this.type =type;
87+
}
88+
89+
Stringvalue() {
90+
returnvalue;
91+
}
5792

5893
/**
59-
* All viewer permissions and permissions for actions that modify state.
94+
* Returns the type of role (editor, owner, or viewer). Returns {@code null} if the role type
95+
* is unrecognized.
6096
*/
61-
EDITOR("roles/editor"),
97+
publicTypetype() {
98+
returntype;
99+
}
62100

63101
/**
64-
* All editor permissions and permissions for the following actions:
65-
* <ul>
66-
* <li>Manage access control for a resource.
67-
* <li>Set up billing (for a project).
68-
* </ul>
102+
* Returns a {@code Role} of type {@link Type#VIEWER VIEWER}.
69103
*/
70-
OWNER("roles/owner");
104+
publicstaticRoleviewer() {
105+
returnnewRole("roles/viewer",Type.VIEWER);
106+
}
71107

72-
privateStringstrValue;
108+
/**
109+
* Returns a {@code Role} of type {@link Type#EDITOR EDITOR}.
110+
*/
111+
publicstaticRoleeditor() {
112+
returnnewRole("roles/editor",Type.EDITOR);
113+
}
73114

74-
privateRole(StringstrValue) {
75-
this.strValue =strValue;
115+
/**
116+
* Returns a {@code Role} of type {@link Type#OWNER OWNER}.
117+
*/
118+
publicstaticRoleowner() {
119+
returnnewRole("roles/owner",Type.OWNER);
76120
}
77121

78-
StringstrValue() {
79-
returnstrValue;
122+
staticRolerawRole(StringroleStr) {
123+
returnnewRole(roleStr,null);
80124
}
81125

82126
staticRolefromStr(StringroleStr) {
83-
returnRole.valueOf(CaseFormat.LOWER_CAMEL.to(
84-
CaseFormat.UPPER_UNDERSCORE,roleStr.substring("roles/".length())));
127+
try {
128+
Typetype =Type.valueOf(roleStr.split("/")[1].toUpperCase());
129+
returnnewRole(roleStr,type);
130+
}catch (Exceptionex) {
131+
returnnewRole(roleStr,null);
132+
}
133+
}
134+
135+
@Override
136+
publicfinalinthashCode() {
137+
returnObjects.hash(value,type);
138+
}
139+
140+
@Override
141+
publicfinalbooleanequals(Objectobj) {
142+
if (!(objinstanceofRole)) {
143+
returnfalse;
144+
}
145+
Roleother = (Role)obj;
146+
returnObjects.equals(value,other.value()) &&Objects.equals(type,other.type());
85147
}
86148
}
87149

@@ -124,7 +186,7 @@ com.google.api.services.cloudresourcemanager.model.Policy toPb() {
124186
for (Map.Entry<Role,Set<Identity>>binding :bindings().entrySet()) {
125187
com.google.api.services.cloudresourcemanager.model.BindingbindingPb =
126188
newcom.google.api.services.cloudresourcemanager.model.Binding();
127-
bindingPb.setRole(binding.getKey().strValue());
189+
bindingPb.setRole(binding.getKey().value());
128190
bindingPb.setMembers(
129191
Lists.transform(
130192
newArrayList<>(binding.getValue()),

‎gcloud-java-resourcemanager/src/main/java/com/google/gcloud/resourcemanager/Project.java‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ public Project reload() {
157157
* completes, the project is not retrievable by the {@link ResourceManager#get} and
158158
* {@link ResourceManager#list} methods. The caller must have modify permissions for this project.
159159
*
160-
* @see <a
161-
* href="https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/delete">Cloud
162-
* Resource Manager delete</a>
163160
* @throws ResourceManagerException upon failure
161+
* @see <a href=
162+
* "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/delete">Cloud
163+
* Resource Manager delete</a>
164164
*/
165165
publicvoiddelete() {
166166
resourceManager.delete(projectId());
@@ -174,10 +174,10 @@ public void delete() {
174174
* state of {@link ProjectInfo.State#DELETE_IN_PROGRESS}, the project cannot be restored. The
175175
* caller must have modify permissions for this project.
176176
*
177-
* @see <a
178-
* href="https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/undelete">Cloud
179-
* Resource Manager undelete</a>
180177
* @throws ResourceManagerException upon failure (including when the project can't be restored)
178+
* @see <a href=
179+
* "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/undelete">Cloud
180+
* Resource Manager undelete</a>
181181
*/
182182
publicvoidundelete() {
183183
resourceManager.undelete(projectId());
@@ -188,11 +188,11 @@ public void undelete() {
188188
*
189189
* <p>The caller must have modify permissions for this project.
190190
*
191-
* @see <a
192-
* href="https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/update">Cloud
193-
* Resource Manager update</a>
194191
* @return the Project representing the new project metadata
195192
* @throws ResourceManagerException upon failure
193+
* @see <a href=
194+
* "https://cloud.google.com/resource-manager/reference/rest/v1beta1/projects/update">Cloud
195+
* Resource Manager update</a>
196196
*/
197197
publicProjectreplace() {
198198
returnresourceManager.replace(this);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp