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

[Storage] Bucket lock #3574

Merged
merged 16 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
* <li>createBatch
* <li>checksums, etags
* <li>IAM operations</li>
* <li>BucketLock operations</li>
* </ul>
* </ul>
*/
Expand Down Expand Up @@ -520,6 +521,11 @@ public Notification createNotification(String bucket, Notification notification)
throw new UnsupportedOperationException();
}

@Override
public Bucket lockRetentionPolicy(Bucket bucket, Map<Option, ?> options) {
throw new UnsupportedOperationException();
}

@Override
public ServiceAccount getServiceAccount(String projectId) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,30 @@ Builder setCustomerEncryption(CustomerEncryption customerEncryption) {
return this;
}

@GcpLaunchStage.Beta
@Override
Builder setKmsKeyName(String kmsKeyName) {
infoBuilder.setKmsKeyName(kmsKeyName);
return this;
}

@Override
public Builder setEventBasedHold(Boolean eventBasedHold) {
infoBuilder.setEventBasedHold(eventBasedHold);
return this;
}

@Override
public Builder setTemporaryHold(Boolean temporaryHold) {
infoBuilder.setTemporaryHold(temporaryHold);
return this;
}

@Override
Builder setRetentionExpirationTime(Long retentionExpirationTime) {
infoBuilder.setRetentionExpirationTime(retentionExpirationTime);
return this;
}

