本文整理了Java中com.google.cloud.storage.Bucket.getDefaultKmsKeyName()
方法的一些代码示例,展示了Bucket.getDefaultKmsKeyName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.getDefaultKmsKeyName()
方法的具体详情如下:
包路径:com.google.cloud.storage.Bucket
类名称:Bucket
方法名:getDefaultKmsKeyName
暂无
代码示例来源:origin: googleapis/google-cloud-java
/** Example of setting a default KMS key on a bucket. */
public Bucket setDefaultKmsKey(String bucketName, String kmsKeyName) throws StorageException {
// [START storage_set_bucket_default_kms_key]
// Instantiate a Google Cloud Storage client
Storage storage = StorageOptions.getDefaultInstance().getService();
// The name of the existing bucket to set a default KMS key for, e.g. "my-bucket"
// String bucketName = "my-bucket"
// The name of the KMS-key to use as a default
// Key names are provided in the following format:
// 'projects/<PROJECT>/locations/<LOCATION>/keyRings/<RING_NAME>/cryptoKeys/<KEY_NAME>'
// String kmsKeyName = ""
BucketInfo bucketInfo =
BucketInfo.newBuilder(bucketName).setDefaultKmsKeyName(kmsKeyName).build();
Bucket bucket = storage.update(bucketInfo);
System.out.println("Default KMS Key Name: " + bucket.getDefaultKmsKeyName());
// [END storage_set_bucket_default_kms_key]
return bucket;
}
代码示例来源:origin: googleapis/google-cloud-java
.build());
assertNotNull(remoteBucket);
assertTrue(remoteBucket.getDefaultKmsKeyName().startsWith(kmsKeyOneResourcePath));
try {
Iterator<Bucket> bucketIterator =
Bucket bucket = bucketIterator.next();
assertTrue(bucket.getName().startsWith(bucketName));
assertNotNull(bucket.getDefaultKmsKeyName());
assertTrue(bucket.getDefaultKmsKeyName().startsWith(kmsKeyOneResourcePath));
assertNull(bucket.getCreateTime());
assertNull(bucket.getSelfLink());
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testClearBucketDefaultKmsKeyName() throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
Bucket remoteBucket =
storage.create(
BucketInfo.newBuilder(bucketName)
.setDefaultKmsKeyName(kmsKeyOneResourcePath)
.setLocation(KMS_KEY_RING_LOCATION)
.build());
try {
assertEquals(kmsKeyOneResourcePath, remoteBucket.getDefaultKmsKeyName());
Bucket updatedBucket = remoteBucket.toBuilder().setDefaultKmsKeyName(null).build().update();
assertNull(updatedBucket.getDefaultKmsKeyName());
} finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testUpdateBucketDefaultKmsKeyName() throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
Bucket remoteBucket =
storage.create(
BucketInfo.newBuilder(bucketName)
.setDefaultKmsKeyName(kmsKeyOneResourcePath)
.setLocation(KMS_KEY_RING_LOCATION)
.build());
try {
assertEquals(kmsKeyOneResourcePath, remoteBucket.getDefaultKmsKeyName());
Bucket updatedBucket =
remoteBucket.toBuilder().setDefaultKmsKeyName(kmsKeyTwoResourcePath).build().update();
assertEquals(kmsKeyTwoResourcePath, updatedBucket.getDefaultKmsKeyName());
} finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}
代码示例来源:origin: googleapis/google-cloud-java
@Test
public void testCreateBlobWithDefaultKmsKeyName()
throws ExecutionException, InterruptedException {
String bucketName = RemoteStorageHelper.generateBucketName();
Bucket bucket =
storage.create(
BucketInfo.newBuilder(bucketName)
.setDefaultKmsKeyName(kmsKeyOneResourcePath)
.setLocation(KMS_KEY_RING_LOCATION)
.build());
assertEquals(bucket.getDefaultKmsKeyName(), kmsKeyOneResourcePath);
try {
String blobName = "test-create-with-default-kms-key-name-blob";
BlobInfo blob = BlobInfo.newBuilder(bucket, blobName).build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
assertEquals(blob.getBucket(), remoteBlob.getBucket());
assertEquals(blob.getName(), remoteBlob.getName());
assertNotNull(remoteBlob.getKmsKeyName());
assertTrue(remoteBlob.getKmsKeyName().startsWith(kmsKeyOneResourcePath));
byte[] readBytes = storage.readAllBytes(bucketName, blobName);
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
} finally {
RemoteStorageHelper.forceDelete(storage, bucketName, 5, TimeUnit.SECONDS);
}
}
代码示例来源:origin: googleapis/google-cloud-java
assertEquals(BUCKET_LABELS, bucket.getLabels());
assertEquals(REQUESTER_PAYS, bucket.requesterPays());
assertEquals(DEFAULT_KMS_KEY_NAME, bucket.getDefaultKmsKeyName());
assertEquals(DEFAULT_EVENT_BASED_HOLD, bucket.getDefaultEventBasedHold());
assertEquals(RETENTION_EFFECTIVE_TIME, bucket.getRetentionEffectiveTime());
内容来源于网络,如有侵权,请联系作者删除!