Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support of public access prevention #636

Merged
merged 22 commits into from Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -112,6 +112,7 @@ public static class IamConfiguration implements Serializable {

private Boolean isUniformBucketLevelAccessEnabled;
private Long uniformBucketLevelAccessLockedTime;
private String publicAccessPrevention;
shaffeeullah marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean equals(Object o) {
Expand All @@ -125,12 +126,16 @@ public boolean equals(Object o) {

@Override
public int hashCode() {
return Objects.hash(isUniformBucketLevelAccessEnabled, uniformBucketLevelAccessLockedTime);
return Objects.hash(
isUniformBucketLevelAccessEnabled,
uniformBucketLevelAccessLockedTime,
publicAccessPrevention);
}

private IamConfiguration(Builder builder) {
this.isUniformBucketLevelAccessEnabled = builder.isUniformBucketLevelAccessEnabled;
this.uniformBucketLevelAccessLockedTime = builder.uniformBucketLevelAccessLockedTime;
this.publicAccessPrevention = builder.publicAccessPrevention;
}

public static Builder newBuilder() {
Expand All @@ -141,6 +146,7 @@ public Builder toBuilder() {
Builder builder = new Builder();
builder.isUniformBucketLevelAccessEnabled = isUniformBucketLevelAccessEnabled;
builder.uniformBucketLevelAccessLockedTime = uniformBucketLevelAccessLockedTime;
builder.publicAccessPrevention = publicAccessPrevention;
return builder;
}

Expand All @@ -164,6 +170,10 @@ public Long getUniformBucketLevelAccessLockedTime() {
return uniformBucketLevelAccessLockedTime;
}

public String getPublicAccessPrevention() {
return publicAccessPrevention;
}

Bucket.IamConfiguration toPb() {
Bucket.IamConfiguration iamConfiguration = new Bucket.IamConfiguration();

Expand All @@ -176,6 +186,7 @@ Bucket.IamConfiguration toPb() {
: new DateTime(uniformBucketLevelAccessLockedTime));

iamConfiguration.setUniformBucketLevelAccess(uniformBucketLevelAccess);
iamConfiguration.setPublicAccessPrevention(publicAccessPrevention);

return iamConfiguration;
}
Expand All @@ -188,13 +199,15 @@ static IamConfiguration fromPb(Bucket.IamConfiguration iamConfiguration) {
return newBuilder()
.setIsUniformBucketLevelAccessEnabled(uniformBucketLevelAccess.getEnabled())
.setUniformBucketLevelAccessLockedTime(lockedTime == null ? null : lockedTime.getValue())
.setPublicAccessPrevention(iamConfiguration.getPublicAccessPrevention())
.build();
}

/** Builder for {@code IamConfiguration} */
public static class Builder {
private Boolean isUniformBucketLevelAccessEnabled;
private Long uniformBucketLevelAccessLockedTime;
private String publicAccessPrevention;

/** Deprecated in favor of setIsUniformBucketLevelAccessEnabled(). */
@Deprecated
Expand Down Expand Up @@ -235,6 +248,18 @@ Builder setUniformBucketLevelAccessLockedTime(Long uniformBucketLevelAccessLocke
return this;
}

/**
* Sets the bucket's Public Access Prevention configuration. Currently, 'unspecified' and
* 'enforced' are supported.
*
* @see <a
* href="https://cloud.google.com/storage/docs/public-access-prevention">public-access-prevention</a>
*/
public Builder setPublicAccessPrevention(String publicAccessPrevention) {
this.publicAccessPrevention = publicAccessPrevention;
return this;
}

/** Builds an {@code IamConfiguration} object */
public IamConfiguration build() {
return new IamConfiguration(this);
Expand Down
Expand Up @@ -72,10 +72,12 @@ public class BucketInfoTest {
LifecycleAction.newDeleteAction(),
LifecycleCondition.newBuilder().setAge(5).build()));
private static final String INDEX_PAGE = "index.html";
private static final String PUBLIC_ACCESS_PREVENTION_ENFORCED = "enforced";
shaffeeullah marked this conversation as resolved.
Show resolved Hide resolved
private static final BucketInfo.IamConfiguration IAM_CONFIGURATION =
BucketInfo.IamConfiguration.newBuilder()
.setIsUniformBucketLevelAccessEnabled(true)
.setUniformBucketLevelAccessLockedTime(System.currentTimeMillis())
.setPublicAccessPrevention(PUBLIC_ACCESS_PREVENTION_ENFORCED)
.build();
private static final BucketInfo.Logging LOGGING =
BucketInfo.Logging.newBuilder()
Expand Down Expand Up @@ -358,11 +360,13 @@ public void testIamConfiguration() {
BucketInfo.IamConfiguration.newBuilder()
.setIsUniformBucketLevelAccessEnabled(true)
.setUniformBucketLevelAccessLockedTime(System.currentTimeMillis())
.setPublicAccessPrevention(PUBLIC_ACCESS_PREVENTION_ENFORCED)
.build()
.toPb();

assertEquals(Boolean.TRUE, iamConfiguration.getUniformBucketLevelAccess().getEnabled());
assertNotNull(iamConfiguration.getUniformBucketLevelAccess().getLockedTime());
assertEquals(PUBLIC_ACCESS_PREVENTION_ENFORCED, iamConfiguration.getPublicAccessPrevention());
}

@Test
Expand Down