|
19 | 19 | import static com.google.common.base.Preconditions.checkArgument; |
20 | 20 | import static com.google.common.base.Preconditions.checkNotNull; |
21 | 21 |
|
| 22 | +import com.google.api.client.util.Data; |
22 | 23 | import com.google.api.core.BetaApi; |
23 | 24 | import com.google.api.gax.paging.Page; |
24 | 25 | import com.google.auth.ServiceAccountSigner; |
@@ -94,7 +95,7 @@ enum BucketField implements FieldSelector { |
94 | 95 | CORS("cors"), |
95 | 96 | STORAGE_CLASS("storageClass"), |
96 | 97 | ETAG("etag"), |
97 | | - DEFAULT_KMS_KEY_NAME("defaultKmsKeyName"), |
| 98 | + ENCRYPTION("encryption"), |
98 | 99 | BILLING("billing"); |
99 | 100 |
|
100 | 101 | static final List<? extends FieldSelector> REQUIRED_FIELDS = ImmutableList.of(NAME); |
@@ -207,6 +208,15 @@ public static BucketTargetOption metagenerationNotMatch() { |
207 | 208 | public static BucketTargetOption userProject(String userProject) { |
208 | 209 | return new BucketTargetOption(StorageRpc.Option.USER_PROJECT, userProject); |
209 | 210 | } |
| 211 | + |
| 212 | +// /** |
| 213 | +// * Returns an option to define the defaultKmsKeyName. |
| 214 | +// */ |
| 215 | +// public static BucketTargetOption defaultKmsKeyName(String defaultKmsKeyName) { |
| 216 | +// defaultKmsKeyName = defaultKmsKeyName != null |
| 217 | +// ? new String(defaultKmsKeyName) : Data.<String>nullOf(String.class); |
| 218 | +// return new BucketTargetOption(StorageRpc.Option.KMS_KEY_NAME, defaultKmsKeyName); |
| 219 | +// } |
210 | 220 | } |
211 | 221 |
|
212 | 222 | /** |
@@ -384,6 +394,15 @@ public static BlobTargetOption encryptionKey(String key) { |
384 | 394 | return new BlobTargetOption(StorageRpc.Option.CUSTOMER_SUPPLIED_KEY, key); |
385 | 395 | } |
386 | 396 |
|
| 397 | + /** |
| 398 | + * Returns an option to set a KMS key resource name of the blob. |
| 399 | + * |
| 400 | + * @param kmsKeyName the KMS crypto key resource name |
| 401 | + */ |
| 402 | + public static BlobTargetOption kmsKeyName(String kmsKeyName) { |
| 403 | + return new BlobTargetOption(StorageRpc.Option.KMS_KEY_NAME, kmsKeyName); |
| 404 | + } |
| 405 | + |
387 | 406 | static Tuple<BlobInfo, BlobTargetOption[]> convert(BlobInfo info, BlobWriteOption... options) { |
388 | 407 | BlobInfo.Builder infoBuilder = info.toBuilder().setCrc32c(null).setMd5(null); |
389 | 408 | List<BlobTargetOption> targetOptions = Lists.newArrayListWithCapacity(options.length); |
@@ -417,7 +436,7 @@ class BlobWriteOption implements Serializable { |
417 | 436 |
|
418 | 437 | enum Option { |
419 | 438 | PREDEFINED_ACL, IF_GENERATION_MATCH, IF_GENERATION_NOT_MATCH, IF_METAGENERATION_MATCH, |
420 | | - IF_METAGENERATION_NOT_MATCH, IF_MD5_MATCH, IF_CRC32C_MATCH, CUSTOMER_SUPPLIED_KEY, USER_PROJECT; |
| 439 | + IF_METAGENERATION_NOT_MATCH, IF_MD5_MATCH, IF_CRC32C_MATCH, CUSTOMER_SUPPLIED_KEY, USER_PROJECT, KMS_KEY_NAME; |
421 | 440 |
|
422 | 441 | StorageRpc.Option toRpcOption() { |
423 | 442 | return StorageRpc.Option.valueOf(this.name()); |
@@ -542,6 +561,10 @@ public static BlobWriteOption encryptionKey(String key) { |
542 | 561 | public static BlobWriteOption userProject(String userProject) { |
543 | 562 | return new BlobWriteOption(Option.USER_PROJECT, userProject); |
544 | 563 | } |
| 564 | + |
| 565 | + public static BlobWriteOption kmsKeyName(String kmsKeyName) { |
| 566 | + return new BlobWriteOption(Option.KMS_KEY_NAME, kmsKeyName); |
| 567 | + } |
545 | 568 | } |
546 | 569 |
|
547 | 570 | /** |
|
0 commit comments