Skip to content

Commit f79346e

Browse files
feat: add search_all_resources and search_all_iam_policies (via synth) (#32)
* changes without context autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters. * fix: consolidate logging setup (#541) * fix: consolidate logging setup When switching autosynth to use synthtool's git module, we transitively load synthtool's logger setup which adds a log handler globally. This causes logs to be emitted twice (with 2 different styles). This consolidates the logging setup into a single helper and now both autosynth's and synthtool's logger instance use the same configuration (with different logger names). * fix: add the level name when the log isn't colorize Source-Author: Jeff Ching <chingor@google.com> Source-Date: Tue May 12 15:53:43 2020 -0700 Source-Repo: googleapis/synthtool Source-Sha: c585ac3b5eff5cd2097a5315ffd9cf4823cc1ed2 Source-Link: googleapis/synthtool@c585ac3 * cloudasset: add SearchAllResources and SearchAllIamPolicies RPCs PiperOrigin-RevId: 311601348 Source-Author: Google APIs <noreply@google.com> Source-Date: Thu May 14 14:03:19 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 2433bd50656264a2ef9f684bf646fb4d250d39ff Source-Link: googleapis/googleapis@2433bd5 * feat!: additional client library annotations feat: reload information in the Document resource BREAKING CHANGE: additional long-running operation annotations BREAKING CHANGE: some existing request fields are now explicitly required BREAKING CHANGE: the order of the Session resource patterns has changed PiperOrigin-RevId: 312345206 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue May 19 13:46:01 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 7a8875d4bcf51993f6f7aa181066cc5ec95539d5 Source-Link: googleapis/googleapis@7a8875d * Upgrade protoc-docs-plugin version to 0.7.0 to fix unstable docstrings. PiperOrigin-RevId: 312689208 Source-Author: Google APIs <noreply@google.com> Source-Date: Thu May 21 10:00:47 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: dec3204175104cef49bf21d685d5517caaf0058f Source-Link: googleapis/googleapis@dec3204 * docs: Properly format literal strings. PiperOrigin-RevId: 313202929 Source-Author: Google APIs <noreply@google.com> Source-Date: Tue May 26 09:12:28 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: f563b1dffee42be2f61c326c39af4974c1984278 Source-Link: googleapis/googleapis@f563b1d * docs: fix wrapping Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com> Co-authored-by: Bu Sun Kim <busunkim@google.com>
1 parent d2ef171 commit f79346e

File tree

16 files changed

+1843
-250
lines changed

16 files changed

+1843
-250
lines changed

packages/google-cloud-asset/google/cloud/asset_v1/gapic/asset_service_client.py

Lines changed: 304 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
"""Accesses the google.cloud.asset.v1 AssetService API."""
1818

19+
import functools
1920
import pkg_resources
2021
import warnings
2122

@@ -28,6 +29,7 @@
2829
import google.api_core.grpc_helpers
2930
import google.api_core.operation
3031
import google.api_core.operations_v1
32+
import google.api_core.page_iterator
3133
import google.api_core.path_template
3234
import grpc
3335

@@ -830,3 +832,305 @@ def update_feed(
830832
return self._inner_api_calls["update_feed"](
831833
request, retry=retry, timeout=timeout, metadata=metadata
832834
)
835+
836+
def search_all_resources(
837+
self,
838+
scope,
839+
query=None,
840+
asset_types=None,
841+
page_size=None,
842+
order_by=None,
843+
retry=google.api_core.gapic_v1.method.DEFAULT,
844+
timeout=google.api_core.gapic_v1.method.DEFAULT,
845+
metadata=None,
846+
):
847+
"""
848+
Searches all the resources within the given accessible scope (e.g., a
849+
project, a folder or an organization). Callers should have
850+
cloud.assets.SearchAllResources permission upon the requested scope,
851+
otherwise the request will be rejected.
852+
853+
Example:
854+
>>> from google.cloud import asset_v1
855+
>>>
856+
>>> client = asset_v1.AssetServiceClient()
857+
>>>
858+
>>> # TODO: Initialize `scope`:
859+
>>> scope = ''
860+
>>>
861+
>>> # Iterate over all results
862+
>>> for element in client.search_all_resources(scope):
863+
... # process element
864+
... pass
865+
>>>
866+
>>>
867+
>>> # Alternatively:
868+
>>>
869+
>>> # Iterate over results one page at a time
870+
>>> for page in client.search_all_resources(scope).pages:
871+
... for element in page:
872+
... # process element
873+
... pass
874+
875+
Args:
876+
scope (str): Required. A scope can be a project, a folder or an organization. The
877+
search is limited to the resources within the ``scope``.
878+
879+
The allowed values are:
880+
881+
- projects/{PROJECT_ID}
882+
- projects/{PROJECT_NUMBER}
883+
- folders/{FOLDER_NUMBER}
884+
- organizations/{ORGANIZATION_NUMBER}
885+
query (str): Optional. The query statement. An empty query can be specified to
886+
search all the resources of certain ``asset_types`` within the given
887+
``scope``.
888+
889+
Examples:
890+
891+
- ``name : "Important"`` to find Cloud resources whose name contains
892+
"Important" as a word.
893+
- ``displayName : "Impor*"`` to find Cloud resources whose display name
894+
contains "Impor" as a word prefix.
895+
- ``description : "*por*"`` to find Cloud resources whose description
896+
contains "por" as a substring.
897+
- ``location : "us-west*"`` to find Cloud resources whose location is
898+
prefixed with "us-west".
899+
- ``labels : "prod"`` to find Cloud resources whose labels contain
900+
"prod" as a key or value.
901+
- ``labels.env : "prod"`` to find Cloud resources which have a label
902+
"env" and its value is "prod".
903+
- ``labels.env : *`` to find Cloud resources which have a label "env".
904+
- ``"Important"`` to find Cloud resources which contain "Important" as
905+
a word in any of the searchable fields.
906+
- ``"Impor*"`` to find Cloud resources which contain "Impor" as a word
907+
prefix in any of the searchable fields.
908+
- ``"*por*"`` to find Cloud resources which contain "por" as a
909+
substring in any of the searchable fields.
910+
- ``("Important" AND location : ("us-west1" OR "global"))`` to find
911+
Cloud resources which contain "Important" as a word in any of the
912+
searchable fields and are also located in the "us-west1" region or
913+
the "global" location.
914+
915+
See `how to construct a
916+
query <https://cloud.google.com/asset-inventory/docs/searching-resources#how_to_construct_a_query>`__
917+
for more details.
918+
asset_types (list[str]): Optional. A list of asset types that this request searches for. If
919+
empty, it will search all the `searchable asset
920+
types <https://cloud.google.com/asset-inventory/docs/supported-asset-types#searchable_asset_types>`__.
921+
page_size (int): The maximum number of resources contained in the
922+
underlying API response. If page streaming is performed per-
923+
resource, this parameter does not affect the return value. If page
924+
streaming is performed per-page, this determines the maximum number
925+
of resources in a page.
926+
order_by (str): Optional. A comma separated list of fields specifying the sorting
927+
order of the results. The default order is ascending. Add " DESC" after
928+
the field name to indicate descending order. Redundant space characters
929+
are ignored. Example: "location DESC, name". See `supported resource
930+
metadata
931+
fields <https://cloud.google.com/asset-inventory/docs/searching-resources#query_on_resource_metadata_fields>`__
932+
for more details.
933+
retry (Optional[google.api_core.retry.Retry]): A retry object used
934+
to retry requests. If ``None`` is specified, requests will
935+
be retried using a default configuration.
936+
timeout (Optional[float]): The amount of time, in seconds, to wait
937+
for the request to complete. Note that if ``retry`` is
938+
specified, the timeout applies to each individual attempt.
939+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
940+
that is provided to the method.
941+
942+
Returns:
943+
A :class:`~google.api_core.page_iterator.PageIterator` instance.
944+
An iterable of :class:`~google.cloud.asset_v1.types.ResourceSearchResult` instances.
945+
You can also iterate over the pages of the response
946+
using its `pages` property.
947+
948+
Raises:
949+
google.api_core.exceptions.GoogleAPICallError: If the request
950+
failed for any reason.
951+
google.api_core.exceptions.RetryError: If the request failed due
952+
to a retryable error and retry attempts failed.
953+
ValueError: If the parameters are invalid.
954+
"""
955+
# Wrap the transport method to add retry and timeout logic.
956+
if "search_all_resources" not in self._inner_api_calls:
957+
self._inner_api_calls[
958+
"search_all_resources"
959+
] = google.api_core.gapic_v1.method.wrap_method(
960+
self.transport.search_all_resources,
961+
default_retry=self._method_configs["SearchAllResources"].retry,
962+
default_timeout=self._method_configs["SearchAllResources"].timeout,
963+
client_info=self._client_info,
964+
)
965+
966+
request = asset_service_pb2.SearchAllResourcesRequest(
967+
scope=scope,
968+
query=query,
969+
asset_types=asset_types,
970+
page_size=page_size,
971+
order_by=order_by,
972+
)
973+
if metadata is None:
974+
metadata = []
975+
metadata = list(metadata)
976+
try:
977+
routing_header = [("scope", scope)]
978+
except AttributeError:
979+
pass
980+
else:
981+
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
982+
routing_header
983+
)
984+
metadata.append(routing_metadata)
985+
986+
iterator = google.api_core.page_iterator.GRPCIterator(
987+
client=None,
988+
method=functools.partial(
989+
self._inner_api_calls["search_all_resources"],
990+
retry=retry,
991+
timeout=timeout,
992+
metadata=metadata,
993+
),
994+
request=request,
995+
items_field="results",
996+
request_token_field="page_token",
997+
response_token_field="next_page_token",
998+
)
999+
return iterator
1000+
1001+
def search_all_iam_policies(
1002+
self,
1003+
scope,
1004+
query=None,
1005+
page_size=None,
1006+
retry=google.api_core.gapic_v1.method.DEFAULT,
1007+
timeout=google.api_core.gapic_v1.method.DEFAULT,
1008+
metadata=None,
1009+
):
1010+
"""
1011+
Searches all the IAM policies within the given accessible scope (e.g., a
1012+
project, a folder or an organization). Callers should have
1013+
cloud.assets.SearchAllIamPolicies permission upon the requested scope,
1014+
otherwise the request will be rejected.
1015+
1016+
Example:
1017+
>>> from google.cloud import asset_v1
1018+
>>>
1019+
>>> client = asset_v1.AssetServiceClient()
1020+
>>>
1021+
>>> # TODO: Initialize `scope`:
1022+
>>> scope = ''
1023+
>>>
1024+
>>> # Iterate over all results
1025+
>>> for element in client.search_all_iam_policies(scope):
1026+
... # process element
1027+
... pass
1028+
>>>
1029+
>>>
1030+
>>> # Alternatively:
1031+
>>>
1032+
>>> # Iterate over results one page at a time
1033+
>>> for page in client.search_all_iam_policies(scope).pages:
1034+
... for element in page:
1035+
... # process element
1036+
... pass
1037+
1038+
Args:
1039+
scope (str): Required. A scope can be a project, a folder or an organization. The
1040+
search is limited to the IAM policies within the ``scope``.
1041+
1042+
The allowed values are:
1043+
1044+
- projects/{PROJECT_ID}
1045+
- projects/{PROJECT_NUMBER}
1046+
- folders/{FOLDER_NUMBER}
1047+
- organizations/{ORGANIZATION_NUMBER}
1048+
query (str): Optional. The query statement. An empty query can be specified to
1049+
search all the IAM policies within the given ``scope``.
1050+
1051+
Examples:
1052+
1053+
- ``policy : "amy@gmail.com"`` to find Cloud IAM policy bindings that
1054+
specify user "amy@gmail.com".
1055+
- ``policy : "roles/compute.admin"`` to find Cloud IAM policy bindings
1056+
that specify the Compute Admin role.
1057+
- ``policy.role.permissions : "storage.buckets.update"`` to find Cloud
1058+
IAM policy bindings that specify a role containing
1059+
"storage.buckets.update" permission.
1060+
- ``resource : "organizations/123"`` to find Cloud IAM policy bindings
1061+
that are set on "organizations/123".
1062+
- ``(resource : ("organizations/123" OR "folders/1234") AND policy : "amy")``
1063+
to find Cloud IAM policy bindings that are set on "organizations/123"
1064+
or "folders/1234", and also specify user "amy".
1065+
1066+
See `how to construct a
1067+
query <https://cloud.google.com/asset-inventory/docs/searching-iam-policies#how_to_construct_a_query>`__
1068+
for more details.
1069+
page_size (int): The maximum number of resources contained in the
1070+
underlying API response. If page streaming is performed per-
1071+
resource, this parameter does not affect the return value. If page
1072+
streaming is performed per-page, this determines the maximum number
1073+
of resources in a page.
1074+
retry (Optional[google.api_core.retry.Retry]): A retry object used
1075+
to retry requests. If ``None`` is specified, requests will
1076+
be retried using a default configuration.
1077+
timeout (Optional[float]): The amount of time, in seconds, to wait
1078+
for the request to complete. Note that if ``retry`` is
1079+
specified, the timeout applies to each individual attempt.
1080+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
1081+
that is provided to the method.
1082+
1083+
Returns:
1084+
A :class:`~google.api_core.page_iterator.PageIterator` instance.
1085+
An iterable of :class:`~google.cloud.asset_v1.types.IamPolicySearchResult` instances.
1086+
You can also iterate over the pages of the response
1087+
using its `pages` property.
1088+
1089+
Raises:
1090+
google.api_core.exceptions.GoogleAPICallError: If the request
1091+
failed for any reason.
1092+
google.api_core.exceptions.RetryError: If the request failed due
1093+
to a retryable error and retry attempts failed.
1094+
ValueError: If the parameters are invalid.
1095+
"""
1096+
# Wrap the transport method to add retry and timeout logic.
1097+
if "search_all_iam_policies" not in self._inner_api_calls:
1098+
self._inner_api_calls[
1099+
"search_all_iam_policies"
1100+
] = google.api_core.gapic_v1.method.wrap_method(
1101+
self.transport.search_all_iam_policies,
1102+
default_retry=self._method_configs["SearchAllIamPolicies"].retry,
1103+
default_timeout=self._method_configs["SearchAllIamPolicies"].timeout,
1104+
client_info=self._client_info,
1105+
)
1106+
1107+
request = asset_service_pb2.SearchAllIamPoliciesRequest(
1108+
scope=scope, query=query, page_size=page_size
1109+
)
1110+
if metadata is None:
1111+
metadata = []
1112+
metadata = list(metadata)
1113+
try:
1114+
routing_header = [("scope", scope)]
1115+
except AttributeError:
1116+
pass
1117+
else:
1118+
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
1119+
routing_header
1120+
)
1121+
metadata.append(routing_metadata)
1122+
1123+
iterator = google.api_core.page_iterator.GRPCIterator(
1124+
client=None,
1125+
method=functools.partial(
1126+
self._inner_api_calls["search_all_iam_policies"],
1127+
retry=retry,
1128+
timeout=timeout,
1129+
metadata=metadata,
1130+
),
1131+
request=request,
1132+
items_field="results",
1133+
request_token_field="page_token",
1134+
response_token_field="next_page_token",
1135+
)
1136+
return iterator

packages/google-cloud-asset/google/cloud/asset_v1/gapic/asset_service_client_config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@
5252
"retry_codes_name": "non_idempotent",
5353
"retry_params_name": "default",
5454
},
55+
"SearchAllResources": {
56+
"timeout_millis": 60000,
57+
"retry_codes_name": "idempotent",
58+
"retry_params_name": "default",
59+
},
60+
"SearchAllIamPolicies": {
61+
"timeout_millis": 60000,
62+
"retry_codes_name": "idempotent",
63+
"retry_params_name": "default",
64+
},
5565
},
5666
}
5767
}

