Skip to content

Commit 60652be

Browse files
frankynJesseLovelace
authored andcommitted
[Storage] Support rename of BPO to UniformBucketLevelAccess (GoogleCloudPlatform#2335)
* Update BPO -> UBLA * Update BPO -> UBLA
1 parent 70c3595 commit 60652be

6 files changed

+130
-123
lines changed

storage/cloud-client/README.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,11 @@ To run this sample:
312312
313313
314314
315-
Bucket Policy Only
315+
Uniform Bucket Level Access
316316
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
317317
318318
.. image:: https://gstatic.com/cloudssh/images/open-btn.png
319-
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=storage/cloud-client/bucket_policy_only.py,storage/cloud-client/README.rst
319+
:target: https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/GoogleCloudPlatform/python-docs-samples&page=editor&open_in_editor=storage/cloud-client/uniform_bucket_level_access.py,storage/cloud-client/README.rst
320320
321321
322322
@@ -325,20 +325,20 @@ To run this sample:
325325
326326
.. code-block:: bash
327327
328-
$ python bucket_policy_only.py
328+
$ python uniform_bucket_level_access.py
329329
330-
usage: bucket_policy_only.py [-h]
331-
{enable-bucket-policy-only,disable-bucket-policy-only,get-bucket-policy-only}
330+
usage: uniform_bucket_level_access.py [-h]
331+
{enable-uniform-bucket-level-access,disable-uniform-bucket-level-access,get-uniform-bucket-level-access}
332332
...
333333
334334
positional arguments:
335-
{enable-bucket-policy-only,disable-bucket-policy-only,get-bucket-policy-only}
336-
enable-bucket-policy-only
337-
Enable Bucket Policy Only for a bucket
338-
disable-bucket-policy-only
339-
Disable Bucket Policy Only for a bucket
340-
get-bucket-policy-only
341-
Get Bucket Policy Only for a bucket
335+
{enable-uniform-bucket-level-access,disable-uniform-bucket-level-access,get-uniform-bucket-level-access}
336+
enable-uniform-bucket-level-access
337+
Enable uniform bucket-level access for a bucket
338+
disable-uniform-bucket-level-access
339+
Disable uniform bucket-level access for a bucket
340+
get-uniform-bucket-level-access
341+
Get uniform bucket-level access for a bucket
342342
343343
optional arguments:
344344
-h, --help show this help message and exit
@@ -437,4 +437,4 @@ to `browse the source`_ and `report issues`_.
437437
https://github.com/GoogleCloudPlatform/google-cloud-python/issues
438438
439439
440-
.. _Google Cloud SDK: https://cloud.google.com/sdk/
440+
.. _Google Cloud SDK: https://cloud.google.com/sdk/

storage/cloud-client/README.rst.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ samples:
2727
- name: Bucket Lock
2828
file: bucket_lock.py
2929
show_help: true
30-
- name: Bucket Policy Only
31-
file: bucket_policy_only.py
30+
- name: Uniform bucket-level access
31+
file: uniform_bucket_level_access.py
3232
show_help: true
3333
- name: Notification Polling
3434
file: notification_polling.py

storage/cloud-client/bucket_policy_only.py

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

storage/cloud-client/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
google-cloud-pubsub==1.0.0
2-
google-cloud-storage==1.19.1
2+
google-cloud-storage==1.22.0
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2019 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the 'License');
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
import argparse
18+
19+
from google.cloud import storage
20+
21+
22+
def enable_uniform_bucket_level_access(bucket_name):
23+
"""Enable uniform bucket-level access for a bucket"""
24+
# [START storage_enable_uniform_bucket_level_access]
25+
# bucket_name = "my-bucket"
26+
27+
storage_client = storage.Client()
28+
bucket = storage_client.bucket(bucket_name)
29+
30+
bucket.iam_configuration.uniform_bucket_level_access_enabled = True
31+
bucket.patch()
32+
33+
print('Uniform bucket-level access was enabled for {}.'.format(
34+
bucket.name))
35+
# [END storage_enable_uniform_bucket_level_access]
36+
37+
38+
def disable_uniform_bucket_level_access(bucket_name):
39+
"""Disable uniform bucket-level access for a bucket"""
40+
# [START storage_uniform_bucket_level_access]
41+
# bucket_name = "my-bucket"
42+
43+
storage_client = storage.Client()
44+
bucket = storage_client.bucket(bucket_name)
45+
46+
bucket.iam_configuration.uniform_bucket_level_access_enabled = False
47+
bucket.patch()
48+
49+
print('Uniform bucket-level access was disabled for {}.'.format(
50+
bucket.name))
51+
52+
53+
def get_uniform_bucket_level_access(bucket_name):
54+
"""Get uniform bucket-level access for a bucket"""
55+
# [START storage_get_uniform_bucket_level_access]
56+
# bucket_name = "my-bucket"
57+
58+
storage_client = storage.Client()
59+
bucket = storage_client.get_bucket(bucket_name)
60+
iam_configuration = bucket.iam_configuration
61+
62+
if iam_configuration.uniform_bucket_level_access_enabled:
63+
print('Uniform bucket-level access is enabled for {}.'.format(
64+
bucket.name))
65+
print('Bucket will be locked on {}.'.format(
66+
iam_configuration.uniform_bucket_level_locked_time))
67+
else:
68+
print('Uniform bucket-level access is disabled for {}.'.format(
69+
bucket.name))
70+
# [END storage_get_uniform_bucket_level_access]
71+
72+
73+
if __name__ == '__main__':
74+
75+
parser = argparse.ArgumentParser(
76+
description=__doc__,
77+
formatter_class=argparse.RawDescriptionHelpFormatter)
78+
subparsers = parser.add_subparsers(dest='command')
79+
80+
enable_uniform_bucket_level_access_parser = subparsers.add_parser(
81+
'enable-uniform-bucket-level-access',
82+
help=enable_uniform_bucket_level_access.__doc__)
83+
enable_uniform_bucket_level_access_parser.add_argument('bucket_name')
84+
85+
disable_uniform_bucket_level_access_parser = subparsers.add_parser(
86+
'disable-uniform-bucket-level-access',
87+
help=disable_uniform_bucket_level_access.__doc__)
88+
disable_uniform_bucket_level_access_parser.add_argument('bucket_name')
89+
90+
get_uniform_bucket_level_access_parser = subparsers.add_parser(
91+
'get-uniform-bucket-level-access',
92+
help=get_uniform_bucket_level_access.__doc__)
93+
get_uniform_bucket_level_access_parser.add_argument('bucket_name')
94+
95+
args = parser.parse_args()
96+
97+
if args.command == 'enable-uniform-bucket-level-access':
98+
enable_uniform_bucket_level_access(args.bucket_name)
99+
elif args.command == 'disable-uniform-bucket-level-access':
100+
disable_uniform_bucket_level_access(args.bucket_name)
101+
elif args.command == 'get-uniform-bucket-level-access':
102+
get_uniform_bucket_level_access(args.bucket_name)

