Skip to content

Commit c9c278a

Browse files
frankynbshaffer
authored andcommitted
[Storage] Support UniformBucketLevelAccess (GoogleCloudPlatform#936)
1 parent 4d9862a commit c9c278a

8 files changed

+151
-153
lines changed

storage/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ This simple command-line application demonstrates how to invoke
4444
object-acl Manage the ACL for Cloud Storage objects
4545
objects Manage Cloud Storage objects
4646
requester-pays Manage Cloud Storage requester pays buckets and objects
47-
bucket-policy-only Manage Cloud Storage bucket policy only buckets
47+
uniform-bucket-level-access Manage Cloud Storage uniform bucket-level access buckets
4848
get-object-v2-signed-url Generate a v2 signed URL for downloading an object.
4949
get-object-v4-signed-url Generate a v4 signed URL for downloading an object.
5050
get-object-v4-upload-signed-url Generate a v4 signed URL for uploading an object.

storage/composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
"src/delete_object.php",
2121
"src/delete_object_acl.php",
2222
"src/delete_hmac_key.php",
23-
"src/disable_bucket_policy_only.php",
23+
"src/disable_uniform_bucket_level_access.php",
2424
"src/disable_default_event_based_hold.php",
2525
"src/disable_requester_pays.php",
2626
"src/deactivate_hmac_key.php",
2727
"src/download_encrypted_object.php",
2828
"src/download_file_requester_pays.php",
2929
"src/download_object.php",
30-
"src/enable_bucket_policy_only.php",
30+
"src/enable_uniform_bucket_level_access.php",
3131
"src/enable_default_event_based_hold.php",
3232
"src/enable_default_kms_key.php",
3333
"src/enable_requester_pays.php",
@@ -39,7 +39,7 @@
3939
"src/get_bucket_default_acl.php",
4040
"src/get_bucket_default_acl_for_entity.php",
4141
"src/get_bucket_labels.php",
42-
"src/get_bucket_policy_only.php",
42+
"src/get_uniform_bucket_level_access.php",
4343
"src/get_object_acl.php",
4444
"src/get_object_acl_for_entity.php",
4545
"src/get_object_v2_signed_url.php",

storage/src/enable_bucket_policy_only.php renamed to storage/src/disable_uniform_bucket_level_access.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,31 @@
2323

2424
namespace Google\Cloud\Samples\Storage;
2525

26-
# [START storage_enable_bucket_policy_only]
26+
# [START storage_disable_uniform_bucket_level_access]
2727
use Google\Cloud\Storage\StorageClient;
2828

2929
/**
30-
* Enable Bucket Policy Only.
30+
* Enable uniform bucket-level access.
3131
*
3232
* @param string $bucketName Name of your Google Cloud Storage bucket.
3333
*
3434
* @return void
3535
*/
36-
function enable_bucket_policy_only($bucketName)
36+
function disable_uniform_bucket_level_access($bucketName)
3737
{
3838
$storage = new StorageClient();
3939
$bucket = $storage->bucket($bucketName);
4040
$bucket->update([
4141
'iamConfiguration' => [
42+
'uniformBucketLevelAccess' => [
43+
'enabled' => false
44+
],
45+
// This is a workaround
4246
'bucketPolicyOnly' => [
43-
'enabled' => true
44-
]
47+
'enabled' => false
48+
],
4549
]
4650
]);
47-
printf('Bucket Policy Only was enabled for %s' . PHP_EOL, $bucketName);
51+
printf('Uniform bucket-level access was disabled for %s' . PHP_EOL, $bucketName);
4852
}
49-
# [END storage_enable_bucket_policy_only]
53+
# [END storage_disable_uniform_bucket_level_access]

storage/src/disable_bucket_policy_only.php renamed to storage/src/enable_uniform_bucket_level_access.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,31 @@
2323

2424
namespace Google\Cloud\Samples\Storage;
2525

26-
# [START storage_disable_bucket_policy_only]
26+
# [START storage_enable_uniform_bucket_level_access]
2727
use Google\Cloud\Storage\StorageClient;
2828

2929
/**
30-
* Enable Bucket Policy Only.
30+
* Enable uniform bucket-level access.
3131
*
3232
* @param string $bucketName Name of your Google Cloud Storage bucket.
3333
*
3434
* @return void
3535
*/
36-
function disable_bucket_policy_only($bucketName)
36+
function enable_uniform_bucket_level_access($bucketName)
3737
{
3838
$storage = new StorageClient();
3939
$bucket = $storage->bucket($bucketName);
4040
$bucket->update([
4141
'iamConfiguration' => [
42+
'uniformBucketLevelAccess' => [
43+
'enabled' => true
44+
],
45+
// This is a workaround
4246
'bucketPolicyOnly' => [
43-
'enabled' => false
47+
'enabled' => true
4448
]
4549
]
4650
]);
47-
printf('Bucket Policy Only was disabled for %s' . PHP_EOL, $bucketName);
51+
printf('Uniform bucket-level access was enabled for %s' . PHP_EOL, $bucketName);
4852
}
49-
# [END storage_disable_bucket_policy_only]
53+
# [END storage_enable_uniform_bucket_level_access]

