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

Side by Side Diff: gslib/project_id.py

Issue 698893003: Update checked in version of gsutil to version 4.6 (Closed) Base URL: http://dart.googlecode.com/svn/third_party/gsutil/
Patch Set: Created 6 years, 1 month 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
« no previous file with comments | « gslib/progress_callback.py ('k') | gslib/storage_uri_builder.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # -*- coding: utf-8 -*-
1 # Copyright 2011 Google Inc. All Rights Reserved. 2 # Copyright 2011 Google Inc. All Rights Reserved.
2 # 3 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # 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 not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 6 # You may obtain a copy of the License at
6 # 7 #
7 # http://www.apache.org/licenses/LICENSE-2.0 8 # http://www.apache.org/licenses/LICENSE-2.0
8 # 9 #
9 # Unless required by applicable law or agreed to in writing, software 10 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and 13 # See the License for the specific language governing permissions and
13 # limitations under the License. 14 # limitations under the License.
15 """Helper module for Google Cloud Storage project IDs."""
16
17 from __future__ import absolute_import
14 18
15 import boto 19 import boto
16 20
17 from gslib.exception import ProjectIdException 21 from gslib.cloud_api import ProjectIdException
18 from gslib.wildcard_iterator import WILDCARD_BUCKET_ITERATOR
19 22
20 GOOG_PROJ_ID_HDR = 'x-goog-project-id' 23 GOOG_PROJ_ID_HDR = 'x-goog-project-id'
21 24
22 25
23 class ProjectIdHandler(object): 26 def PopulateProjectId(project_id=None):
24 """Google Project ID header handling.""" 27 """Fills in a project_id from the boto config file if one is not provided."""
25 28 if not project_id:
26 def __init__(self): 29 default_id = boto.config.get_value('GSUtil', 'default_project_id')
27 """Instantiates Project ID handler. Call after boto config file loaded.""" 30 if not default_id:
28 config = boto.config 31 raise ProjectIdException('MissingProjectId')
29 self.project_id = config.get_value('GSUtil', 'default_project_id') 32 return default_id
30 33 return project_id
31 def SetProjectId(self, project_id):
32 """Overrides project ID value from config file default.
33
34 Args:
35 project_id: Project ID to use.
36 """
37 self.project_id = project_id
38
39 def FillInProjectHeaderIfNeeded(self, command, uri, headers):
40 """Fills project ID header into headers if defined and applicable.
41
42 Args:
43 command: The command being run.
44 uri: The URI against which this command is being run.
45 headers: Dictionary containing optional HTTP headers to pass to boto.
46 Must not be None.
47 """
48
49 # We only include the project ID header if it's a GS URI and a project_id
50 # was specified and
51 # (it's an 'mb', 'logging set off', or 'logging set on' command or
52 # a boto request in integration tests or
53 # (an 'ls' command that doesn't specify a bucket or wildcarded bucket)).
54 if (uri.scheme.lower() == 'gs' and self.project_id
55 and (command == 'mb' or command == 'disablelogging'
56 or command == 'enablelogging'
57 or command == 'test'
58 or (command == 'ls' and not uri.names_bucket())
59 or (command == WILDCARD_BUCKET_ITERATOR))):
60 # Note: check for None (as opposed to "not headers") here because
61 # it's ok to pass empty headers.
62 if headers is None:
63 raise ProjectIdException(
64 'FillInProjectHeaderIfNeeded called with headers=None')
65 headers[GOOG_PROJ_ID_HDR] = self.project_id
66 elif headers.has_key(GOOG_PROJ_ID_HDR):
67 del headers[GOOG_PROJ_ID_HDR]
OLDNEW
« no previous file with comments | « gslib/progress_callback.py ('k') | gslib/storage_uri_builder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698