Skip to content

Commit

Permalink
feat: Change metadata field for the AnalyzeIamPolicyLongrunning (#245)
Browse files Browse the repository at this point in the history
*the metadata field change for AnalyzeIamPolicyLongrunning is BACKWARD INCOMPATIBLE. Adding this change expand our ability to return richer metadata information for the longrunning operation. Due to the small usage of this API, we've contacted all the customers to make sure they are not using the metadata field and hence won't be broken by this change.

Committer: @aaronlichen-hp
PiperOrigin-RevId: 386530026

Source-Link: googleapis/googleapis@746461e

Source-Link: googleapis/googleapis-gen@c2c1745

feat: Add AnalyzeMove API
feat: Add read_mask field for SearchAllResourcesRequest 
feat: Add VersionedResource field for ResourceSearchResult
feat: Add AttachedResource field for ResourceSearchResult
  • Loading branch information
gcf-owl-bot[bot] authored Jul 24, 2021
1 parent 4b5c02d commit af6cdb2
Show file tree
Hide file tree
Showing 13 changed files with 647 additions and 22 deletions.
18 changes: 18 additions & 0 deletions packages/google-cloud-asset/google/cloud/asset/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
AssetServiceAsyncClient,
)

from google.cloud.asset_v1.types.asset_service import (
AnalyzeIamPolicyLongrunningMetadata,
)
from google.cloud.asset_v1.types.asset_service import AnalyzeIamPolicyLongrunningRequest
from google.cloud.asset_v1.types.asset_service import (
AnalyzeIamPolicyLongrunningResponse,
)
from google.cloud.asset_v1.types.asset_service import AnalyzeIamPolicyRequest
from google.cloud.asset_v1.types.asset_service import AnalyzeIamPolicyResponse
from google.cloud.asset_v1.types.asset_service import AnalyzeMoveRequest
from google.cloud.asset_v1.types.asset_service import AnalyzeMoveResponse
from google.cloud.asset_v1.types.asset_service import BatchGetAssetsHistoryRequest
from google.cloud.asset_v1.types.asset_service import BatchGetAssetsHistoryResponse
from google.cloud.asset_v1.types.asset_service import BigQueryDestination
Expand All @@ -43,6 +48,9 @@
from google.cloud.asset_v1.types.asset_service import ListAssetsResponse
from google.cloud.asset_v1.types.asset_service import ListFeedsRequest
from google.cloud.asset_v1.types.asset_service import ListFeedsResponse
from google.cloud.asset_v1.types.asset_service import MoveAnalysis
from google.cloud.asset_v1.types.asset_service import MoveAnalysisResult
from google.cloud.asset_v1.types.asset_service import MoveImpact
from google.cloud.asset_v1.types.asset_service import OutputConfig
from google.cloud.asset_v1.types.asset_service import OutputResult
from google.cloud.asset_v1.types.asset_service import PartitionSpec
Expand All @@ -54,6 +62,7 @@
from google.cloud.asset_v1.types.asset_service import UpdateFeedRequest
from google.cloud.asset_v1.types.asset_service import ContentType
from google.cloud.asset_v1.types.assets import Asset
from google.cloud.asset_v1.types.assets import AttachedResource
from google.cloud.asset_v1.types.assets import ConditionEvaluation
from google.cloud.asset_v1.types.assets import IamPolicyAnalysisResult
from google.cloud.asset_v1.types.assets import IamPolicyAnalysisState
Expand All @@ -62,14 +71,18 @@
from google.cloud.asset_v1.types.assets import ResourceSearchResult
from google.cloud.asset_v1.types.assets import TemporalAsset
from google.cloud.asset_v1.types.assets import TimeWindow
from google.cloud.asset_v1.types.assets import VersionedResource

__all__ = (
"AssetServiceClient",
"AssetServiceAsyncClient",
"AnalyzeIamPolicyLongrunningMetadata",
"AnalyzeIamPolicyLongrunningRequest",
"AnalyzeIamPolicyLongrunningResponse",
"AnalyzeIamPolicyRequest",
"AnalyzeIamPolicyResponse",
"AnalyzeMoveRequest",
"AnalyzeMoveResponse",
"BatchGetAssetsHistoryRequest",
"BatchGetAssetsHistoryResponse",
"BigQueryDestination",
Expand All @@ -88,6 +101,9 @@
"ListAssetsResponse",
"ListFeedsRequest",
"ListFeedsResponse",
"MoveAnalysis",
"MoveAnalysisResult",
"MoveImpact",
"OutputConfig",
"OutputResult",
"PartitionSpec",
Expand All @@ -99,6 +115,7 @@
"UpdateFeedRequest",
"ContentType",
"Asset",
"AttachedResource",
"ConditionEvaluation",
"IamPolicyAnalysisResult",
"IamPolicyAnalysisState",
Expand All @@ -107,4 +124,5 @@
"ResourceSearchResult",
"TemporalAsset",
"TimeWindow",
"VersionedResource",
)
16 changes: 16 additions & 0 deletions packages/google-cloud-asset/google/cloud/asset_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
from .services.asset_service import AssetServiceClient
from .services.asset_service import AssetServiceAsyncClient