storage/src/get_bucket_policy_only.php renamed to storage/src/get_uniform_bucket_level_access.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@
2323

2424
namespace Google\Cloud\Samples\Storage;
2525

26-
# [START storage_get_bucket_policy_only]
26+
# [START storage_get_uniform_bucket_level_access]
2727
use Google\Cloud\Storage\StorageClient;
2828

2929
/**
30-
* Enable Bucket Policy Only.
30+
* Enable uniform bucket-level access.
3131
*
3232
* @param string $bucketName Name of your Google Cloud Storage bucket.
3333
*
3434
* @return void
3535
*/
36-
function get_bucket_policy_only($bucketName)
36+
function get_uniform_bucket_level_access($bucketName)
3737
{
3838
$storage = new StorageClient();
3939
$bucket = $storage->bucket($bucketName);
4040
$bucketInformation = $bucket->info();
41-
$bucketPolicyOnly = $bucketInformation['iamConfiguration']['bucketPolicyOnly'];
42-
if ($bucketPolicyOnly['enabled']) {
43-
printf('Bucket Policy Only is enabled for %s' . PHP_EOL, $bucketName);
44-
printf('Bucket Policy Only will be locked on %s' . PHP_EOL, $bucketPolicyOnly['LockedTime']);
41+
$ubla = $bucketInformation['iamConfiguration']['uniformBucketLevelAccess'];
42+
if ($ubla['enabled']) {
43+
printf('Uniform bucket-level access is enabled for %s' . PHP_EOL, $bucketName);
44+
printf('Uniform bucket-level access will be locked on %s' . PHP_EOL, $ubla['LockedTime']);
4545
} else {
46-
printf('Bucket Policy Only is disabled for %s' . PHP_EOL, $bucketName);
46+
printf('Uniform bucket-level access is disabled for %s' . PHP_EOL, $bucketName);
4747
}
4848
}
49-
# [END storage_get_bucket_policy_only]
49+
# [END storage_get_uniform_bucket_level_access]

storage/storage.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -405,27 +405,27 @@
405405
}
406406
});
407407

408-
$application->add(new Command('bucket-policy-only'))
409-
->setDescription('Manage Cloud Storage bucket policy only buckets.')
408+
$application->add(new Command('uniform-bucket-level-access'))
409+
->setDescription('Manage Cloud Storage uniform bucket-level access buckets.')
410410
->setHelp(<<
411-
The %command.name% command manages Cloud Storage bucket policy only buckets.
411+
The %command.name% command manages Cloud Storage uniform bucket-level access buckets.
412412
413413
php %command.full_name% --help
414414
415415
EOF
416416
)
417-
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage Bucket Policy Only bucket name')
418-
->addOption('enable', null, InputOption::VALUE_NONE, 'Enable Bucket Policy Only on a Cloud Storage bucket')
419-
->addOption('disable', null, InputOption::VALUE_NONE, 'Disable Bucket Policy Only on a Cloud Storage bucket')
420-
->addOption('get', null, InputOption::VALUE_NONE, 'Get Bucket Policy Only on a Cloud Storage bucekt')
417+
->addArgument('bucket', InputArgument::REQUIRED, 'The Cloud Storage uniform bucket-level access bucket name')
418+
->addOption('enable', null, InputOption::VALUE_NONE, 'Enable uniform bucket-level access on a Cloud Storage bucket')
419+
->addOption('disable', null, InputOption::VALUE_NONE, 'Disable uniform bucket-level access on a Cloud Storage bucket')
420+
->addOption('get', null, InputOption::VALUE_NONE, 'Get uniform bucket-level access on a Cloud Storage bucekt')
421421
->setCode(function ($input, $output) {
422422
$bucketName = $input->getArgument('bucket');
423423
if ($input->getOption('enable')) {
424-
enable_bucket_policy_only($bucketName);
424+
enable_uniform_bucket_level_access($bucketName);
425425
} elseif ($input->getOption('disable')) {
426-
disable_bucket_policy_only($bucketName);
426+
disable_uniform_bucket_level_access($bucketName);
427427
} elseif ($input->getOption('get')) {
428-
get_bucket_policy_only($bucketName);
428+
get_uniform_bucket_level_access($bucketName);
429429
} else {
430430
throw new \Exception('You must provide --enable, --disable, or --get with a bucket name.');
431431
}

storage/test/BucketPolicyOnlyCommandTest.php

Lines changed: 0 additions & 117 deletions
This file was deleted.

0 commit comments

Comments
 (0)