From 6bf2ff4479e007698f11c40958abf0759fcf6f48 Mon Sep 17 00:00:00 2001 From: Matt Houglum Date: Fri, 9 Aug 2019 13:45:46 -0700 Subject: 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. --- .../google_compute_engine/boto/boto_config.py | 13 +++++++------ .../google_compute_engine/boto/tests/boto_config_test.py | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'packages') 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() -- cgit v1.2.1