Search in sources :

Example 1 with BucketInfo

use of com.google.cloud.storage.BucketInfo in project google-cloud-java by GoogleCloudPlatform.

the class StorageSnippets method updateBucket.

/**
 * Example of updating bucket information.
 */
// [TARGET update(BucketInfo, BucketTargetOption...)]
// [VARIABLE "my_unique_bucket"]
public Bucket updateBucket(String bucketName) {
    // [START updateBucket]
    BucketInfo bucketInfo = BucketInfo.newBuilder(bucketName).setVersioningEnabled(true).build();
    Bucket bucket = storage.update(bucketInfo);
    // [END updateBucket]
    return bucket;
}
Also used : Bucket(com.google.cloud.storage.Bucket) BucketInfo(com.google.cloud.storage.BucketInfo)

Example 2 with BucketInfo

use of com.google.cloud.storage.BucketInfo in project google-cloud-java by GoogleCloudPlatform.

the class StorageSnippets method setDefaultKmsKey.

/**
 * 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;
}
Also used : Storage(com.google.cloud.storage.Storage) Bucket(com.google.cloud.storage.Bucket) BucketInfo(com.google.cloud.storage.BucketInfo)

Aggregations

Bucket (com.google.cloud.storage.Bucket)2 BucketInfo (com.google.cloud.storage.BucketInfo)2 Storage (com.google.cloud.storage.Storage)1