Skip to content

Commit

Permalink
🦉 Updates from OwlBot post-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
gcf-owl-bot[bot] committed Feb 15, 2024
1 parent a80829c commit a42e53f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 56 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ implementation 'com.google.cloud:google-cloud-storage'
If you are using Gradle without BOM, add this to your dependencies:

```Groovy
implementation 'com.google.cloud:google-cloud-storage:2.33.0'
implementation 'com.google.cloud:google-cloud-storage:2.34.0'
```

If you are using SBT, add this to your dependencies:

```Scala
libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.33.0"
libraryDependencies += "com.google.cloud" % "google-cloud-storage" % "2.34.0"
```
<!-- {x-version-update-end} -->

Expand Down Expand Up @@ -237,6 +237,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/
| Create Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucket.java) |
| Create Bucket Dual Region | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketDualRegion.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketDualRegion.java) |
| Create Bucket Pub Sub Notification | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketPubSubNotification.java) |
| Create Bucket With Object Retention | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithObjectRetention.java) |
| Create Bucket With Storage Class And Location | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithStorageClassAndLocation.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithStorageClassAndLocation.java) |
| Create Bucket With Turbo Replication | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithTurboReplication.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/CreateBucketWithTurboReplication.java) |
| Delete Bucket | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucket.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/bucket/DeleteBucket.java) |
Expand Down Expand Up @@ -322,6 +323,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/java-storage/tree/
| Rotate Object Encryption Key | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/RotateObjectEncryptionKey.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/RotateObjectEncryptionKey.java) |
| Set Event Based Hold | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetEventBasedHold.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetEventBasedHold.java) |
| Set Object Metadata | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetObjectMetadata.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetObjectMetadata.java) |
| Set Object Retention Policy | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetObjectRetentionPolicy.java) |
| Set Temporary Hold | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/SetTemporaryHold.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/SetTemporaryHold.java) |
| Stream Object Download | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/StreamObjectDownload.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/StreamObjectDownload.java) |
| Stream Object Upload | [source code](https://github.com/googleapis/java-storage/blob/main/samples/snippets/src/main/java/com/example/storage/object/StreamObjectUpload.java) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/java-storage&page=editor&open_in_editor=samples/snippets/src/main/java/com/example/storage/object/StreamObjectUpload.java) |
Expand Down Expand Up @@ -428,7 +430,7 @@ Java is a registered trademark of Oracle and/or its affiliates.
[kokoro-badge-link-5]: http://storage.googleapis.com/cloud-devrel-public/java/badges/java-storage/java11.html
[stability-image]: https://img.shields.io/badge/stability-stable-green
[maven-version-image]: https://img.shields.io/maven-central/v/com.google.cloud/google-cloud-storage.svg
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-storage/2.33.0
[maven-version-link]: https://central.sonatype.com/artifact/com.google.cloud/google-cloud-storage/2.34.0
[authentication]: https://github.com/googleapis/google-cloud-java#authentication
[auth-scopes]: https://developers.google.com/identity/protocols/oauth2/scopes
[predefined-iam-roles]: https://cloud.google.com/iam/docs/understanding-roles#predefined_roles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,25 @@
import com.google.cloud.storage.StorageOptions;

public class CreateBucketWithObjectRetention {
public static void createBucketWithObjectRetention(String projectId, String bucketName) {
// The ID of your GCP project
// String projectId = "your-project-id";
public static void createBucketWithObjectRetention(String projectId, String bucketName) {
// The ID of your GCP project
// String projectId = "your-project-id";

// The ID to give your GCS bucket
// String bucketName = "your-unique-bucket-name";
// The ID to give your GCS bucket
// String bucketName = "your-unique-bucket-name";

Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();

Bucket bucket = storage.create(BucketInfo.of(bucketName), Storage.BucketTargetOption.enableObjectRetention(true));
Bucket bucket =
storage.create(
BucketInfo.of(bucketName), Storage.BucketTargetOption.enableObjectRetention(true));

System.out.println(
"Created bucket "
+ bucket.getName()
+ " with object retention enabled setting: "
+ bucket.getObjectRetention().getMode().toString());
}
System.out.println(
"Created bucket "
+ bucket.getName()
+ " with object retention enabled setting: "
+ bucket.getObjectRetention().getMode().toString());
}
}

// [END storage_create_bucket_with_object_retention]
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,58 @@

// [START storage_set_object_retention_policy]

import static java.time.OffsetDateTime.now;

import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo.Retention;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageException;
import com.google.cloud.storage.StorageOptions;


import static java.time.OffsetDateTime.now;

public class SetObjectRetentionPolicy {
public static void setObjectRetentionPolicy(String projectId, String bucketName, String objectName)
throws StorageException {
// The ID of your GCP project
// String projectId = "your-project-id";

// The ID of your GCS bucket that has object retention enabled
// String bucketName = "your-unique-bucket-name";
public static void setObjectRetentionPolicy(
String projectId, String bucketName, String objectName) throws StorageException {
// The ID of your GCP project
// String projectId = "your-project-id";

// The ID of your GCS object
// String objectName = "your-object-name";
// The ID of your GCS bucket that has object retention enabled
// String bucketName = "your-unique-bucket-name";

Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
BlobId blobId = BlobId.of(bucketName, objectName);
Blob blob = storage.get(blobId);
if (blob == null) {
System.out.println("The object " + objectName + " was not found in " + bucketName);
return;
}
// The ID of your GCS object
// String objectName = "your-object-name";

Blob updated = blob.toBuilder().setRetention(Retention.newBuilder()
.setMode(Retention.Mode.UNLOCKED)
.setRetainUntilTime(now().plusDays(10))
.build())
.build()
.update();
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
BlobId blobId = BlobId.of(bucketName, objectName);
Blob blob = storage.get(blobId);
if (blob == null) {
System.out.println("The object " + objectName + " was not found in " + bucketName);
return;
}

System.out.println("Retention policy for object " + objectName + " was set to:");
System.out.println(updated.getRetention().toString());
Blob updated =
blob.toBuilder()
.setRetention(
Retention.newBuilder()
.setMode(Retention.Mode.UNLOCKED)
.setRetainUntilTime(now().plusDays(10))
.build())
.build()
.update();

// To modify an existing policy on an Unlocked object, pass in the override parameter
blob.toBuilder().setRetention(updated.getRetention()
.toBuilder().setRetainUntilTime(now().plusDays(9)).build())
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));
System.out.println("Retention policy for object " + objectName + " was set to:");
System.out.println(updated.getRetention().toString());

// To modify an existing policy on an Unlocked object, pass in the override parameter
blob.toBuilder()
.setRetention(
updated.getRetention().toBuilder().setRetainUntilTime(now().plusDays(9)).build())
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));