@Override
public Blob build() {
return new Blob(storage, infoBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public StorageObject apply(BlobInfo blobInfo) {
private final boolean isDirectory;
private final CustomerEncryption customerEncryption;
private final String kmsKeyName;
private final Boolean eventBasedHold;
private final Boolean temporaryHold;
private final Long retentionExpirationTime;

/**
* This class is meant for internal use only. Users are discouraged from using this class.
Expand Down Expand Up @@ -268,12 +271,19 @@ public abstract static class Builder {

abstract Builder setCustomerEncryption(CustomerEncryption customerEncryption);

abstract Builder setKmsKeyName(String kmsKeyName);

/**
*
* Sets the blob's kmsKeyName.
* Sets the blob's eventBasedHold.
*/
@GcpLaunchStage.Beta
abstract Builder setKmsKeyName(String kmsKeyName);
public abstract Builder setEventBasedHold(Boolean eventBasedHold);

/**
* Sets the blob's temporaryHold.
*/
public abstract Builder setTemporaryHold(Boolean temporaryHold);

abstract Builder setRetentionExpirationTime(Long retentionExpirationTime);

/**
* Creates a {@code BlobInfo} object.
Expand Down Expand Up @@ -308,6 +318,9 @@ static final class BuilderImpl extends Builder {
private CustomerEncryption customerEncryption;
private StorageClass storageClass;
private String kmsKeyName;
private Boolean eventBasedHold;
private Boolean temporaryHold;
private Long retentionExpirationTime;

BuilderImpl(BlobId blobId) {
this.blobId = blobId;
Expand Down Expand Up @@ -339,6 +352,9 @@ static final class BuilderImpl extends Builder {
isDirectory = blobInfo.isDirectory;
storageClass = blobInfo.storageClass;
kmsKeyName = blobInfo.kmsKeyName;
eventBasedHold = blobInfo.eventBasedHold;
temporaryHold = blobInfo.temporaryHold;
retentionExpirationTime = blobInfo.retentionExpirationTime;
}

@Override
Expand Down Expand Up @@ -486,13 +502,30 @@ Builder setCustomerEncryption(CustomerEncryption customerEncryption) {
return this;
}

@GcpLaunchStage.Beta
@Override
Builder setKmsKeyName(String kmsKeyName) {
this.kmsKeyName = kmsKeyName;
return this;
}

@Override
public Builder setEventBasedHold(Boolean eventBasedHold) {
this.eventBasedHold = eventBasedHold;
return this;
}

@Override
public Builder setTemporaryHold(Boolean temporaryHold) {
this.temporaryHold = temporaryHold;
return this;
}

@Override
Builder setRetentionExpirationTime(Long retentionExpirationTime) {
this.retentionExpirationTime = retentionExpirationTime;
return this;
}

@Override
public BlobInfo build() {
checkNotNull(blobId);
Expand Down Expand Up @@ -526,6 +559,9 @@ public BlobInfo build() {
isDirectory = firstNonNull(builder.isDirectory, Boolean.FALSE);
storageClass = builder.storageClass;
kmsKeyName = builder.kmsKeyName;
eventBasedHold = builder.eventBasedHold;
temporaryHold = builder.temporaryHold;
retentionExpirationTime = builder.retentionExpirationTime;
}

/**
Expand Down Expand Up @@ -759,11 +795,25 @@ public StorageClass getStorageClass() {
/**
* Returns the Cloud KMS key used to encrypt the blob, if any.
*/
@GcpLaunchStage.Beta
public String getKmsKeyName() {
return kmsKeyName;
}

/**
* Returns the Event Based Hold status of the blob, if any.
*/
public Boolean getEventBasedHold() { return eventBasedHold; }

This comment was marked as spam.


/**
* Returns the Temporary Hold status of the blob, if any.
*/
public Boolean getTemporaryHold() { return temporaryHold; }

/**
* Returns the Retention Expiration Time of the blob, if a retention period is defined.
*/
public Long getRetentionExpirationTime() { return retentionExpirationTime; }

/**
* Returns a builder for the current blob.
*/
Expand Down Expand Up @@ -836,8 +886,13 @@ public ObjectAccessControl apply(Acl acl) {
if (customerEncryption != null) {
storageObject.setCustomerEncryption(customerEncryption.toPb());
}
if (retentionExpirationTime != null) {
storageObject.setRetentionExpirationTime(new DateTime(retentionExpirationTime));
}

storageObject.setKmsKeyName(kmsKeyName);
storageObject.setEventBasedHold(eventBasedHold);
storageObject.setTemporaryHold(temporaryHold);
storageObject.setMetadata(pbMetadata);
storageObject.setCacheControl(cacheControl);
storageObject.setContentEncoding(contentEncoding);
Expand Down Expand Up @@ -971,6 +1026,15 @@ public Acl apply(ObjectAccessControl objectAccessControl) {
if (storageObject.getKmsKeyName() != null) {
builder.setKmsKeyName(storageObject.getKmsKeyName());
}
if (storageObject.getEventBasedHold() != null) {
builder.setEventBasedHold(storageObject.getEventBasedHold());
}
if (storageObject.getTemporaryHold() != null) {
builder.setTemporaryHold(storageObject.getTemporaryHold());
}
if (storageObject.getRetentionExpirationTime() != null) {
builder.setRetentionExpirationTime(storageObject.getRetentionExpirationTime().getValue());
}
return builder.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -628,13 +628,36 @@ public Builder setLabels(Map<String, String> labels) {
return this;
}

@GcpLaunchStage.Beta
@Override
public Builder setDefaultKmsKeyName(String defaultKmsKeyName) {
infoBuilder.setDefaultKmsKeyName(defaultKmsKeyName);
return this;
}

@Override
public Builder setDefaultEventBasedHold(Boolean defaultEventBasedHold) {
infoBuilder.setDefaultEventBasedHold(defaultEventBasedHold);
return this;
}

@Override
Builder setRetentionEffectiveTime(Long retentionEffectiveTime) {
infoBuilder.setRetentionEffectiveTime(retentionEffectiveTime);
return this;
}

@Override
Builder setRetentionPolicyIsLocked(Boolean retentionIsLocked) {
infoBuilder.setRetentionPolicyIsLocked(retentionIsLocked);
return this;
}

@Override
public Builder setRetentionPeriod(Long retentionPeriod) {
infoBuilder.setRetentionPeriod(retentionPeriod);
return this;
}

@Override
public Bucket build() {
return new Bucket(storage, infoBuilder);
Expand Down Expand Up @@ -1111,6 +1134,28 @@ public List<Acl> listDefaultAcls() {
return storage.listDefaultAcls(getName());
}

/**
* Locks bucket retention policy. Requires a local metageneration value in the request. Review example below.
*
* Warning: Once a retention policy is locked, it can no longer be unlocked or removed only increased.

This comment was marked as spam.

*
* Accepts an optional userProject {@link BucketTargetOption} option which defines the project id

This comment was marked as spam.

* to assign operational costs.
*
* <p>Example of locking a retention policy on a bucket, only if its metageneration matches the buckets

This comment was marked as spam.

* metagenerationn otherwise a {@link StorageException} is thrown.

This comment was marked as spam.

* <pre> {@code
* String bucketName = "my_unique_bucket";
* Bucket bucket = storage.get(bucketName, BucketGetOption.fields(BucketField.METAGENERATION));
* bucket.lockRetentionPolicy(BucketTargetOption.metagenerationMatch());
* }</pre>
*
* @throws StorageException upon failure
*/
public Bucket lockRetentionPolicy(BucketTargetOption... options) {
return storage.lockRetentionPolicy(this, options);
}

/**
* Returns the bucket's {@code Storage} object used to issue requests.
*/
Expand Down
Loading