Skip to content

Commit

Permalink
Get Project Metadata (#521)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Fryyyyy authored Dec 4, 2024
1 parent 649dd2d commit 25b1cd4
Show file tree
Hide file tree
Showing 7 changed files with 707 additions and 580 deletions.
2 changes: 1 addition & 1 deletion libcloudforensics/providers/azure/internal/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def ExecuteRequest(
request = getattr(client, func)
response = request(**kwargs)
responses.append(response)
next_link = response.next_link if hasattr(response, 'next_link') else None
next_link = response.next_link if hasattr(response, 'next_link') else ''
if not next_link:
return responses

Expand Down
2 changes: 1 addition & 1 deletion libcloudforensics/providers/gcp/internal/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def CreateService(
"""

try:
credentials, _ = default()
credentials, _ = default() # type: ignore [no-untyped-call]
except DefaultCredentialsError as exception:
raise errors.CredentialsConfigurationError(
'Could not get application default credentials. Have you run $ gcloud '
Expand Down
13 changes: 13 additions & 0 deletions libcloudforensics/providers/gcp/internal/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ def RegionDisks(
self._region_disks = self.ListRegionDisks()
return self._region_disks

def GetProjectMetadata(self) -> Dict[str, Any]:
"""Get API operation object for the project level metadata.
Returns:
Dict: An API operation object for the Google Compute Engine
project-level metadata.
https://cloud.google.com/compute/docs/reference/rest/v1/projects/get#response-body
"""
gce_projects_client = self.GceApi().projects() # pylint: disable=no-member
request = gce_projects_client.get(project=self.project_id)
response = request.execute() # type: Dict[str, Any]
return response

def ListInstances(self) -> Dict[str, 'GoogleComputeInstance']:
"""List instances in project.
Expand Down
2 changes: 1 addition & 1 deletion libcloudforensics/providers/gcp/internal/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self,
if project_id:
self.project_id = project_id
else:
_, project_id = default()
_, project_id = default() # type: ignore [no-untyped-call]
if project_id:
self.project_id = project_id
else:
Expand Down
1,262 changes: 688 additions & 574 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/providers/azure/internal/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class AZStorageTest(unittest.TestCase):
"""Test Azure storage class."""
# pylint: disable=line-too-long

@mock.patch('azure.mgmt.storage.v2023_01_01.operations._storage_accounts_operations.StorageAccountsOperations.list_keys')
@mock.patch('azure.mgmt.storage.v2023_01_01.operations._storage_accounts_operations.StorageAccountsOperations.begin_create')
@mock.patch('azure.mgmt.storage.v2023_05_01.operations._storage_accounts_operations.StorageAccountsOperations.list_keys')
@mock.patch('azure.mgmt.storage.v2023_05_01.operations._storage_accounts_operations.StorageAccountsOperations.begin_create')
@typing.no_type_check
def testCreateStorageAccount(self, mock_create, mock_list_keys):
"""Test that a storage account is created and its information retrieved"""
Expand Down
2 changes: 1 addition & 1 deletion tools/gcp_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ def AssignProjectID(args: 'argparse.Namespace') -> None:
from the gcloud environment.
"""
if not args.project:
_, project_id = default()
_, project_id = default() # type: ignore [no-untyped-call]
if project_id:
args.project = project_id
else:
Expand Down

0 comments on commit 25b1cd4

Please sign in to comment.