summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Houglum <houglum@google.com>2019-08-09 13:45:46 -0700
committerMax Illfelder <illfelder@users.noreply.github.com>2019-08-09 13:45:46 -0700
commit6bf2ff4479e007698f11c40958abf0759fcf6f48 (patch)
treec86f63304ec1b8e1280c56992600d4c6b91eeb4e
parent324758120ce4ef7eaaf6cfcbbc0712dcf164d7bb (diff)
downloadgoogle-compute-image-packages-6bf2ff4479e007698f11c40958abf0759fcf6f48.tar.gz
Use non-numeric project ID in generated boto.cfg for GSUtil (#828)
* Generated boto cfg now uses project ID, not number ...for the "default_project_id" attribute under the [GSUtil] section of the config file at /etc/boto.cfg. Fixes #827. * Fix indentation/line-wrap style.
-rw-r--r--packages/python-google-compute-engine/google_compute_engine/boto/boto_config.py13
-rw-r--r--packages/python-google-compute-engine/google_compute_engine/boto/tests/boto_config_test.py4
2 files changed, 9 insertions, 8 deletions
diff --git a/packages/python-google-compute-engine/google_compute_engine/boto/boto_config.py b/packages/python-google-compute-engine/google_compute_engine/boto/boto_config.py
index 2c92d9d..4db24b4 100644
--- a/packages/python-google-compute-engine/google_compute_engine/boto/boto_config.py
+++ b/packages/python-google-compute-engine/google_compute_engine/boto/boto_config.py
@@ -58,14 +58,15 @@ class BotoConfig(object):
self.watcher = metadata_watcher.MetadataWatcher(logger=self.logger)
self._CreateConfig(project_id)
- def _GetNumericProjectId(self):
- """Get the numeric project ID for this VM.
+ def _GetProjectId(self):
+ """Get the (non-numeric) project ID for this VM.
Returns:
- string, the numeric project ID if one is found.
+ string, the project ID if one is found.
"""
- project_id = 'project/numeric-project-id'
- return self.watcher.GetMetadata(metadata_key=project_id, recursive=False)
+ project_id_key = 'project/project-id'
+ return self.watcher.GetMetadata(
+ metadata_key=project_id_key, recursive=False)
def _CreateConfig(self, project_id):
"""Create the boto config to support standalone GSUtil.
@@ -73,7 +74,7 @@ class BotoConfig(object):
Args:
project_id: string, the project ID to use in the config file.
"""
- project_id = project_id or self._GetNumericProjectId()
+ project_id = project_id or self._GetProjectId()
# Our project doesn't support service accounts.
if not project_id:
diff --git a/packages/python-google-compute-engine/google_compute_engine/boto/tests/boto_config_test.py b/packages/python-google-compute-engine/google_compute_engine/boto/tests/boto_config_test.py
index bc2c05a..1b57e19 100644
--- a/packages/python-google-compute-engine/google_compute_engine/boto/tests/boto_config_test.py
+++ b/packages/python-google-compute-engine/google_compute_engine/boto/tests/boto_config_test.py
@@ -68,7 +68,7 @@ class BotoConfigTest(unittest.TestCase):
boto_config.BotoConfig()
mock_watcher_instance.GetMetadata.assert_called_once_with(
- metadata_key='project/numeric-project-id', recursive=False)
+ metadata_key='project/project-id', recursive=False)
expected_calls = [
mock.call('GSUtil', 'default_project_id', self.project_id),
]
@@ -85,7 +85,7 @@ class BotoConfigTest(unittest.TestCase):
boto_config.BotoConfig()
mock_watcher_instance.GetMetadata.assert_called_once_with(
- metadata_key='project/numeric-project-id', recursive=False)
+ metadata_key='project/project-id', recursive=False)
mock_config.SetOption.assert_not_called()