Navigation Menu

Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
feat: Release of relationships in v1, Add content type Relationship t…
Browse files Browse the repository at this point in the history
…o support relationship export (#262)

* feat: Release of relationships in v1, Add content type Relationship to support relationship export Committer: lvv@

PiperOrigin-RevId: 391065985

Source-Link: googleapis/googleapis@b9e69f8

Source-Link: googleapis/googleapis-gen@6d0f250

* 🦉 Updates from OwlBot

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] committed Aug 17, 2021
1 parent c79d51d commit 93c92c1
Show file tree
Hide file tree
Showing 7 changed files with 200 additions and 4 deletions.
6 changes: 6 additions & 0 deletions google/cloud/asset/__init__.py
Expand Up @@ -67,6 +67,9 @@
from google.cloud.asset_v1.types.assets import IamPolicyAnalysisResult
from google.cloud.asset_v1.types.assets import IamPolicyAnalysisState
from google.cloud.asset_v1.types.assets import IamPolicySearchResult
from google.cloud.asset_v1.types.assets import RelatedAsset
from google.cloud.asset_v1.types.assets import RelatedAssets
from google.cloud.asset_v1.types.assets import RelationshipAttributes
from google.cloud.asset_v1.types.assets import Resource
from google.cloud.asset_v1.types.assets import ResourceSearchResult
from google.cloud.asset_v1.types.assets import TemporalAsset
Expand Down Expand Up @@ -120,6 +123,9 @@
"IamPolicyAnalysisResult",
"IamPolicyAnalysisState",
"IamPolicySearchResult",
"RelatedAsset",
"RelatedAssets",
"RelationshipAttributes",
"Resource",
"ResourceSearchResult",
"TemporalAsset",
Expand Down
6 changes: 6 additions & 0 deletions google/cloud/asset_v1/__init__.py
Expand Up @@ -61,6 +61,9 @@
from .types.assets import IamPolicyAnalysisResult
from .types.assets import IamPolicyAnalysisState
from .types.assets import IamPolicySearchResult
from .types.assets import RelatedAsset
from .types.assets import RelatedAssets
from .types.assets import RelationshipAttributes
from .types.assets import Resource
from .types.assets import ResourceSearchResult
from .types.assets import TemporalAsset
Expand Down Expand Up @@ -109,6 +112,9 @@
"OutputResult",
"PartitionSpec",
"PubsubDestination",
"RelatedAsset",
"RelatedAssets",
"RelationshipAttributes",
"Resource",
"ResourceSearchResult",
"SearchAllIamPoliciesRequest",
Expand Down
6 changes: 6 additions & 0 deletions google/cloud/asset_v1/types/__init__.py
Expand Up @@ -60,6 +60,9 @@
IamPolicyAnalysisResult,
IamPolicyAnalysisState,
IamPolicySearchResult,
RelatedAsset,
RelatedAssets,
RelationshipAttributes,
Resource,
ResourceSearchResult,
TemporalAsset,
Expand Down Expand Up @@ -112,6 +115,9 @@
"IamPolicyAnalysisResult",
"IamPolicyAnalysisState",
"IamPolicySearchResult",
"RelatedAsset",
"RelatedAssets",
"RelationshipAttributes",
"Resource",
"ResourceSearchResult",
"TemporalAsset",
Expand Down
78 changes: 77 additions & 1 deletion google/cloud/asset_v1/types/asset_service.py
Expand Up @@ -76,6 +76,7 @@ class ContentType(proto.Enum):
ORG_POLICY = 4
ACCESS_POLICY = 5
OS_INVENTORY = 6
RELATIONSHIP = 7


class AnalyzeIamPolicyLongrunningMetadata(proto.Message):
Expand All @@ -84,7 +85,8 @@ class AnalyzeIamPolicyLongrunningMetadata(proto.Message):
Attributes:
create_time (google.protobuf.timestamp_pb2.Timestamp):
The time the operation was created.
Output only. The time the operation was
created.
"""

create_time = proto.Field(proto.MESSAGE, number=1, message=timestamp_pb2.Timestamp,)
Expand Down Expand Up @@ -138,13 +140,31 @@ class ExportAssetsRequest(proto.Message):
output_config (google.cloud.asset_v1.types.OutputConfig):
Required. Output configuration indicating
where the results will be output to.
relationship_types (Sequence[str]):
A list of relationship types to export, for example:
``INSTANCE_TO_INSTANCEGROUP``. This field should only be
specified if content_type=RELATIONSHIP.
- If specified: it snapshots specified relationships. It
returns an error if any of the [relationship_types]
doesn't belong to the supported relationship types of the
[asset_types] or if any of the [asset_types] doesn't
belong to the source types of the [relationship_types].
- Otherwise: it snapshots the supported relationships for
all [asset_types] or returns an error if any of the
[asset_types] has no relationship support. An unspecified
asset types field means all supported asset_types. See
`Introduction to Cloud Asset
Inventory <https://cloud.google.com/asset-inventory/docs/overview>`__
for all supported asset types and relationship types.
"""

parent = proto.Field(proto.STRING, number=1,)
read_time = proto.Field(proto.MESSAGE, number=2, message=timestamp_pb2.Timestamp,)
asset_types = proto.RepeatedField(proto.STRING, number=3,)
content_type = proto.Field(proto.ENUM, number=4, enum="ContentType",)
output_config = proto.Field(proto.MESSAGE, number=5, message="OutputConfig",)
relationship_types = proto.RepeatedField(proto.STRING, number=6,)


class ExportAssetsResponse(proto.Message):
Expand Down Expand Up @@ -228,6 +248,23 @@ class ListAssetsRequest(proto.Message):
``ListAssetsRequest``. It is a continuation of a prior
``ListAssets`` call, and the API should return the next page
of assets.
relationship_types (Sequence[str]):
A list of relationship types to output, for example:
``INSTANCE_TO_INSTANCEGROUP``. This field should only be
specified if content_type=RELATIONSHIP.
- If specified: it snapshots specified relationships. It
returns an error if any of the [relationship_types]
doesn't belong to the supported relationship types of the
[asset_types] or if any of the [asset_types] doesn't
belong to the source types of the [relationship_types].
- Otherwise: it snapshots the supported relationships for
all [asset_types] or returns an error if any of the
[asset_types] has no relationship support. An unspecified
asset types field means all supported asset_types. See
`Introduction to Cloud Asset
Inventory <https://cloud.google.com/asset-inventory/docs/overview>`__
for all supported asset types and relationship types.
"""

parent = proto.Field(proto.STRING, number=1,)
Expand All @@ -236,6 +273,7 @@ class ListAssetsRequest(proto.Message):
content_type = proto.Field(proto.ENUM, number=4, enum="ContentType",)
page_size = proto.Field(proto.INT32, number=5,)
page_token = proto.Field(proto.STRING, number=6,)
relationship_types = proto.RepeatedField(proto.STRING, number=7,)


class ListAssetsResponse(proto.Message):
Expand Down Expand Up @@ -290,6 +328,23 @@ class BatchGetAssetsHistoryRequest(proto.Message):
not set, the snapshot of the assets at end_time will be
returned. The returned results contain all temporal assets
whose time window overlap with read_time_window.
relationship_types (Sequence[str]):
Optional. A list of relationship types to output, for
example: ``INSTANCE_TO_INSTANCEGROUP``. This field should
only be specified if content_type=RELATIONSHIP.
- If specified: it outputs specified relationships' history
on the [asset_names]. It returns an error if any of the
[relationship_types] doesn't belong to the supported
relationship types of the [asset_names] or if any of the
[asset_names]'s types doesn't belong to the source types
of the [relationship_types].
- Otherwise: it outputs the supported relationships'
history on the [asset_names] or returns an error if any
of the [asset_names]'s types has no relationship support.
See `Introduction to Cloud Asset
Inventory <https://cloud.google.com/asset-inventory/docs/overview>`__
for all supported asset types and relationship types.
"""

