2323import com .google .gcloud .IamPolicy ;
2424import com .google .gcloud .Identity ;
2525
26- import java .io .Serializable ;
2726import java .util .ArrayList ;
2827import java .util .HashMap ;
2928import java .util .LinkedList ;
3029import java .util .List ;
3130import java .util .Map ;
32- import java .util .Objects ;
3331import java .util .Set ;
3432
3533/**
4240 *
4341 * @see <a href="https://cloud.google.com/iam/reference/rest/v1/Policy">Policy</a>
4442 */
45- public class Policy extends IamPolicy <Policy . Role > {
43+ public class Policy extends IamPolicy <String > {
4644
4745 private static final long serialVersionUID = -5573557282693961850L ;
4846
4947 /**
50- * Represents legacy roles in an IAM Policy.
48+ * The project-level roles in an IAM policy. This enum is not an exhaustive list of all roles
49+ * you can use in an IAM policy. You can also use service-specific roles (e.g.
50+ * <i>roles/pubsub.editor</i>). See the <i>Supported Cloud Platform Services</i> page for links
51+ * to service-specific roles.
52+ *
53+ * @see <a href="https://cloud.google.com/iam/#supported_cloud_platform_services">Supported Cloud
54+ * Platform Services</a>
5155 */
52- public static class Role implements Serializable {
56+ public enum ProjectRole {
5357
5458 /**
55- * The recognized roles in a Project's IAM policy .
59+ * Permissions for read-only actions that preserve state .
5660 */
57- public enum Type {
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- private static final long serialVersionUID = 2421978909244287488L ;
80-
81- private final String value ;
82- private final Type type ;
83-
84- private Role (String value , Type type ) {
85- this .value = value ;
86- this .type = type ;
87- }
88-
89- String value () {
90- return value ;
91- }
61+ VIEWER ("roles/viewer" ),
9262
9363 /**
94- * Returns the type of role (editor, owner, or viewer). Returns {@code null} if the role type
95- * is unrecognized.
64+ * All viewer permissions and permissions for actions that modify state.
9665 */
97- public Type type () {
98- return type ;
99- }
66+ EDITOR ("roles/editor" ),
10067
10168 /**
102- * Returns a {@code Role} of type {@link Type#VIEWER VIEWER}.
69+ * All editor permissions and permissions for the following actions:
70+ * <ul>
71+ * <li>Manage access control for a resource.
72+ * <li>Set up billing (for a project).
73+ * </ul>
10374 */
104- public static Role viewer () {
105- return new Role ("roles/viewer" , Type .VIEWER );
106- }
75+ OWNER ("roles/owner" );
10776
108- /**
109- * Returns a {@code Role} of type {@link Type#EDITOR EDITOR}.
110- */
111- public static Role editor () {
112- return new Role ("roles/editor" , Type .EDITOR );
77+ String value ;
78+
79+ private ProjectRole (String value ) {
80+ this .value = value ;
11381 }
11482
11583 /**
116- * Returns a {@code Role} of type {@link Type#OWNER OWNER} .
84+ * Returns the string value associated with the role .
11785 */
118- public static Role owner () {
119- return new Role ("roles/owner" , Type .OWNER );
120- }
121-
122- static Role rawRole (String roleStr ) {
123- return new Role (roleStr , null );
124- }
125-
126- static Role fromStr (String roleStr ) {
127- try {
128- Type type = Type .valueOf (roleStr .split ("/" )[1 ].toUpperCase ());
129- return new Role (roleStr , type );
130- } catch (Exception ex ) {
131- return new Role (roleStr , null );
132- }
133- }
134-
135- @ Override
136- public final int hashCode () {
137- return Objects .hash (value , type );
138- }
139-
140- @ Override
141- public final boolean equals (Object obj ) {
142- if (!(obj instanceof Role )) {
143- return false ;
144- }
145- Role other = (Role ) obj ;
146- return Objects .equals (value , other .value ()) && Objects .equals (type , other .type ());
86+ public String value () {
87+ return value ;
14788 }
14889 }
14990
15091 /**
15192 * Builder for an IAM Policy.
15293 */
153- public static class Builder extends IamPolicy .Builder <Role , Builder > {
94+ public static class Builder extends IamPolicy .Builder <String , Builder > {
15495
15596 private Builder () {}
15697
15798 @ VisibleForTesting
158- Builder (Map <Role , Set <Identity >> bindings , String etag , Integer version ) {
99+ Builder (Map <String , Set <Identity >> bindings , String etag , Integer version ) {
159100 bindings (bindings ).etag (etag ).version (version );
160101 }
161102
@@ -188,10 +129,10 @@ com.google.api.services.cloudresourcemanager.model.Policy toPb() {
188129 new com .google .api .services .cloudresourcemanager .model .Policy ();
189130 List <com .google .api .services .cloudresourcemanager .model .Binding > bindingPbList =
190131 new LinkedList <>();
191- for (Map .Entry <Role , Set <Identity >> binding : bindings ().entrySet ()) {
132+ for (Map .Entry <String , Set <Identity >> binding : bindings ().entrySet ()) {
192133 com .google .api .services .cloudresourcemanager .model .Binding bindingPb =
193134 new com .google .api .services .cloudresourcemanager .model .Binding ();
194- bindingPb .setRole (binding .getKey (). value () );
135+ bindingPb .setRole (binding .getKey ());
195136 bindingPb .setMembers (
196137 Lists .transform (
197138 new ArrayList <>(binding .getValue ()),
@@ -211,11 +152,11 @@ public String apply(Identity identity) {
211152
212153 static Policy fromPb (
213154 com .google .api .services .cloudresourcemanager .model .Policy policyPb ) {
214- Map <Role , Set <Identity >> bindings = new HashMap <>();
155+ Map <String , Set <Identity >> bindings = new HashMap <>();
215156 for (com .google .api .services .cloudresourcemanager .model .Binding bindingPb :
216157 policyPb .getBindings ()) {
217158 bindings .put (
218- Role . fromStr ( bindingPb .getRole () ),
159+ bindingPb .getRole (),
219160 ImmutableSet .copyOf (
220161 Lists .transform (
221162 bindingPb .getMembers (),
0 commit comments