| OLD | NEW |
| (Empty) |
| 1 # Copyright 2011 Google Inc. All Rights Reserved. | |
| 2 # | |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 # you may not use this file except in compliance with the License. | |
| 5 # You may obtain a copy of the License at | |
| 6 # | |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 # | |
| 9 # Unless required by applicable law or agreed to in writing, software | |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 # See the License for the specific language governing permissions and | |
| 13 # limitations under the License. | |
| 14 | |
| 15 from gslib.command import Command | |
| 16 from gslib.command import COMMAND_NAME | |
| 17 from gslib.command import COMMAND_NAME_ALIASES | |
| 18 from gslib.command import CONFIG_REQUIRED | |
| 19 from gslib.command import FILE_URIS_OK | |
| 20 from gslib.command import MAX_ARGS | |
| 21 from gslib.command import MIN_ARGS | |
| 22 from gslib.command import PROVIDER_URIS_OK | |
| 23 from gslib.command import SUPPORTED_SUB_ARGS | |
| 24 from gslib.command import URIS_START_ARG | |
| 25 from gslib.help_provider import HELP_NAME | |
| 26 from gslib.help_provider import HELP_NAME_ALIASES | |
| 27 from gslib.help_provider import HELP_ONE_LINE_SUMMARY | |
| 28 from gslib.help_provider import HELP_TEXT | |
| 29 from gslib.help_provider import HelpType | |
| 30 from gslib.help_provider import HELP_TYPE | |
| 31 from gslib.util import NO_MAX | |
| 32 | |
| 33 _detailed_help_text = (""" | |
| 34 <B>SYNOPSIS</B> | |
| 35 gsutil setacl [-R] file-or-canned_acl_name uri... | |
| 36 | |
| 37 | |
| 38 <B>DESCRIPTION</B> | |
| 39 The setacl command allows you to set an Access Control List on one or | |
| 40 more buckets and objects. The simplest way to use it is to specify one of | |
| 41 the canned ACLs, e.g.,: | |
| 42 | |
| 43 gsutil setacl private gs://bucket | |
| 44 | |
| 45 or: | |
| 46 | |
| 47 gsutil setacl public-read gs://bucket/object | |
| 48 | |
| 49 See "gsutil help acls" for a list of all canned ACLs. | |
| 50 | |
| 51 If you want to define more fine-grained control over your data, you can | |
| 52 retrieve an ACL using the getacl command (see "gsutil help getacl"), | |
| 53 save the output to a file, edit the file, and then use the gsutil setacl | |
| 54 command to set that ACL on the buckets and/or objects. For example: | |
| 55 | |
| 56 gsutil getacl gs://bucket/file.txt > acl.txt | |
| 57 (Make changes to acl.txt such as adding an additional grant.) | |
| 58 gsutil setacl acl.txt gs://cats/file.txt | |
| 59 | |
| 60 Note that you can set an ACL on multiple buckets or objects at once, | |
| 61 for example: | |
| 62 | |
| 63 gsutil setacl acl.txt gs://bucket/*.jpg | |
| 64 | |
| 65 If you have a large number of ACLs to update you might want to use the | |
| 66 gsutil -m option, to perform a parallel (multi-threaded/multi-processing) | |
| 67 update: | |
| 68 | |
| 69 gsutil -m setacl acl.txt gs://bucket/*.jpg | |
| 70 | |
| 71 Note that multi-threading/multi-processing is only done when the named URIs | |
| 72 refer to objects. gsutil -m setacl gs://bucket1 gs://bucket2 will run the | |
| 73 setacl operations sequentially. | |
| 74 | |
| 75 One other note: If you want to change a set of ACLs by adding and removing | |
| 76 grants, without the need to manually retrieve and edit the XML representation, | |
| 77 you can do that with the chacl command (see 'gsutil help chacl'). | |
| 78 | |
| 79 | |
| 80 <B>OPTIONS</B> | |
| 81 -R, -r Performs setacl request recursively, to all objects under the | |
| 82 specified URI. | |
| 83 | |
| 84 -a Performs setacl request on all object versions. | |
| 85 """) | |
| 86 | |
| 87 | |
| 88 class SetAclCommand(Command): | |
| 89 """Implementation of gsutil setacl command.""" | |
| 90 | |
| 91 # Command specification (processed by parent class). | |
| 92 command_spec = { | |
| 93 # Name of command. | |
| 94 COMMAND_NAME : 'setacl', | |
| 95 # List of command name aliases. | |
| 96 COMMAND_NAME_ALIASES : [], | |
| 97 # Min number of args required by this command. | |
| 98 MIN_ARGS : 2, | |
| 99 # Max number of args required by this command, or NO_MAX. | |
| 100 MAX_ARGS : NO_MAX, | |
| 101 # Getopt-style string specifying acceptable sub args. | |
| 102 SUPPORTED_SUB_ARGS : 'aRrv', | |
| 103 # True if file URIs acceptable for this command. | |
| 104 FILE_URIS_OK : False, | |
| 105 # True if provider-only URIs acceptable for this command. | |
| 106 PROVIDER_URIS_OK : False, | |
| 107 # Index in args of first URI arg. | |
| 108 URIS_START_ARG : 1, | |
| 109 # True if must configure gsutil before running command. | |
| 110 CONFIG_REQUIRED : True, | |
| 111 } | |
| 112 help_spec = { | |
| 113 # Name of command or auxiliary help info for which this help applies. | |
| 114 HELP_NAME : 'setacl', | |
| 115 # List of help name aliases. | |
| 116 HELP_NAME_ALIASES : [], | |
| 117 # Type of help: | |
| 118 HELP_TYPE : HelpType.COMMAND_HELP, | |
| 119 # One line summary of this help. | |
| 120 HELP_ONE_LINE_SUMMARY : 'Set bucket and/or object ACLs', | |
| 121 # The full help text. | |
| 122 HELP_TEXT : _detailed_help_text, | |
| 123 } | |
| 124 | |
| 125 # Command entry point. | |
| 126 def RunCommand(self): | |
| 127 if self.sub_opts: | |
| 128 for o, unused_a in self.sub_opts: | |
| 129 if o == '-a': | |
| 130 self.all_versions = True | |
| 131 elif o == '-r' or o == '-R': | |
| 132 self.recursion_requested = True | |
| 133 elif o == '-v': | |
| 134 self.THREADED_LOGGER.info('WARNING: The %s -v option is no longer' | |
| 135 ' needed, and will eventually be removed.\n' | |
| 136 % self.command_name) | |
| 137 self.SetAclCommandHelper() | |
| 138 return 0 | |
| OLD | NEW |