parent = proto.Field(proto.STRING, number=1,)
Expand All @@ -298,6 +353,7 @@ class BatchGetAssetsHistoryRequest(proto.Message):
read_time_window = proto.Field(
proto.MESSAGE, number=4, message=gca_assets.TimeWindow,
)
relationship_types = proto.RepeatedField(proto.STRING, number=5,)


class BatchGetAssetsHistoryResponse(proto.Message):
Expand Down Expand Up @@ -675,6 +731,25 @@ class Feed(proto.Message):
See our `user
guide <https://cloud.google.com/asset-inventory/docs/monitoring-asset-changes-with-condition>`__
for detailed instructions.
relationship_types (Sequence[str]):
A list of relationship types to output, for example:
``INSTANCE_TO_INSTANCEGROUP``. This field should only be
specified if content_type=RELATIONSHIP.
- If specified: it outputs specified relationship updates
on the [asset_names] or the [asset_types]. It returns an
error if any of the [relationship_types] doesn't belong
to the supported relationship types of the [asset_names]
or [asset_types], or any of the [asset_names] or the
[asset_types] doesn't belong to the source types of the
[relationship_types].
- Otherwise: it outputs the supported relationships of the
types of [asset_names] and [asset_types] or returns an
error if any of the [asset_names] or the [asset_types]
has no replationship support. See `Introduction to Cloud
Asset
Inventory <https://cloud.google.com/asset-inventory/docs/overview>`__
for all supported asset types and relationship types.
"""

name = proto.Field(proto.STRING, number=1,)
Expand All @@ -685,6 +760,7 @@ class Feed(proto.Message):
proto.MESSAGE, number=5, message="FeedOutputConfig",
)
condition = proto.Field(proto.MESSAGE, number=6, message=expr_pb2.Expr,)
relationship_types = proto.RepeatedField(proto.STRING, number=7,)


class SearchAllResourcesRequest(proto.Message):
Expand Down
90 changes: 90 additions & 0 deletions google/cloud/asset_v1/types/assets.py
Expand Up @@ -33,6 +33,9 @@
"TimeWindow",
"Asset",
"Resource",
"RelatedAssets",
"RelationshipAttributes",
"RelatedAsset",
"ResourceSearchResult",
"VersionedResource",
"AttachedResource",
Expand Down Expand Up @@ -157,6 +160,10 @@ class Asset(proto.Message):
`this
topic <https://cloud.google.com/compute/docs/instances/os-inventory-management>`__
for more information.
related_assets (google.cloud.asset_v1.types.RelatedAssets):
The related assets of the asset of one
relationship type. One asset only represents one
type of relationship.
ancestors (Sequence[str]):
The ancestry path of an asset in Google Cloud `resource
hierarchy <https://cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy>`__,
Expand Down Expand Up @@ -199,6 +206,7 @@ class Asset(proto.Message):
message=service_perimeter_pb2.ServicePerimeter,
)
os_inventory = proto.Field(proto.MESSAGE, number=12, message=Inventory,)
related_assets = proto.Field(proto.MESSAGE, number=13, message="RelatedAssets",)
ancestors = proto.RepeatedField(proto.STRING, number=10,)


Expand Down Expand Up @@ -259,6 +267,88 @@ class Resource(proto.Message):
location = proto.Field(proto.STRING, number=8,)


class RelatedAssets(proto.Message):
r"""The detailed related assets with the ``relationship_type``.
Attributes:
relationship_attributes (google.cloud.asset_v1.types.RelationshipAttributes):
The detailed relationship attributes.
assets (Sequence[google.cloud.asset_v1.types.RelatedAsset]):
The peer resources of the relationship.
"""

relationship_attributes = proto.Field(
proto.MESSAGE, number=1, message="RelationshipAttributes",
)
assets = proto.RepeatedField(proto.MESSAGE, number=2, message="RelatedAsset",)


class RelationshipAttributes(proto.Message):
r"""The relationship attributes which include ``type``,
``source_resource_type``, ``target_resource_type`` and ``action``.
Attributes:
type_ (str):
The unique identifier of the relationship type. Example:
``INSTANCE_TO_INSTANCEGROUP``
source_resource_type (str):
The source asset type. Example:
``compute.googleapis.com/Instance``
target_resource_type (str):
The target asset type. Example:
``compute.googleapis.com/Disk``
action (str):
The detail of the relationship, e.g. ``contains``,
``attaches``
"""

type_ = proto.Field(proto.STRING, number=4,)
source_resource_type = proto.Field(proto.STRING, number=1,)
target_resource_type = proto.Field(proto.STRING, number=2,)
action = proto.Field(proto.STRING, number=3,)


class RelatedAsset(proto.Message):
r"""An asset identify in Google Cloud which contains its name, type and
ancestors. An asset can be any resource in the Google Cloud
`resource
hierarchy <https://cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy>`__,
a resource outside the Google Cloud resource hierarchy (such as
Google Kubernetes Engine clusters and objects), or a policy (e.g.
Cloud IAM policy). See `Supported asset
types <https://cloud.google.com/asset-inventory/docs/supported-asset-types>`__
for more information.
Attributes:
asset (str):
The full name of the asset. Example:
``//compute.googleapis.com/projects/my_project_123/zones/zone1/instances/instance1``
See `Resource
names <https://cloud.google.com/apis/design/resource_names#full_resource_name>`__
for more information.
asset_type (str):
The type of the asset. Example:
``compute.googleapis.com/Disk``
See `Supported asset
types <https://cloud.google.com/asset-inventory/docs/supported-asset-types>`__
for more information.
ancestors (Sequence[str]):
The ancestors of an asset in Google Cloud `resource
hierarchy <https://cloud.google.com/resource-manager/docs/cloud-platform-resource-hierarchy>`__,
represented as a list of relative resource names. An
ancestry path starts with the closest ancestor in the
hierarchy and ends at root.
Example:
``["projects/123456789", "folders/5432", "organizations/1234"]``
"""

asset = proto.Field(proto.STRING, number=1,)
asset_type = proto.Field(proto.STRING, number=2,)
ancestors = proto.RepeatedField(proto.STRING, number=3,)


class ResourceSearchResult(proto.Message):
r"""A result of Resource Search, containing information of a
cloud resource.
Expand Down
6 changes: 3 additions & 3 deletions scripts/fixup_asset_v1_keywords.py
Expand Up @@ -42,12 +42,12 @@ class assetCallTransformer(cst.CSTTransformer):
'analyze_iam_policy': ('analysis_query', 'execution_timeout', ),
'analyze_iam_policy_longrunning': ('analysis_query', 'output_config', ),
'analyze_move': ('resource', 'destination_parent', 'view', ),
'batch_get_assets_history': ('parent', 'asset_names', 'content_type', 'read_time_window', ),
'batch_get_assets_history': ('parent', 'asset_names', 'content_type', 'read_time_window', 'relationship_types', ),
'create_feed': ('parent', 'feed_id', 'feed', ),
'delete_feed': ('name', ),
'export_assets': ('parent', 'output_config', 'read_time', 'asset_types', 'content_type', ),
'export_assets': ('parent', 'output_config', 'read_time', 'asset_types', 'content_type', 'relationship_types', ),
'get_feed': ('name', ),
'list_assets': ('parent', 'read_time', 'asset_types', 'content_type', 'page_size', 'page_token', ),
'list_assets': ('parent', 'read_time', 'asset_types', 'content_type', 'page_size', 'page_token', 'relationship_types', ),
'list_feeds': ('parent', ),
'search_all_iam_policies': ('scope', 'query', 'page_size', 'page_token', 'asset_types', 'order_by', ),
'search_all_resources': ('scope', 'query', 'asset_types', 'page_size', 'page_token', 'order_by', 'read_mask', ),
Expand Down

0 comments on commit 93c92c1

Please sign in to comment.