Skip to content

Commit

Permalink
chore: generate libraries at Tue Dec 10 17:14:47 UTC 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
cloud-java-bot committed Dec 10, 2024
1 parent 8a0de13 commit 05b7f6b
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 29 deletions.
12 changes: 9 additions & 3 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static void main(String[] args) {
static void deleteBlob(String bucketName, String blobName) {
// Customize retry behavior
RetrySettings retrySettings =
StorageOptions.getDefaultRetrySettings().toBuilder()
StorageOptions.getDefaultRetrySettings()
.toBuilder()
// Set the max number of attempts to 10 (initial attempt plus 9 retries)
.setMaxAttempts(10)
// Set the backoff multiplier to 3.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public static void disableRequesterPays(String projectId, String bucketName) {

Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Bucket bucket = storage.get(bucketName, Storage.BucketGetOption.userProject(projectId));
bucket.toBuilder()
bucket
.toBuilder()
.setRequesterPays(false)
.build()
.update(Storage.BucketTargetOption.userProject(projectId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static void disableSoftDelete(String projectId, String bucketName) {

Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Bucket bucket = storage.get(bucketName);
bucket.toBuilder()
bucket
.toBuilder()
.setSoftDeletePolicy(
// Setting the retention duration to 0 disables Soft Delete.
BucketInfo.SoftDeletePolicy.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static void enableLifecycleManagement(String projectId, String bucketName
// See the LifecycleRule documentation for additional info on what you can do with lifecycle
// management rules. This one deletes objects that are over 100 days old.
// https://googleapis.dev/java/google-cloud-clients/latest/com/google/cloud/storage/BucketInfo.LifecycleRule.html
bucket.toBuilder()
bucket
.toBuilder()
.setLifecycleRules(
ImmutableList.of(
new LifecycleRule(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public static void enableUniformBucketLevelAccess(String projectId, String bucke
BucketInfo.IamConfiguration.newBuilder().setIsUniformBucketLevelAccessEnabled(true).build();

storage.update(
bucket.toBuilder()
bucket
.toBuilder()
.setIamConfiguration(iamConfiguration)
.setAcl(null)
.setDefaultAcl(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public static void makeBucketPublic(String projectId, String bucketName) {
Policy originalPolicy = storage.getIamPolicy(bucketName);
storage.setIamPolicy(
bucketName,
originalPolicy.toBuilder()
originalPolicy
.toBuilder()
.addIdentity(StorageRoles.objectViewer(), Identity.allUsers()) // All users can view
.build());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public static void setBucketAutoclass(
Bucket bucket = storage.get(bucketName);

Bucket toUpdate =
bucket.toBuilder()
bucket
.toBuilder()
.setAutoclass(
Autoclass.newBuilder()
.setEnabled(enabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public static void setPublicAccessPreventionEnforced(String projectId, String bu
Bucket bucket = storage.get(bucketName);

// Enforces public access prevention for the bucket
bucket.toBuilder()
bucket
.toBuilder()
.setIamConfiguration(
BucketInfo.IamConfiguration.newBuilder()
.setPublicAccessPrevention(BucketInfo.PublicAccessPrevention.ENFORCED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public static void setPublicAccessPreventionInherited(String projectId, String b
Bucket bucket = storage.get(bucketName);

// Sets public access prevention to 'inherited' for the bucket
bucket.toBuilder()
bucket
.toBuilder()
.setIamConfiguration(
BucketInfo.IamConfiguration.newBuilder()
.setPublicAccessPrevention(BucketInfo.PublicAccessPrevention.INHERITED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public static void setRetentionPolicy(
Bucket bucket = storage.get(bucketName);
Bucket bucketWithRetentionPolicy =
storage.update(
bucket.toBuilder()
bucket
.toBuilder()
.setRetentionPeriodDuration(Duration.ofSeconds(retentionPeriodSeconds))
.build(),
BucketTargetOption.metagenerationMatch());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public static void setSoftDeletePolicy(String projectId, String bucketName) {

Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Bucket bucket = storage.get(bucketName);
bucket.toBuilder()
bucket
.toBuilder()
.setSoftDeletePolicy(
BucketInfo.SoftDeletePolicy.newBuilder()
.setRetentionDuration(Duration.ofDays(10))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,14 @@ public class ITBucketSnippets {
public static void beforeClass() {
RemoteStorageHelper helper = RemoteStorageHelper.create();
storage =
helper.getOptions().toBuilder()
helper
.getOptions()
.toBuilder()
.setRetrySettings(
helper.getOptions().getRetrySettings().toBuilder()
helper
.getOptions()
.getRetrySettings()
.toBuilder()
.setRetryDelayMultiplier(3.0)
.build())
.build()
Expand Down Expand Up @@ -221,7 +226,8 @@ public void testGetBucketMetadata() {
Bucket bucket =
storage.get(BUCKET, Storage.BucketGetOption.fields(Storage.BucketField.values()));
bucket =
bucket.toBuilder()
bucket
.toBuilder()
.setLabels(ImmutableMap.of("k", "v"))
.setLifecycleRules(
ImmutableList.of(
Expand Down Expand Up @@ -288,7 +294,9 @@ public void testEnableLifecycleManagement() throws Throwable {

@Test
public void testDisableLifecycleManagement() throws Throwable {
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setLifecycleRules(
ImmutableList.of(
new BucketInfo.LifecycleRule(
Expand All @@ -308,7 +316,9 @@ public void testGetPublicAccessPrevention() throws Throwable {
try {
// By default a bucket PAP state is INHERITED and we are changing the state to validate
// non-default state.
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setIamConfiguration(
BucketInfo.IamConfiguration.newBuilder()
.setPublicAccessPrevention(BucketInfo.PublicAccessPrevention.ENFORCED)
Expand All @@ -325,7 +335,9 @@ public void testGetPublicAccessPrevention() throws Throwable {
assertTrue(snippetOutput.contains("enforced"));
} finally {
// No matter what happens make sure test set bucket back to INHERITED
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setIamConfiguration(
BucketInfo.IamConfiguration.newBuilder()
.setPublicAccessPrevention(BucketInfo.PublicAccessPrevention.INHERITED)
Expand All @@ -347,7 +359,9 @@ public void testSetPublicAccessPreventionEnforced() throws Throwable {
BucketInfo.PublicAccessPrevention.ENFORCED));
} finally {
// No matter what happens make sure test set bucket back to INHERITED
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setIamConfiguration(
BucketInfo.IamConfiguration.newBuilder()
.setPublicAccessPrevention(BucketInfo.PublicAccessPrevention.INHERITED)
Expand All @@ -360,7 +374,9 @@ public void testSetPublicAccessPreventionEnforced() throws Throwable {
@Test
public void testSetPublicAccessPreventionInherited() throws Throwable {
try {
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setIamConfiguration(
BucketInfo.IamConfiguration.newBuilder()
.setPublicAccessPrevention(BucketInfo.PublicAccessPrevention.ENFORCED)
Expand All @@ -382,7 +398,9 @@ public void testSetPublicAccessPreventionInherited() throws Throwable {
BucketInfo.PublicAccessPrevention.INHERITED));
} finally {
// No matter what happens make sure test set bucket back to INHERITED
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setIamConfiguration(
BucketInfo.IamConfiguration.newBuilder()
.setPublicAccessPrevention(BucketInfo.PublicAccessPrevention.INHERITED)
Expand Down Expand Up @@ -441,7 +459,9 @@ public void testMakeBucketPublic() throws Throwable {

@Test
public void deleteBucketDefaultKmsKey() throws Throwable {
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setDefaultKmsKeyName(
"projects/cloud-java-ci-sample/locations/us/keyRings/"
+ "gcs_test_kms_key_ring/cryptoKeys/gcs_kms_key_one")
Expand Down Expand Up @@ -500,7 +520,9 @@ public void testConfigureBucketCors() throws Throwable {

@Test
public void testRemoveBucketCors() throws Throwable {
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setCors(
ImmutableList.of(
Cors.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ public void testSetObjectRetentionPolicy() {
assertNotNull(storage.get(tempBucket, retentionBlob).getRetention());
} finally {

storage.get(tempBucket, retentionBlob).toBuilder()
storage
.get(tempBucket, retentionBlob)
.toBuilder()
.setRetention(null)
.build()
.update(Storage.BlobTargetOption.overrideUnlockedRetention(true));
Expand All @@ -457,7 +459,9 @@ public void testSetObjectRetentionPolicy() {
@Test
public void testListSoftDeletedObjects() {
// This is already the default, but we set it here in case the default ever changes
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setSoftDeletePolicy(
BucketInfo.SoftDeletePolicy.newBuilder()
.setRetentionDuration(Duration.ofDays(7))
Expand All @@ -479,7 +483,9 @@ public void testListSoftDeletedObjects() {
@Test
public void testListSoftDeletedVersionsOfObject() {
// This is already the default, but we set it here in case the default ever changes
storage.get(BUCKET).toBuilder()
storage
.get(BUCKET)
.toBuilder()
.setSoftDeletePolicy(
BucketInfo.SoftDeletePolicy.newBuilder()
.setRetentionDuration(Duration.ofDays(7))
Expand Down Expand Up @@ -512,7 +518,9 @@ public void testRestoreSoftDeletedObject() {
storage.create(BucketInfo.of(bucket));
try {
// This is already the default, but we set it here in case the default ever changes
storage.get(bucket).toBuilder()
storage
.get(bucket)
.toBuilder()
.setSoftDeletePolicy(
BucketInfo.SoftDeletePolicy.newBuilder()
.setRetentionDuration(Duration.ofDays(7))
Expand Down

0 comments on commit 05b7f6b

Please sign in to comment.