System.out.println("Retention policy for object " + objectName + " was updated to:");
System.out.println(storage.get(blobId).getRetention().toString());
}
System.out.println("Retention policy for object " + objectName + " was updated to:");
System.out.println(storage.get(blobId).getRetention().toString());
}
}

// [START storage_set_object_retention_policy]
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,5 @@ public void testCreateBucketWithObjectRetention() {
} finally {
storage.delete(tempBucket);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.BlobId;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.Storage.BlobListOption;
Expand Down Expand Up @@ -440,15 +439,21 @@ public void testBatchSetObjectMetadata() {
@Test
public void testSetObjectRetentionPolicy() {
String tempBucket = RemoteStorageHelper.generateBucketName();
storage.create(BucketInfo.of(tempBucket), Storage.BucketTargetOption.enableObjectRetention(true));
storage.create(
BucketInfo.of(tempBucket), Storage.BucketTargetOption.enableObjectRetention(true));
String retentionBlob = "retentionblob";
storage.create(BlobInfo.newBuilder(tempBucket, retentionBlob).build());
assertNull(storage.get(tempBucket, retentionBlob).getRetention());
try {
SetObjectRetentionPolicy.setObjectRetentionPolicy(PROJECT_ID, tempBucket, retentionBlob);
assertNotNull(storage.get(tempBucket, retentionBlob).getRetention());
} finally {
storage.get(tempBucket, retentionBlob).toBuilder().setRetention(null).build().update(Storage.BlobTargetOption.overrideUnlockedRetention(true));
storage
.get(tempBucket, retentionBlob)
.toBuilder()
.setRetention(null)
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));
storage.delete(tempBucket, retentionBlob);
storage.delete(tempBucket);
}
Expand Down

0 comments on commit a42e53f

Please sign in to comment.