Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Project Metadata #521

Merged
merged 8 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading