@@ -95,6 +95,118 @@ public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo)
9595 private final Long retentionEffectiveTime ;
9696 private final Boolean retentionPolicyIsLocked ;
9797 private final Long retentionPeriod ;
98+ private final IamConfiguration iamConfiguration ;
99+
100+ /**
101+ * The Bucket's IAM Configuration.
102+ *
103+ * @see <a href="https://cloud.google.com/storage/docs/bucket-policy-only">Bucket Policy Only</a>
104+ */
105+ public static class IamConfiguration implements Serializable {
106+ private static final long serialVersionUID = -8671736104909424616L ;
107+
108+ private Boolean isBucketPolicyOnlyEnabled ;
109+ private Long bucketPolicyOnlyLockedTime ;
110+
111+ @ Override
112+ public boolean equals (Object o ) {
113+ if (this == o ) return true ;
114+ if (o == null || getClass () != o .getClass ()) {
115+ return false ;
116+ }
117+ IamConfiguration other = (IamConfiguration ) o ;
118+ return Objects .equals (toPb (), other .toPb ());
119+ }
120+
121+ @ Override
122+ public int hashCode () {
123+ return Objects .hash (isBucketPolicyOnlyEnabled , bucketPolicyOnlyLockedTime );
124+ }
125+
126+ private IamConfiguration (Builder builder ) {
127+ this .isBucketPolicyOnlyEnabled = builder .isBucketPolicyOnlyEnabled ;
128+ this .bucketPolicyOnlyLockedTime = builder .bucketPolicyOnlyLockedTime ;
129+ }
130+
131+ public static Builder newBuilder () {
132+ return new Builder ();
133+ }
134+
135+ public Builder toBuilder () {
136+ Builder builder = new Builder ();
137+ builder .isBucketPolicyOnlyEnabled = isBucketPolicyOnlyEnabled ;
138+ builder .bucketPolicyOnlyLockedTime = bucketPolicyOnlyLockedTime ;
139+ return builder ;
140+ }
141+
142+ public Boolean isBucketPolicyOnlyEnabled () {
143+ return isBucketPolicyOnlyEnabled ;
144+ }
145+
146+ public Long getBucketPolicyOnlyLockedTime () {
147+ return bucketPolicyOnlyLockedTime ;
148+ }
149+
150+ Bucket .IamConfiguration toPb () {
151+ Bucket .IamConfiguration iamConfiguration = new Bucket .IamConfiguration ();
152+
153+ Bucket .IamConfiguration .BucketPolicyOnly bucketPolicyOnly =
154+ new Bucket .IamConfiguration .BucketPolicyOnly ();
155+ bucketPolicyOnly .setEnabled (isBucketPolicyOnlyEnabled );
156+ bucketPolicyOnly .setLockedTime (
157+ bucketPolicyOnlyLockedTime == null ? null : new DateTime (bucketPolicyOnlyLockedTime ));
158+
159+ iamConfiguration .setBucketPolicyOnly (bucketPolicyOnly );
160+
161+ return iamConfiguration ;
162+ }
163+
164+ static IamConfiguration fromPb (Bucket .IamConfiguration iamConfiguration ) {
165+ Bucket .IamConfiguration .BucketPolicyOnly bucketPolicyOnly =
166+ iamConfiguration .getBucketPolicyOnly ();
167+ DateTime lockedTime = bucketPolicyOnly .getLockedTime ();
168+
169+ return newBuilder ()
170+ .setIsBucketPolicyOnlyEnabled (bucketPolicyOnly .getEnabled ())
171+ .setBucketPolicyOnlyLockedTime (lockedTime == null ? null : lockedTime .getValue ())
172+ .build ();
173+ }
174+
175+ /** Builder for {@code IamConfiguration} */
176+ public static class Builder {
177+ private Boolean isBucketPolicyOnlyEnabled ;
178+ private Long bucketPolicyOnlyLockedTime ;
179+
180+ /**
181+ * Sets whether BucketPolicyOnly is enabled for this bucket. When this is enabled, access to
182+ * the bucket will be configured through IAM, and legacy ACL policies will not work. When this
183+ * is first enabled, {@code bucketPolicyOnly.lockedTime} will be set by the API automatically.
184+ * This field can then be disabled until the time specified, after which it will become
185+ * immutable and calls to change it will fail. If this is enabled, calls to access legacy ACL
186+ * information will fail.
187+ */
188+ public Builder setIsBucketPolicyOnlyEnabled (Boolean isBucketPolicyOnlyEnabled ) {
189+ this .isBucketPolicyOnlyEnabled = isBucketPolicyOnlyEnabled ;
190+ return this ;
191+ }
192+
193+ /**
194+ * Sets the deadline for switching {@code bucketPolicyOnly.enabled} back to false. After this
195+ * time passes, calls to do so will fail. This is package-private, since in general this field
196+ * should never be set by a user--it's automatically set by the backend when {@code enabled}
197+ * is set to true.
198+ */
199+ Builder setBucketPolicyOnlyLockedTime (Long bucketPolicyOnlyLockedTime ) {
200+ this .bucketPolicyOnlyLockedTime = bucketPolicyOnlyLockedTime ;
201+ return this ;
202+ }
203+
204+ /** Builds an {@code IamConfiguration} object */
205+ public IamConfiguration build () {
206+ return new IamConfiguration (this );
207+ }
208+ }
209+ }
98210
99211 /**
100212 * Lifecycle rule for a bucket. Allows supported Actions, such as deleting and changing storage
@@ -786,6 +898,15 @@ public abstract static class Builder {
786898 @ BetaApi
787899 public abstract Builder setRetentionPeriod (Long retentionPeriod );
788900
901+ /**
902+ * Sets the IamConfiguration to specify whether IAM access should be enabled.
903+ *
904+ * @see <a href="https://cloud.google.com/storage/docs/bucket-policy-only">Bucket Policy
905+ * Only</a>
906+ */
907+ @ BetaApi
908+ public abstract Builder setIamConfiguration (IamConfiguration iamConfiguration );
909+
789910 /** Creates a {@code BucketInfo} object. */
790911 public abstract BucketInfo build ();
791912 }
@@ -816,6 +937,7 @@ static final class BuilderImpl extends Builder {
816937 private Long retentionEffectiveTime ;
817938 private Boolean retentionPolicyIsLocked ;
818939 private Long retentionPeriod ;
940+ private IamConfiguration iamConfiguration ;
819941
820942 BuilderImpl (String name ) {
821943 this .name = name ;
@@ -846,6 +968,7 @@ static final class BuilderImpl extends Builder {
846968 retentionEffectiveTime = bucketInfo .retentionEffectiveTime ;
847969 retentionPolicyIsLocked = bucketInfo .retentionPolicyIsLocked ;
848970 retentionPeriod = bucketInfo .retentionPeriod ;
971+ iamConfiguration = bucketInfo .iamConfiguration ;
849972 }
850973
851974 @ Override
@@ -998,6 +1121,12 @@ public Builder setRetentionPeriod(Long retentionPeriod) {
9981121 return this ;
9991122 }
10001123
1124+ @ Override
1125+ public Builder setIamConfiguration (IamConfiguration iamConfiguration ) {
1126+ this .iamConfiguration = iamConfiguration ;
1127+ return this ;
1128+ }
1129+
10011130 @ Override
10021131 public BucketInfo build () {
10031132 checkNotNull (name );
@@ -1030,6 +1159,7 @@ public BucketInfo build() {
10301159 retentionEffectiveTime = builder .retentionEffectiveTime ;
10311160 retentionPolicyIsLocked = builder .retentionPolicyIsLocked ;
10321161 retentionPeriod = builder .retentionPeriod ;
1162+ iamConfiguration = builder .iamConfiguration ;
10331163 }
10341164
10351165 /** Returns the service-generated id for the bucket. */
@@ -1268,6 +1398,12 @@ public Long getRetentionPeriod() {
12681398 return retentionPeriod ;
12691399 }
12701400
1401+ /** Returns the IAM configuration */
1402+ @ BetaApi
1403+ public IamConfiguration getIamConfiguration () {
1404+ return iamConfiguration ;
1405+ }
1406+
12711407 /** Returns a builder for the current bucket. */
12721408 public Builder toBuilder () {
12731409 return new BuilderImpl (this );
@@ -1405,6 +1541,9 @@ public Rule apply(LifecycleRule lifecycleRule) {
14051541 bucketPb .setRetentionPolicy (retentionPolicy );
14061542 }
14071543 }
1544+ if (iamConfiguration != null ) {
1545+ bucketPb .setIamConfiguration (iamConfiguration .toPb ());
1546+ }
14081547
14091548 return bucketPb ;
14101549 }
@@ -1526,6 +1665,10 @@ public DeleteRule apply(Rule rule) {
15261665 builder .setRetentionPeriod (retentionPolicy .getRetentionPeriod ());
15271666 }
15281667 }
1668+ Bucket .IamConfiguration iamConfiguration = bucketPb .getIamConfiguration ();
1669+ if (iamConfiguration != null ) {
1670+ builder .setIamConfiguration (IamConfiguration .fromPb (iamConfiguration ));
1671+ }
15291672 return builder .build ();
15301673 }
15311674}
0 commit comments