packages/google-cloud-asset/google/cloud/asset_v1/gapic/transports/asset_service_grpc_transport.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,35 @@ def update_feed(self):
214214
deserialized response object.
215215
"""
216216
return self._stubs["asset_service_stub"].UpdateFeed
217+
218+
@property
219+
def search_all_resources(self):
220+
"""Return the gRPC stub for :meth:`AssetServiceClient.search_all_resources`.
221+
222+
Searches all the resources within the given accessible scope (e.g., a
223+
project, a folder or an organization). Callers should have
224+
cloud.assets.SearchAllResources permission upon the requested scope,
225+
otherwise the request will be rejected.
226+
227+
Returns:
228+
Callable: A callable which accepts the appropriate
229+
deserialized request object and returns a
230+
deserialized response object.
231+
"""
232+
return self._stubs["asset_service_stub"].SearchAllResources
233+
234+
@property
235+
def search_all_iam_policies(self):
236+
"""Return the gRPC stub for :meth:`AssetServiceClient.search_all_iam_policies`.
237+
238+
Searches all the IAM policies within the given accessible scope (e.g., a
239+
project, a folder or an organization). Callers should have
240+
cloud.assets.SearchAllIamPolicies permission upon the requested scope,
241+
otherwise the request will be rejected.
242+
243+
Returns:
244+
Callable: A callable which accepts the appropriate
245+
deserialized request object and returns a
246+
deserialized response object.
247+
"""
248+
return self._stubs["asset_service_stub"].SearchAllIamPolicies

0 commit comments

Comments
 (0)