2626from gcloud import storage
2727
2828
29- def get_bucket_acl (bucket_name ):
29+ def print_bucket_acl (bucket_name ):
3030 """Prints out a bucket's access control list."""
3131 storage_client = storage .Client ()
3232 bucket = storage_client .bucket (bucket_name )
@@ -35,11 +35,12 @@ def get_bucket_acl(bucket_name):
3535 print ('{}: {}' .format (entry ['role' ], entry ['entity' ]))
3636
3737
38- def get_bucket_acl_for_user (bucket_name , user_email ):
38+ def print_bucket_acl_for_user (bucket_name , user_email ):
3939 """Prints out a bucket's access control list for a given user."""
4040 storage_client = storage .Client ()
4141 bucket = storage_client .bucket (bucket_name )
4242
43+ # Reload fetches the current ACL from Cloud Storage.
4344 bucket .acl .reload ()
4445
4546 # You can also use `group`, `domain`, `all_authenticated` and `all` to
@@ -49,26 +50,33 @@ def get_bucket_acl_for_user(bucket_name, user_email):
4950 print (roles )
5051
5152
52- def set_bucket_acl (bucket_name , user_email ):
53+ def add_bucket_owner (bucket_name , user_email ):
5354 """Adds a user as an owner on the given bucket."""
5455 storage_client = storage .Client ()
5556 bucket = storage_client .bucket (bucket_name )
5657
57- # You can also use `group`, `domain`, `all_authenticated` and `all` to
58- # grant access to different types of entities. You can also use
59- # `grant_read` or `grant_write` to grant different roles.
58+ # Reload fetches the current ACL from Cloud Storage.
59+ bucket .acl .reload ()
60+
61+ # You can also use `group()`, `domain()`, `all_authenticated()` and `all()`
62+ # to grant access to different types of entities.
63+ # You can also use `grant_read()` or `grant_write()` to grant different
64+ # roles.
6065 bucket .acl .user (user_email ).grant_owner ()
6166 bucket .acl .save ()
6267
6368 print ('Added user {} as an owner on bucket {}.' .format (
6469 user_email , bucket_name ))
6570
6671
67- def remove_bucket_acl (bucket_name , user_email ):
72+ def remove_bucket_owner (bucket_name , user_email ):
6873 """Removes a user from the access control list of the given bucket."""
6974 storage_client = storage .Client ()
7075 bucket = storage_client .bucket (bucket_name )
7176
77+ # Reload fetches the current ACL from Cloud Storage.
78+ bucket .acl .reload ()
79+
7280 # You can also use `group`, `domain`, `all_authenticated` and `all` to
7381 # remove access for different types of entities.
7482 bucket .acl .user (user_email ).revoke_read ()
@@ -80,12 +88,15 @@ def remove_bucket_acl(bucket_name, user_email):
8088 user_email , bucket_name ))
8189
8290
83- def set_bucket_default_acl (bucket_name , user_email ):
91+ def add_bucket_default_owner (bucket_name , user_email ):
8492 """Adds a user as an owner in the given bucket's default object access
8593 control list."""
8694 storage_client = storage .Client ()
8795 bucket = storage_client .bucket (bucket_name )
8896
97+ # Reload fetches the current ACL from Cloud Storage.
98+ bucket .acl .reload ()
99+
89100 # You can also use `group`, `domain`, `all_authenticated` and `all` to
90101 # grant access to different types of entities. You can also use
91102 # `grant_read` or `grant_write` to grant different roles.
@@ -96,12 +107,15 @@ def set_bucket_default_acl(bucket_name, user_email):
96107 user_email , bucket_name ))
97108
98109
99- def remove_bucket_default_acl (bucket_name , user_email ):
110+ def remove_bucket_default_owner (bucket_name , user_email ):
100111 """Removes a user from the access control list of the given bucket's
101112 default object access control list."""
102113 storage_client = storage .Client ()
103114 bucket = storage_client .bucket (bucket_name )
104115
116+ # Reload fetches the current ACL from Cloud Storage.
117+ bucket .acl .reload ()
118+
105119 # You can also use `group`, `domain`, `all_authenticated` and `all` to
106120 # remove access for different types of entities.
107121 bucket .default_object_acl .user (user_email ).revoke_read ()
@@ -113,7 +127,7 @@ def remove_bucket_default_acl(bucket_name, user_email):
113127 user_email , bucket_name ))
114128
115129
116- def get_blob_acl (bucket_name , blob_name ):
130+ def print_blob_acl (bucket_name , blob_name ):
117131 """Prints out a blob's access control list."""
118132 storage_client = storage .Client ()
119133 bucket = storage_client .bucket (bucket_name )
@@ -123,12 +137,13 @@ def get_blob_acl(bucket_name, blob_name):
123137 print ('{}: {}' .format (entry ['role' ], entry ['entity' ]))
124138
125139
126- def get_blob_acl_for_user (bucket_name , blob_name , user_email ):
127- """Prints out a bucket 's access control list for a given user."""
140+ def print_blob_acl_for_user (bucket_name , blob_name , user_email ):
141+ """Prints out a blob 's access control list for a given user."""
128142 storage_client = storage .Client ()
129143 bucket = storage_client .bucket (bucket_name )
130144 blob = bucket .blob (blob_name )
131145
146+ # Reload fetches the current ACL from Cloud Storage.
132147 blob .acl .reload ()
133148
134149 # You can also use `group`, `domain`, `all_authenticated` and `all` to
@@ -138,12 +153,15 @@ def get_blob_acl_for_user(bucket_name, blob_name, user_email):
138153 print (roles )
139154
140155
141- def set_blob_acl (bucket_name , blob_name , user_email ):
156+ def add_blob_owner (bucket_name , blob_name , user_email ):
142157 """Adds a user as an owner on the given blob."""
143158 storage_client = storage .Client ()
144159 bucket = storage_client .bucket (bucket_name )
145160 blob = bucket .blob (blob_name )
146161
162+ # Reload fetches the current ACL from Cloud Storage.
163+ blob .acl .reload ()
164+
147165 # You can also use `group`, `domain`, `all_authenticated` and `all` to
148166 # grant access to different types of entities. You can also use
149167 # `grant_read` or `grant_write` to grant different roles.
@@ -154,7 +172,7 @@ def set_blob_acl(bucket_name, blob_name, user_email):
154172 user_email , blob_name , bucket_name ))
155173
156174
157- def remove_blob_acl (bucket_name , blob_name , user_email ):
175+ def remove_blob_owner (bucket_name , blob_name , user_email ):
158176 """Removes a user from the access control list of the given blob in the
159177 given bucket."""
160178 storage_client = storage .Client ()
@@ -178,78 +196,78 @@ def remove_blob_acl(bucket_name, blob_name, user_email):
178196 formatter_class = argparse .RawDescriptionHelpFormatter )
179197 subparsers = parser .add_subparsers (dest = 'command' )
180198
181- get_bucket_acl_parser = subparsers .add_parser (
182- 'get -bucket-acl' , help = get_bucket_acl .__doc__ )
183- get_bucket_acl_parser .add_argument ('bucket_name' )
184-
185- get_bucket_acl_for_user_parser = subparsers .add_parser (
186- 'get -bucket-acl-for-user' , help = get_bucket_acl .__doc__ )
187- get_bucket_acl_for_user_parser .add_argument ('bucket_name' )
188- get_bucket_acl_for_user_parser .add_argument ('user_email' )
189-
190- set_bucket_acl_parser = subparsers .add_parser (
191- 'set -bucket-acl ' , help = set_bucket_acl .__doc__ )
192- set_bucket_acl_parser .add_argument ('bucket_name' )
193- set_bucket_acl_parser .add_argument ('user_email' )
194-
195- remove_bucket_acl_parser = subparsers .add_parser (
196- 'remove-bucket-acl ' , help = remove_bucket_acl .__doc__ )
197- remove_bucket_acl_parser .add_argument ('bucket_name' )
198- remove_bucket_acl_parser .add_argument ('user_email' )
199-
200- set_bucket_default_acl_parser = subparsers .add_parser (
201- 'set -bucket-default-acl ' , help = set_bucket_default_acl .__doc__ )
202- set_bucket_default_acl_parser .add_argument ('bucket_name' )
203- set_bucket_default_acl_parser .add_argument ('user_email' )
204-
205- remove_bucket_default_acl_parser = subparsers .add_parser (
206- 'remove-bucket-default-acl ' , help = remove_bucket_default_acl .__doc__ )
207- remove_bucket_default_acl_parser .add_argument ('bucket_name' )
208- remove_bucket_default_acl_parser .add_argument ('user_email' )
209-
210- get_blob_acl_parser = subparsers .add_parser (
211- 'get -blob-acl' , help = get_blob_acl .__doc__ )
212- get_blob_acl_parser .add_argument ('bucket_name' )
213- get_blob_acl_parser .add_argument ('blob_name' )
214-
215- get_blob_acl_for_user_parser = subparsers .add_parser (
216- 'get -blob-acl-for-user' , help = get_blob_acl_for_user .__doc__ )
217- get_blob_acl_for_user_parser .add_argument ('bucket_name' )
218- get_blob_acl_for_user_parser .add_argument ('blob_name' )
219- get_blob_acl_for_user_parser .add_argument ('user_email' )
220-
221- set_blob_acl_parser = subparsers .add_parser (
222- 'set -blob-acl ' , help = set_blob_acl .__doc__ )
223- set_blob_acl_parser .add_argument ('bucket_name' )
224- set_blob_acl_parser .add_argument ('blob_name' )
225- set_blob_acl_parser .add_argument ('user_email' )
226-
227- remove_blob_acl_parser = subparsers .add_parser (
228- 'remove-blob-acl ' , help = remove_blob_acl .__doc__ )
229- remove_blob_acl_parser .add_argument ('bucket_name' )
230- remove_blob_acl_parser .add_argument ('blob_name' )
231- remove_blob_acl_parser .add_argument ('user_email' )
199+ print_bucket_acl_parser = subparsers .add_parser (
200+ 'print -bucket-acl' , help = print_bucket_acl .__doc__ )
201+ print_bucket_acl_parser .add_argument ('bucket_name' )
202+
203+ print_bucket_acl_for_user_parser = subparsers .add_parser (
204+ 'print -bucket-acl-for-user' , help = print_bucket_acl .__doc__ )
205+ print_bucket_acl_for_user_parser .add_argument ('bucket_name' )
206+ print_bucket_acl_for_user_parser .add_argument ('user_email' )
207+
208+ add_bucket_owner_parser = subparsers .add_parser (
209+ 'add -bucket-owner ' , help = add_bucket_owner .__doc__ )
210+ add_bucket_owner_parser .add_argument ('bucket_name' )
211+ add_bucket_owner_parser .add_argument ('user_email' )
212+
213+ remove_bucket_owner_parser = subparsers .add_parser (
214+ 'remove-bucket-owner ' , help = remove_bucket_owner .__doc__ )
215+ remove_bucket_owner_parser .add_argument ('bucket_name' )
216+ remove_bucket_owner_parser .add_argument ('user_email' )
217+
218+ add_bucket_default_owner_parser = subparsers .add_parser (
219+ 'add -bucket-default-owner ' , help = add_bucket_default_owner .__doc__ )
220+ add_bucket_default_owner_parser .add_argument ('bucket_name' )
221+ add_bucket_default_owner_parser .add_argument ('user_email' )
222+
223+ remove_bucket_default_owner_parser = subparsers .add_parser (
224+ 'remove-bucket-default-owner ' , help = remove_bucket_default_owner .__doc__ )
225+ remove_bucket_default_owner_parser .add_argument ('bucket_name' )
226+ remove_bucket_default_owner_parser .add_argument ('user_email' )
227+
228+ print_blob_acl_parser = subparsers .add_parser (
229+ 'print -blob-acl' , help = print_blob_acl .__doc__ )
230+ print_blob_acl_parser .add_argument ('bucket_name' )
231+ print_blob_acl_parser .add_argument ('blob_name' )
232+
233+ print_blob_acl_for_user_parser = subparsers .add_parser (
234+ 'print -blob-acl-for-user' , help = print_blob_acl_for_user .__doc__ )
235+ print_blob_acl_for_user_parser .add_argument ('bucket_name' )
236+ print_blob_acl_for_user_parser .add_argument ('blob_name' )
237+ print_blob_acl_for_user_parser .add_argument ('user_email' )
238+
239+ add_blob_owner_parser = subparsers .add_parser (
240+ 'add -blob-owner ' , help = add_blob_owner .__doc__ )
241+ add_blob_owner_parser .add_argument ('bucket_name' )
242+ add_blob_owner_parser .add_argument ('blob_name' )
243+ add_blob_owner_parser .add_argument ('user_email' )
244+
245+ remove_blob_owner_parser = subparsers .add_parser (
246+ 'remove-blob-owner ' , help = remove_blob_owner .__doc__ )
247+ remove_blob_owner_parser .add_argument ('bucket_name' )
248+ remove_blob_owner_parser .add_argument ('blob_name' )
249+ remove_blob_owner_parser .add_argument ('user_email' )
232250
233251 args = parser .parse_args ()
234252
235- if args .command == 'get -bucket-acl' :
236- get_bucket_acl (args .bucket_name )
237- elif args .command == 'get -bucket-acl-for-user' :
238- get_bucket_acl_for_user (args .bucket_name , args .user_email )
239- elif args .command == 'set -bucket-acl ' :
240- set_bucket_acl (args .bucket_name , args .user_email )
241- elif args .command == 'remove-bucket-acl ' :
242- remove_bucket_acl (args .bucket_name , args .user_email )
243- elif args .command == 'set -bucket-default-acl ' :
244- set_bucket_default_acl (args .bucket_name , args .user_email )
245- elif args .command == 'remove-bucket-default-acl ' :
246- remove_bucket_default_acl (args .bucket_name , args .user_email )
247- elif args .command == 'get -blob-acl' :
248- get_blob_acl (args .bucket_name , args .blob_name )
249- elif args .command == 'get -blob-acl-for-user' :
250- get_blob_acl_for_user (
253+ if args .command == 'print -bucket-acl' :
254+ print_bucket_acl (args .bucket_name )
255+ elif args .command == 'print -bucket-acl-for-user' :
256+ print_bucket_acl_for_user (args .bucket_name , args .user_email )
257+ elif args .command == 'add -bucket-owner ' :
258+ add_bucket_owner (args .bucket_name , args .user_email )
259+ elif args .command == 'remove-bucket-owner ' :
260+ remove_bucket_owner (args .bucket_name , args .user_email )
261+ elif args .command == 'add -bucket-default-owner ' :
262+ add_bucket_default_owner (args .bucket_name , args .user_email )
263+ elif args .command == 'remove-bucket-default-owner ' :
264+ remove_bucket_default_owner (args .bucket_name , args .user_email )
265+ elif args .command == 'print -blob-acl' :
266+ print_blob_acl (args .bucket_name , args .blob_name )
267+ elif args .command == 'print -blob-acl-for-user' :
268+ print_blob_acl_for_user (
251269 args .bucket_name , args .blob_name , args .user_email )
252- elif args .command == 'set -blob-acl ' :
253- set_blob_acl (args .bucket_name , args .blob_name , args .user_email )
254- elif args .command == 'remove-blob-acl ' :
255- remove_blob_acl (args .bucket_name , args .blob_name , args .user_email )
270+ elif args .command == 'add -blob-owner ' :
271+ add_blob_owner (args .bucket_name , args .blob_name , args .user_email )
272+ elif args .command == 'remove-blob-owner ' :
273+ remove_blob_owner (args .bucket_name , args .blob_name , args .user_email )
0 commit comments