File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed
main/java/com/google/cloud/storage
test/java/com/google/cloud/storage Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -34,8 +34,8 @@ class PolicyHelper {
3434 static Policy convertFromApiPolicy (com .google .api .services .storage .model .Policy apiPolicy ) {
3535 Policy .Builder policyBuilder = Policy .newBuilder ();
3636 List <Bindings > bindings = apiPolicy .getBindings ();
37+ ImmutableList .Builder <Binding > coreBindings = ImmutableList .builder ();
3738 if (null != bindings && !bindings .isEmpty ()) {
38- ImmutableList .Builder <Binding > coreBindings = ImmutableList .builder ();
3939 for (Bindings binding : bindings ) {
4040 Binding .Builder bindingBuilder = Binding .newBuilder ();
4141 bindingBuilder .setRole (binding .getRole ());
@@ -49,10 +49,8 @@ static Policy convertFromApiPolicy(com.google.api.services.storage.model.Policy
4949 }
5050 coreBindings .add (bindingBuilder .build ());
5151 }
52- policyBuilder .setBindings (coreBindings .build ());
53- } else {
54- throw new IllegalStateException ("Missing required bindings." );
5552 }
53+ policyBuilder .setBindings (coreBindings .build ());
5654 return policyBuilder .setEtag (apiPolicy .getEtag ()).setVersion (apiPolicy .getVersion ()).build ();
5755 }
5856
Original file line number Diff line number Diff line change @@ -3540,6 +3540,11 @@ HmacKeyMetadata updateHmacKeyState(
35403540 /**
35413541 * Gets the IAM policy for the provided bucket.
35423542 *
3543+ * <p>It's possible for bindings to be empty and instead have permissions inherited through
3544+ * Project or Organization IAM Policies. To prevent corrupting policies when you update an IAM
3545+ * policy with {@code Storage.setIamPolicy}, the ETAG value is used to perform optimistic
3546+ * concurrency.
3547+ *
35433548 * <p>Example of getting the IAM policy for a bucket.
35443549 *
35453550 * <pre>{@code
@@ -3556,6 +3561,9 @@ HmacKeyMetadata updateHmacKeyState(
35563561 /**
35573562 * Updates the IAM policy on the specified bucket.
35583563 *
3564+ * <p>To prevent corrupting policies when you update an IAM policy with {@code
3565+ * Storage.setIamPolicy}, the ETAG value is used to perform optimistic concurrency.
3566+ *
35593567 * <p>Example of updating the IAM policy on a bucket.
35603568 *
35613569 * <pre>{@code
Original file line number Diff line number Diff line change @@ -65,11 +65,15 @@ public void testEquivalence() {
6565 assertTrue (new ApiPolicyMatcher (apiPolicy ).matches (actualApiPolicy ));
6666 }
6767
68- @ Test ( expected = IllegalStateException . class )
68+ @ Test
6969 public void testApiPolicyWithoutBinding () {
7070 List <Bindings > bindings = null ;
7171 com .google .api .services .storage .model .Policy apiPolicy =
72- new com .google .api .services .storage .model .Policy ().setBindings (bindings ).setEtag (ETAG );
73- PolicyHelper .convertFromApiPolicy (apiPolicy );
72+ new com .google .api .services .storage .model .Policy ()
73+ .setBindings (bindings )
74+ .setEtag (ETAG )
75+ .setVersion (1 );
76+ Policy policy = PolicyHelper .convertFromApiPolicy (apiPolicy );
77+ assertEquals (policy .getBindings ().size (), 0 );
7478 }
7579}
You can’t perform that action at this time.
0 commit comments