Skip to content

Commit 25b1cd4

Browse files
authored
Get Project Metadata (#521)
* Add script entrypoint * Bump version number * Update poetry lock file * Get Project Metadata (Compute) * Move to main Compute class * Fix azure test to match version * Mypy fixes
1 parent 649dd2d commit 25b1cd4

7 files changed

Lines changed: 707 additions & 580 deletions

File tree

libcloudforensics/providers/azure/internal/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def ExecuteRequest(
244244
request = getattr(client, func)
245245
response = request(**kwargs)
246246
responses.append(response)
247-
next_link = response.next_link if hasattr(response, 'next_link') else None
247+
next_link = response.next_link if hasattr(response, 'next_link') else ''
248248
if not next_link:
249249
return responses
250250

libcloudforensics/providers/gcp/internal/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def CreateService(
172172
"""
173173

174174
try:
175-
credentials, _ = default()
175+
credentials, _ = default() # type: ignore [no-untyped-call]
176176
except DefaultCredentialsError as exception:
177177
raise errors.CredentialsConfigurationError(
178178
'Could not get application default credentials. Have you run $ gcloud '

libcloudforensics/providers/gcp/internal/compute.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ def RegionDisks(
191191
self._region_disks = self.ListRegionDisks()
192192
return self._region_disks
193193

194+
def GetProjectMetadata(self) -> Dict[str, Any]:
195+
"""Get API operation object for the project level metadata.
196+
197+
Returns:
198+
Dict: An API operation object for the Google Compute Engine
199+
project-level metadata.
200+
https://cloud.google.com/compute/docs/reference/rest/v1/projects/get#response-body
201+
"""
202+
gce_projects_client = self.GceApi().projects() # pylint: disable=no-member
203+
request = gce_projects_client.get(project=self.project_id)
204+
response = request.execute() # type: Dict[str, Any]
205+
return response
206+
194207
def ListInstances(self) -> Dict[str, 'GoogleComputeInstance']:
195208
"""List instances in project.
196209

libcloudforensics/providers/gcp/internal/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self,
6666
if project_id:
6767
self.project_id = project_id
6868
else:
69-
_, project_id = default()
69+
_, project_id = default() # type: ignore [no-untyped-call]
7070
if project_id:
7171
self.project_id = project_id
7272
else:

poetry.lock

Lines changed: 688 additions & 574 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/providers/azure/internal/test_storage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class AZStorageTest(unittest.TestCase):
2626
"""Test Azure storage class."""
2727
# pylint: disable=line-too-long
2828

29-
@mock.patch('azure.mgmt.storage.v2023_01_01.operations._storage_accounts_operations.StorageAccountsOperations.list_keys')
30-
@mock.patch('azure.mgmt.storage.v2023_01_01.operations._storage_accounts_operations.StorageAccountsOperations.begin_create')
29+
@mock.patch('azure.mgmt.storage.v2023_05_01.operations._storage_accounts_operations.StorageAccountsOperations.list_keys')
30+
@mock.patch('azure.mgmt.storage.v2023_05_01.operations._storage_accounts_operations.StorageAccountsOperations.begin_create')
3131
@typing.no_type_check
3232
def testCreateStorageAccount(self, mock_create, mock_list_keys):
3333
"""Test that a storage account is created and its information retrieved"""

tools/gcp_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ def AssignProjectID(args: 'argparse.Namespace') -> None:
505505
from the gcloud environment.
506506
"""
507507
if not args.project:
508-
_, project_id = default()
508+
_, project_id = default() # type: ignore [no-untyped-call]
509509
if project_id:
510510
args.project = project_id
511511
else:

0 commit comments

Comments
 (0)