from .types.asset_service import AnalyzeIamPolicyLongrunningMetadata
from .types.asset_service import AnalyzeIamPolicyLongrunningRequest
from .types.asset_service import AnalyzeIamPolicyLongrunningResponse
from .types.asset_service import AnalyzeIamPolicyRequest
from .types.asset_service import AnalyzeIamPolicyResponse
from .types.asset_service import AnalyzeMoveRequest
from .types.asset_service import AnalyzeMoveResponse
from .types.asset_service import BatchGetAssetsHistoryRequest
from .types.asset_service import BatchGetAssetsHistoryResponse
from .types.asset_service import BigQueryDestination
Expand All @@ -39,6 +42,9 @@
from .types.asset_service import ListAssetsResponse
from .types.asset_service import ListFeedsRequest
from .types.asset_service import ListFeedsResponse
from .types.asset_service import MoveAnalysis
from .types.asset_service import MoveAnalysisResult
from .types.asset_service import MoveImpact
from .types.asset_service import OutputConfig
from .types.asset_service import OutputResult
from .types.asset_service import PartitionSpec
Expand All @@ -50,6 +56,7 @@
from .types.asset_service import UpdateFeedRequest
from .types.asset_service import ContentType
from .types.assets import Asset
from .types.assets import AttachedResource
from .types.assets import ConditionEvaluation
from .types.assets import IamPolicyAnalysisResult
from .types.assets import IamPolicyAnalysisState
Expand All @@ -58,15 +65,20 @@
from .types.assets import ResourceSearchResult
from .types.assets import TemporalAsset
from .types.assets import TimeWindow
from .types.assets import VersionedResource

