Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Side by Side Diff: third_party/gsutil/gslib/commands/enablelogging.py

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # Copyright 2011 Google Inc.
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.exception import CommandException
26 from gslib.help_provider import HELP_NAME
27 from gslib.help_provider import HELP_NAME_ALIASES
28 from gslib.help_provider import HELP_ONE_LINE_SUMMARY
29 from gslib.help_provider import HELP_TEXT
30 from gslib.help_provider import HelpType
31 from gslib.help_provider import HELP_TYPE
32 from gslib.util import NO_MAX
33
34 _detailed_help_text = ("""
35 <B>SYNOPSIS</B>
36 gsutil enablelogging -b logging_bucket [-o log_object_prefix] uri...
37
38 <B>DESCRIPTION</B>
39 Google Cloud Storage offers access logs and storage data in the form of
40 CSV files that you can download and view. Access logs provide information
41 for all of the requests made on a specified bucket in the last 24 hours,
42 while the storage logs provide information about the storage consumption of
43 that bucket for the last 24 hour period. The logs and storage data files
44 are automatically created as new objects in a bucket that you specify, in
45 24 hour intervals.
46
47 The gsutil enablelogging command will enable access logging of the
48 buckets named by the specified uris, outputting log files in the specified
49 logging_bucket. logging_bucket must already exist, and all URIs must name
50 buckets (e.g., gs://bucket). For example, the command:
51
52 gsutil enablelogging -b gs://my_logging_bucket -o AccessLog \\
53 gs://my_bucket1 gs://my_bucket2
54
55 will cause all read and write activity to objects in gs://mybucket1 and
56 gs://mybucket2 to be logged to objects prefixed with the name "AccessLog",
57 with those log objects written to the bucket gs://my_logging_bucket.
58
59 Note that log data may contain sensitive information, so you should make
60 sure to set an appropriate default bucket ACL to protect that data. (See
61 "gsutil help setdefacl".)
62
63 You can check logging status using the gsutil getlogging command. For log
64 format details see "gsutil help getlogging".
65
66
67 <B>OPTIONS</B>
68 -b bucket Specifies the log bucket.
69
70 -o prefix Specifies the prefix for log object names. Default value
71 is the bucket name.
72 """)
73
74
75 class EnableLoggingCommand(Command):
76 """Implementation of gsutil enablelogging command."""
77
78 # Command specification (processed by parent class).
79 command_spec = {
80 # Name of command.
81 COMMAND_NAME : 'enablelogging',
82 # List of command name aliases.
83 COMMAND_NAME_ALIASES : [],
84 # Min number of args required by this command.
85 MIN_ARGS : 1,
86 # Max number of args required by this command, or NO_MAX.
87 MAX_ARGS : NO_MAX,
88 # Getopt-style string specifying acceptable sub args.
89 SUPPORTED_SUB_ARGS : 'b:o:',
90 # True if file URIs acceptable for this command.
91 FILE_URIS_OK : False,
92 # True if provider-only URIs acceptable for this command.
93 PROVIDER_URIS_OK : False,
94 # Index in args of first URI arg.
95 URIS_START_ARG : 0,
96 # True if must configure gsutil before running command.
97 CONFIG_REQUIRED : True,
98 }
99 help_spec = {
100 # Name of command or auxiliary help info for which this help applies.
101 HELP_NAME : 'enablelogging',
102 # List of help name aliases.
103 HELP_NAME_ALIASES : ['logging', 'logs', 'log'],
104 # Type of help:
105 HELP_TYPE : HelpType.COMMAND_HELP,
106 # One line summary of this help.
107 HELP_ONE_LINE_SUMMARY : 'Enable logging on buckets',
108 # The full help text.
109 HELP_TEXT : _detailed_help_text,
110 }
111
112 # Command entry point.
113 def RunCommand(self):
114 # Disallow multi-provider enablelogging calls, because the schemas
115 # differ.
116 storage_uri = self.UrisAreForSingleProvider(self.args)
117 if not storage_uri:
118 raise CommandException('enablelogging command spanning providers not '
119 'allowed.')
120 target_bucket_uri = None
121 target_prefix = None
122 for opt, opt_arg in self.sub_opts:
123 if opt == '-b':
124 target_bucket_uri = self.suri_builder.StorageUri(opt_arg)
125 if opt == '-o':
126 target_prefix = opt_arg
127
128 if not target_bucket_uri:
129 raise CommandException('enablelogging requires \'-b <log_bucket>\' '
130 'option')
131 if not target_bucket_uri.names_bucket():
132 raise CommandException('-b option must specify a bucket uri')
133
134 did_some_work = False
135 for uri_str in self.args:
136 for uri in self.exp_handler.WildcardIterator(uri_str).IterUris():
137 if uri.names_object():
138 raise CommandException('enablelogging cannot be applied to objects')
139 did_some_work = True
140 print 'Enabling logging on %s...' % uri
141 self.proj_id_handler.FillInProjectHeaderIfNeeded(
142 'enablelogging', storage_uri, self.headers)
143 uri.enable_logging(target_bucket_uri.bucket_name, target_prefix, False,
144 self.headers)
145 if not did_some_work:
146 raise CommandException('No URIs matched')
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/commands/disablelogging.py ('k') | third_party/gsutil/gslib/commands/getacl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698