Skip to content

Commit

Permalink
refactored parse function to paginated_query
Browse files Browse the repository at this point in the history
  • Loading branch information
mk-armah committed Aug 26, 2024
1 parent aa85d81 commit fa43ee0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions integrations/gcp/gcp_core/search/resource_searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ async def search_all_resources_in_project(
project: dict[str, Any], asset_type: str, asset_name: str | None = None
) -> ASYNC_GENERATOR_RESYNC_TYPE:

def parse_asset_response(response: Any) -> list[AssetData]:
assets = typing.cast(list[AssetData], parse_protobuf_messages(response.results))
latest_resources = [
{
**parse_latest_resource_from_asset(asset),
EXTRA_PROJECT_FIELD: project,
}
for asset in assets
]
return latest_resources

async with semaphore:
"""
List of supported assets: https://cloud.google.com/asset-inventory/docs/supported-asset-types
Expand Down Expand Up @@ -70,20 +81,10 @@ async def search_all_resources_in_project(
async_assets_client,
"search_all_resources",
search_all_resources_request,
lambda response: typing.cast(
list[AssetData], parse_protobuf_messages(response.results)
),
parse_asset_response,
rate_limiter=rate_limiter,
):
asset_data: list[AssetData] = typing.cast(list[AssetData], assets)
latest_resources = [
{
**parse_latest_resource_from_asset(asset),
EXTRA_PROJECT_FIELD: project,
}
for asset in asset_data
]
yield latest_resources
yield assets

except PermissionDenied:
logger.error(
Expand Down
2 changes: 1 addition & 1 deletion integrations/gcp/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "gcp"
version = "0.1.45"
version = "0.1.46"
description = "A GCP ocean integration"
authors = ["Matan Geva <[email protected]>"]

Expand Down

0 comments on commit fa43ee0

Please sign in to comment.