2424import com .google .common .collect .ImmutableMap ;
2525import com .google .common .collect .ImmutableSet ;
2626import com .google .common .collect .Lists ;
27+ import com .google .common .io .BaseEncoding ;
2728import com .google .protobuf .ByteString ;
2829
2930import java .io .Serializable ;
3940import java .util .Set ;
4041
4142/**
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.
43+ * Class for Identity and Access Management (IAM) policies. IAM policies are used to specify access
44+ * settings for Cloud Platform resources. A policy is a map of bindings. A binding assigns a set of
45+ * identities to a role, where the identities can be user accounts, Google groups, Google domains,
46+ * and service accounts. A role is a named list of permissions defined by IAM.
4647 *
4748 * @see <a href="https://cloud.google.com/iam/reference/rest/v1/Policy">Policy</a>
4849 */
@@ -88,7 +89,8 @@ protected Policy fromPb(com.google.iam.v1.Policy policyPb) {
8889 }
8990 return builder ()
9091 .bindings (bindings )
91- .etag (policyPb .getEtag ().size () == 0 ? null : policyPb .getEtag ().toStringUtf8 ())
92+ .etag (policyPb .getEtag ().isEmpty () ? null
93+ : BaseEncoding .base64 ().encode (policyPb .getEtag ().toByteArray ()))
9294 .version (policyPb .getVersion ())
9395 .build ();
9496 }
@@ -106,7 +108,7 @@ protected com.google.iam.v1.Policy toPb(Policy policy) {
106108 }
107109 policyBuilder .addAllBindings (bindingPbList );
108110 if (policy .etag != null ) {
109- policyBuilder .setEtag (ByteString .copyFromUtf8 ( policy .etag ));
111+ policyBuilder .setEtag (ByteString .copyFrom ( BaseEncoding . base64 (). decode ( policy .etag ) ));
110112 }
111113 policyBuilder .setVersion (policy .version );
112114 return policyBuilder .build ();
@@ -250,14 +252,14 @@ public Builder toBuilder() {
250252 }
251253
252254 /**
253- * The map of bindings that comprises the policy.
255+ * Returns the map of bindings that comprises the policy.
254256 */
255257 public Map <Role , Set <Identity >> bindings () {
256258 return bindings ;
257259 }
258260
259261 /**
260- * The policy's etag.
262+ * Returns the policy's etag.
261263 *
262264 * <p>Etags are used for optimistic concurrency control as a way to help prevent simultaneous
263265 * updates of a policy from overwriting each other. It is strongly suggested that systems make
@@ -272,8 +274,8 @@ public String etag() {
272274 }
273275
274276 /**
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.
277+ * Returns the version of the policy. The default version is 0, meaning only the "owner",
278+ * "editor", and "viewer" roles are permitted. If the version is 1, you may also use other roles.
277279 */
278280 public int version () {
279281 return version ;
0 commit comments