OLD | NEW |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 # Copyright 2011 Google Inc. All Rights Reserved. | 2 # Copyright 2011 Google Inc. All Rights Reserved. |
3 # | 3 # |
4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
7 # | 7 # |
8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
9 # | 9 # |
10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
(...skipping 12 matching lines...) Expand all Loading... |
23 from gslib.cloud_api import ServiceException | 23 from gslib.cloud_api import ServiceException |
24 from gslib.command import Command | 24 from gslib.command import Command |
25 from gslib.command import SetAclExceptionHandler | 25 from gslib.command import SetAclExceptionHandler |
26 from gslib.command import SetAclFuncWrapper | 26 from gslib.command import SetAclFuncWrapper |
27 from gslib.command_argument import CommandArgument | 27 from gslib.command_argument import CommandArgument |
28 from gslib.cs_api_map import ApiSelector | 28 from gslib.cs_api_map import ApiSelector |
29 from gslib.exception import CommandException | 29 from gslib.exception import CommandException |
30 from gslib.help_provider import CreateHelpText | 30 from gslib.help_provider import CreateHelpText |
31 from gslib.storage_url import StorageUrlFromString | 31 from gslib.storage_url import StorageUrlFromString |
32 from gslib.third_party.storage_apitools import storage_v1_messages as apitools_m
essages | 32 from gslib.third_party.storage_apitools import storage_v1_messages as apitools_m
essages |
| 33 from gslib.translation_helper import PRIVATE_DEFAULT_OBJ_ACL |
33 from gslib.util import NO_MAX | 34 from gslib.util import NO_MAX |
34 from gslib.util import Retry | 35 from gslib.util import Retry |
35 from gslib.util import UrlsAreForSingleProvider | 36 from gslib.util import UrlsAreForSingleProvider |
36 | 37 |
37 _SET_SYNOPSIS = """ | 38 _SET_SYNOPSIS = """ |
38 gsutil defacl set file-or-canned_acl_name url... | 39 gsutil defacl set file-or-canned_acl_name url... |
39 """ | 40 """ |
40 | 41 |
41 _GET_SYNOPSIS = """ | 42 _GET_SYNOPSIS = """ |
42 gsutil defacl get url | 43 gsutil defacl get url |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 Add the user john.doe@example.com to the default object ACL on bucket | 95 Add the user john.doe@example.com to the default object ACL on bucket |
95 example-bucket with READ access: | 96 example-bucket with READ access: |
96 | 97 |
97 gsutil defacl ch -u john.doe@example.com:READ gs://example-bucket | 98 gsutil defacl ch -u john.doe@example.com:READ gs://example-bucket |
98 | 99 |
99 Add the group admins@example.com to the default object ACL on bucket | 100 Add the group admins@example.com to the default object ACL on bucket |
100 example-bucket with OWNER access: | 101 example-bucket with OWNER access: |
101 | 102 |
102 gsutil defacl ch -g admins@example.com:O gs://example-bucket | 103 gsutil defacl ch -g admins@example.com:O gs://example-bucket |
103 | 104 |
104 Grant the owners of project example-project-123 READ access to new objects | 105 Remove the group admins@example.com from the default object ACL on bucket |
105 created in the bucket example-bucket: | 106 example-bucket: |
106 | 107 |
107 gsutil acl ch -p owners-example-project-123:R gs://example-bucket | 108 gsutil defacl ch -d admins@example.com gs://example-bucket |
| 109 |
| 110 Add the owners of project example-project-123 to the default object ACL on |
| 111 bucket example-bucket with READ access: |
| 112 |
| 113 gsutil defacl ch -p owners-example-project-123:R gs://example-bucket |
108 | 114 |
109 NOTE: You can replace 'owners' with 'viewers' or 'editors' to grant access | 115 NOTE: You can replace 'owners' with 'viewers' or 'editors' to grant access |
110 to a project's viewers/editors respectively. | 116 to a project's viewers/editors respectively. |
111 | 117 |
112 <B>CH OPTIONS</B> | 118 <B>CH OPTIONS</B> |
113 The "ch" sub-command has the following options | 119 The "ch" sub-command has the following options |
114 | 120 |
115 -d Remove all roles associated with the matching entity. | 121 -d Remove all roles associated with the matching entity. |
116 | 122 |
117 -f Normally gsutil stops at the first error. The -f option causes | 123 -f Normally gsutil stops at the first error. The -f option causes |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 current_acl = bucket.defaultObjectAcl | 267 current_acl = bucket.defaultObjectAcl |
262 | 268 |
263 modification_count = 0 | 269 modification_count = 0 |
264 for change in self.changes: | 270 for change in self.changes: |
265 modification_count += change.Execute( | 271 modification_count += change.Execute( |
266 url, current_acl, 'defacl', self.logger) | 272 url, current_acl, 'defacl', self.logger) |
267 if modification_count == 0: | 273 if modification_count == 0: |
268 self.logger.info('No changes to %s', url) | 274 self.logger.info('No changes to %s', url) |
269 return | 275 return |
270 | 276 |
| 277 if not current_acl: |
| 278 # Use a sentinel value to indicate a private (no entries) default |
| 279 # object ACL. |
| 280 current_acl.append(PRIVATE_DEFAULT_OBJ_ACL) |
| 281 |
271 try: | 282 try: |
272 preconditions = Preconditions(meta_gen_match=bucket.metageneration) | 283 preconditions = Preconditions(meta_gen_match=bucket.metageneration) |
273 bucket_metadata = apitools_messages.Bucket(defaultObjectAcl=current_acl) | 284 bucket_metadata = apitools_messages.Bucket(defaultObjectAcl=current_acl) |
274 self.gsutil_api.PatchBucket(url.bucket_name, bucket_metadata, | 285 self.gsutil_api.PatchBucket(url.bucket_name, bucket_metadata, |
275 preconditions=preconditions, | 286 preconditions=preconditions, |
276 provider=url.scheme, fields=['id']) | 287 provider=url.scheme, fields=['id']) |
277 except BadRequestException as e: | 288 except BadRequestException as e: |
278 # Don't retry on bad requests, e.g. invalid email address. | 289 # Don't retry on bad requests, e.g. invalid email address. |
279 raise CommandException('Received bad request from server: %s' % str(e)) | 290 raise CommandException('Received bad request from server: %s' % str(e)) |
280 except AccessDeniedException: | 291 except AccessDeniedException: |
(...skipping 14 matching lines...) Expand all Loading... |
295 elif action_subcommand == 'set': | 306 elif action_subcommand == 'set': |
296 func = self._SetDefAcl | 307 func = self._SetDefAcl |
297 elif action_subcommand in ('ch', 'change'): | 308 elif action_subcommand in ('ch', 'change'): |
298 func = self._ChDefAcl | 309 func = self._ChDefAcl |
299 else: | 310 else: |
300 raise CommandException(('Invalid subcommand "%s" for the %s command.\n' | 311 raise CommandException(('Invalid subcommand "%s" for the %s command.\n' |
301 'See "gsutil help defacl".') % | 312 'See "gsutil help defacl".') % |
302 (action_subcommand, self.command_name)) | 313 (action_subcommand, self.command_name)) |
303 func() | 314 func() |
304 return 0 | 315 return 0 |
OLD | NEW |