__all__ = (
"AssetServiceAsyncClient",
"AnalyzeIamPolicyLongrunningMetadata",
"AnalyzeIamPolicyLongrunningRequest",
"AnalyzeIamPolicyLongrunningResponse",
"AnalyzeIamPolicyRequest",
"AnalyzeIamPolicyResponse",
"AnalyzeMoveRequest",
"AnalyzeMoveResponse",
"Asset",
"AssetServiceClient",
"AttachedResource",
"BatchGetAssetsHistoryRequest",
"BatchGetAssetsHistoryResponse",
"BigQueryDestination",
Expand All @@ -90,6 +102,9 @@
"ListAssetsResponse",
"ListFeedsRequest",
"ListFeedsResponse",
"MoveAnalysis",
"MoveAnalysisResult",
"MoveImpact",
"OutputConfig",
"OutputResult",
"PartitionSpec",
Expand All @@ -103,4 +118,5 @@
"TemporalAsset",
"TimeWindow",
"UpdateFeedRequest",
"VersionedResource",
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"analyze_iam_policy_longrunning"
]
},
"AnalyzeMove": {
"methods": [
"analyze_move"
]
},
"BatchGetAssetsHistory": {
"methods": [
"batch_get_assets_history"
Expand Down Expand Up @@ -85,6 +90,11 @@
"analyze_iam_policy_longrunning"
]
},
"AnalyzeMove": {
"methods": [
"analyze_move"
]
},
"BatchGetAssetsHistory": {
"methods": [
"batch_get_assets_history"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,8 +864,8 @@ async def search_all_resources(
the word "key".
- ``state:ACTIVE`` to find Cloud resources whose state
contains "ACTIVE" as a word.
- ``NOT state:ACTIVE`` to find {{gcp_name}} resources
whose state doesn't contain "ACTIVE" as a word.
- ``NOT state:ACTIVE`` to find Cloud resources whose
state doesn't contain "ACTIVE" as a word.
- ``createTime<1609459200`` to find Cloud resources
that were created before "2021-01-01 00:00:00 UTC".
1609459200 is the epoch timestamp of "2021-01-01
Expand Down Expand Up @@ -1221,8 +1221,8 @@ async def analyze_iam_policy_longrunning(
[google.longrunning.Operation][google.longrunning.Operation],
which allows you to track the operation status. We recommend
intervals of at least 2 seconds with exponential backoff retry
to poll the operation result. The metadata contains the request
to help callers to map responses to requests.
to poll the operation result. The metadata contains the metadata
for the long-running operation.
Args:
request (:class:`google.cloud.asset_v1.types.AnalyzeIamPolicyLongrunningRequest`):
Expand Down Expand Up @@ -1271,12 +1271,67 @@ async def analyze_iam_policy_longrunning(
response,
self._client._transport.operations_client,
asset_service.AnalyzeIamPolicyLongrunningResponse,
metadata_type=asset_service.AnalyzeIamPolicyLongrunningRequest,
metadata_type=asset_service.AnalyzeIamPolicyLongrunningMetadata,
)

# Done; return the response.
return response

async def analyze_move(
self,
request: asset_service.AnalyzeMoveRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.AnalyzeMoveResponse:
r"""Analyze moving a resource to a specified destination
without kicking off the actual move. The analysis is
best effort depending on the user's permissions of
viewing different hierarchical policies and
configurations. The policies and configuration are
subject to change before the actual resource migration
takes place.
Args:
request (:class:`google.cloud.asset_v1.types.AnalyzeMoveRequest`):
The request object. The request message for performing
resource move analysis.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.asset_v1.types.AnalyzeMoveResponse:
The response message for resource
move analysis.
"""
# Create or coerce a protobuf request object.
request = asset_service.AnalyzeMoveRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = gapic_v1.method_async.wrap_method(
self._client._transport.analyze_move,
default_timeout=None,
client_info=DEFAULT_CLIENT_INFO,
)

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
)

# Send the request.
response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# Done; return the response.
return response


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ def search_all_resources(
the word "key".
- ``state:ACTIVE`` to find Cloud resources whose state
contains "ACTIVE" as a word.
- ``NOT state:ACTIVE`` to find {{gcp_name}} resources
whose state doesn't contain "ACTIVE" as a word.
- ``NOT state:ACTIVE`` to find Cloud resources whose
state doesn't contain "ACTIVE" as a word.
- ``createTime<1609459200`` to find Cloud resources
that were created before "2021-01-01 00:00:00 UTC".
1609459200 is the epoch timestamp of "2021-01-01
Expand Down Expand Up @@ -1336,8 +1336,8 @@ def analyze_iam_policy_longrunning(
[google.longrunning.Operation][google.longrunning.Operation],
which allows you to track the operation status. We recommend
intervals of at least 2 seconds with exponential backoff retry
to poll the operation result. The metadata contains the request
to help callers to map responses to requests.
to poll the operation result. The metadata contains the metadata
for the long-running operation.
Args:
request (google.cloud.asset_v1.types.AnalyzeIamPolicyLongrunningRequest):
Expand Down Expand Up @@ -1389,12 +1389,68 @@ def analyze_iam_policy_longrunning(
response,
self._transport.operations_client,
asset_service.AnalyzeIamPolicyLongrunningResponse,
metadata_type=asset_service.AnalyzeIamPolicyLongrunningRequest,
metadata_type=asset_service.AnalyzeIamPolicyLongrunningMetadata,
)

# Done; return the response.
return response

def analyze_move(
self,
request: asset_service.AnalyzeMoveRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.AnalyzeMoveResponse:
r"""Analyze moving a resource to a specified destination
without kicking off the actual move. The analysis is
best effort depending on the user's permissions of
viewing different hierarchical policies and
configurations. The policies and configuration are
subject to change before the actual resource migration
takes place.
Args:
request (google.cloud.asset_v1.types.AnalyzeMoveRequest):
The request object. The request message for performing
resource move analysis.
retry (google.api_core.retry.Retry): Designation of what errors, if any,
should be retried.
timeout (float): The timeout for this request.
metadata (Sequence[Tuple[str, str]]): Strings which should be
sent along with the request as metadata.
Returns:
google.cloud.asset_v1.types.AnalyzeMoveResponse:
The response message for resource
move analysis.
"""
# Create or coerce a protobuf request object.
# Minor optimization to avoid making a copy if the user passes
# in a asset_service.AnalyzeMoveRequest.
# There's no risk of modifying the input as we've already verified
# there are no flattened fields.
if not isinstance(request, asset_service.AnalyzeMoveRequest):
request = asset_service.AnalyzeMoveRequest(request)

# Wrap the RPC method; this adds retry and timeout information,
# and friendly error handling.
rpc = self._transport._wrapped_methods[self._transport.analyze_move]

# Certain fields should be provided within the metadata header;
# add these here.
metadata = tuple(metadata) + (
gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)),
)

# Send the request.
response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,)

# Done; return the response.
return response


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.analyze_move: gapic_v1.method.wrap_method(
self.analyze_move, default_timeout=None, client_info=client_info,
),
}

@property
Expand Down Expand Up @@ -418,5 +421,17 @@ def analyze_iam_policy_longrunning(
]:
raise NotImplementedError()

@property
def analyze_move(
self,
) -> Callable[
[asset_service.AnalyzeMoveRequest],
Union[
asset_service.AnalyzeMoveResponse,
Awaitable[asset_service.AnalyzeMoveResponse],
],
]:
raise NotImplementedError()


__all__ = ("AssetServiceTransport",)
Loading

0 comments on commit af6cdb2

Please sign in to comment.