storage/cloud-client/bucket_policy_only_test.py renamed to storage/cloud-client/uniform_bucket_level_access_test.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,37 @@
1818

1919
import pytest
2020

21-
import bucket_policy_only
21+
import uniform_bucket_level_access
2222

2323

2424
@pytest.fixture()
2525
def bucket():
2626
"""Creates a test bucket and deletes it upon completion."""
2727
client = storage.Client()
28-
bucket_name = 'bucket-policy-only-' + str(int(time.time()))
28+
bucket_name = 'uniform-bucket-level-access-' + str(int(time.time()))
2929
bucket = client.create_bucket(bucket_name)
3030
yield bucket
3131
time.sleep(3)
3232
bucket.delete(force=True)
3333

3434

35-
def test_get_bucket_policy_only(bucket, capsys):
36-
bucket_policy_only.get_bucket_policy_only(bucket.name)
35+
def test_get_uniform_bucket_level_access(bucket, capsys):
36+
uniform_bucket_level_access.get_uniform_bucket_level_access(bucket.name)
3737
out, _ = capsys.readouterr()
38-
assert 'Bucket Policy Only is disabled for {}.'.format(
38+
assert 'Uniform bucket-level access is disabled for {}.'.format(
3939
bucket.name) in out
4040

4141

42-
def test_enable_bucket_policy_only(bucket, capsys):
43-
bucket_policy_only.enable_bucket_policy_only(bucket.name)
42+
def test_enable_uniform_bucket_level_access(bucket, capsys):
43+
uniform_bucket_level_access.enable_uniform_bucket_level_access(bucket.name)
4444
out, _ = capsys.readouterr()
45-
assert 'Bucket Policy Only was enabled for {}.'.format(
45+
assert 'Uniform bucket-level access was enabled for {}.'.format(
4646
bucket.name) in out
4747

4848

49-
def test_disable_bucket_policy_only(bucket, capsys):
50-
bucket_policy_only.disable_bucket_policy_only(bucket.name)
49+
def test_disable_uniform_bucket_level_access(bucket, capsys):
50+
uniform_bucket_level_access.disable_uniform_bucket_level_access(
51+
bucket.name)
5152
out, _ = capsys.readouterr()
52-
assert 'Bucket Policy Only was disabled for {}.'.format(
53+
assert 'Uniform bucket-level access was disabled for {}.'.format(
5354
bucket.name) in out

0 commit comments

Comments
 (0)