google_cloud_asset_v1/
client.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Cloud Asset API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_asset_v1::client::AssetService;
25/// let client = AssetService::builder().build().await?;
26/// // use `client` to make requests to the Cloud Asset API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Asset service definition.
33///
34/// # Configuration
35///
36/// To configure `AssetService` use the `with_*` methods in the type returned
37/// by [builder()][AssetService::builder]. The default configuration should
38/// work for most applications. Common configuration changes include
39///
40/// * [with_endpoint()]: by default this client uses the global default endpoint
41///   (`https://cloudasset.googleapis.com`). Applications using regional
42///   endpoints or running in restricted networks (e.g. a network configured
43//    with [Private Google Access with VPC Service Controls]) may want to
44///   override this default.
45/// * [with_credentials()]: by default this client uses
46///   [Application Default Credentials]. Applications using custom
47///   authentication may need to override this default.
48///
49/// [with_endpoint()]: super::builder::asset_service::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::asset_service::ClientBuilder::credentials
51/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
52/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
53///
54/// # Pooling and Cloning
55///
56/// `AssetService` holds a connection pool internally, it is advised to
57/// create one and the reuse it.  You do not need to wrap `AssetService` in
58/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
59/// already uses an `Arc` internally.
60#[derive(Clone, Debug)]
61pub struct AssetService {
62    inner: std::sync::Arc<dyn super::stub::dynamic::AssetService>,
63}
64
65impl AssetService {
66    /// Returns a builder for [AssetService].
67    ///
68    /// ```
69    /// # tokio_test::block_on(async {
70    /// # use google_cloud_asset_v1::client::AssetService;
71    /// let client = AssetService::builder().build().await?;
72    /// # gax::client_builder::Result::<()>::Ok(()) });
73    /// ```
74    pub fn builder() -> super::builder::asset_service::ClientBuilder {
75        gax::client_builder::internal::new_builder(super::builder::asset_service::client::Factory)
76    }
77
78    /// Creates a new client from the provided stub.
79    ///
80    /// The most common case for calling this function is in tests mocking the
81    /// client's behavior.
82    pub fn from_stub<T>(stub: T) -> Self
83    where
84        T: super::stub::AssetService + 'static,
85    {
86        Self {
87            inner: std::sync::Arc::new(stub),
88        }
89    }
90
91    pub(crate) async fn new(
92        config: gaxi::options::ClientConfig,
93    ) -> gax::client_builder::Result<Self> {
94        let inner = Self::build_inner(config).await?;
95        Ok(Self { inner })
96    }
97
98    async fn build_inner(
99        conf: gaxi::options::ClientConfig,
100    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::AssetService>> {
101        if gaxi::options::tracing_enabled(&conf) {
102            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
103        }
104        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
105    }
106
107    async fn build_transport(
108        conf: gaxi::options::ClientConfig,
109    ) -> gax::client_builder::Result<impl super::stub::AssetService> {
110        super::transport::AssetService::new(conf).await
111    }
112
113    async fn build_with_tracing(
114        conf: gaxi::options::ClientConfig,
115    ) -> gax::client_builder::Result<impl super::stub::AssetService> {
116        Self::build_transport(conf)
117            .await
118            .map(super::tracing::AssetService::new)
119    }
120
121    /// Exports assets with time and resource types to a given Cloud Storage
122    /// location/BigQuery table. For Cloud Storage location destinations, the
123    /// output format is newline-delimited JSON. Each line represents a
124    /// [google.cloud.asset.v1.Asset][google.cloud.asset.v1.Asset] in the JSON
125    /// format; for BigQuery table destinations, the output table stores the fields
126    /// in asset Protobuf as columns. This API implements the
127    /// [google.longrunning.Operation][google.longrunning.Operation] API, which
128    /// allows you to keep track of the export. We recommend intervals of at least
129    /// 2 seconds with exponential retry to poll the export operation result. For
130    /// regular-size resource parent, the export operation usually finishes within
131    /// 5 minutes.
132    ///
133    /// [google.cloud.asset.v1.Asset]: crate::model::Asset
134    /// [google.longrunning.Operation]: longrunning::model::Operation
135    ///
136    /// # Long running operations
137    ///
138    /// This method is used to start, and/or poll a [long-running Operation].
139    /// The [Working with long-running operations] chapter in the [user guide]
140    /// covers these operations in detail.
141    ///
142    /// [long-running operation]: https://google.aip.dev/151
143    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
144    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
145    pub fn export_assets(&self) -> super::builder::asset_service::ExportAssets {
146        super::builder::asset_service::ExportAssets::new(self.inner.clone())
147    }
148
149    /// Lists assets with time and resource types and returns paged results in
150    /// response.
151    pub fn list_assets(&self) -> super::builder::asset_service::ListAssets {
152        super::builder::asset_service::ListAssets::new(self.inner.clone())
153    }
154
155    /// Batch gets the update history of assets that overlap a time window.
156    /// For IAM_POLICY content, this API outputs history when the asset and its
157    /// attached IAM POLICY both exist. This can create gaps in the output history.
158    /// Otherwise, this API outputs history with asset in both non-delete or
159    /// deleted status.
160    /// If a specified asset does not exist, this API returns an INVALID_ARGUMENT
161    /// error.
162    pub fn batch_get_assets_history(&self) -> super::builder::asset_service::BatchGetAssetsHistory {
163        super::builder::asset_service::BatchGetAssetsHistory::new(self.inner.clone())
164    }
165
166    /// Creates a feed in a parent project/folder/organization to listen to its
167    /// asset updates.
168    pub fn create_feed(&self) -> super::builder::asset_service::CreateFeed {
169        super::builder::asset_service::CreateFeed::new(self.inner.clone())
170    }
171
172    /// Gets details about an asset feed.
173    pub fn get_feed(&self) -> super::builder::asset_service::GetFeed {
174        super::builder::asset_service::GetFeed::new(self.inner.clone())
175    }
176
177    /// Lists all asset feeds in a parent project/folder/organization.
178    pub fn list_feeds(&self) -> super::builder::asset_service::ListFeeds {
179        super::builder::asset_service::ListFeeds::new(self.inner.clone())
180    }
181
182    /// Updates an asset feed configuration.
183    pub fn update_feed(&self) -> super::builder::asset_service::UpdateFeed {
184        super::builder::asset_service::UpdateFeed::new(self.inner.clone())
185    }
186
187    /// Deletes an asset feed.
188    pub fn delete_feed(&self) -> super::builder::asset_service::DeleteFeed {
189        super::builder::asset_service::DeleteFeed::new(self.inner.clone())
190    }
191
192    /// Searches all Google Cloud resources within the specified scope, such as a
193    /// project, folder, or organization. The caller must be granted the
194    /// `cloudasset.assets.searchAllResources` permission on the desired scope,
195    /// otherwise the request will be rejected.
196    pub fn search_all_resources(&self) -> super::builder::asset_service::SearchAllResources {
197        super::builder::asset_service::SearchAllResources::new(self.inner.clone())
198    }
199
200    /// Searches all IAM policies within the specified scope, such as a project,
201    /// folder, or organization. The caller must be granted the
202    /// `cloudasset.assets.searchAllIamPolicies` permission on the desired scope,
203    /// otherwise the request will be rejected.
204    pub fn search_all_iam_policies(&self) -> super::builder::asset_service::SearchAllIamPolicies {
205        super::builder::asset_service::SearchAllIamPolicies::new(self.inner.clone())
206    }
207
208    /// Analyzes IAM policies to answer which identities have what accesses on
209    /// which resources.
210    pub fn analyze_iam_policy(&self) -> super::builder::asset_service::AnalyzeIamPolicy {
211        super::builder::asset_service::AnalyzeIamPolicy::new(self.inner.clone())
212    }
213
214    /// Analyzes IAM policies asynchronously to answer which identities have what
215    /// accesses on which resources, and writes the analysis results to a Google
216    /// Cloud Storage or a BigQuery destination. For Cloud Storage destination, the
217    /// output format is the JSON format that represents a
218    /// [AnalyzeIamPolicyResponse][google.cloud.asset.v1.AnalyzeIamPolicyResponse].
219    /// This method implements the
220    /// [google.longrunning.Operation][google.longrunning.Operation], which allows
221    /// you to track the operation status. We recommend intervals of at least 2
222    /// seconds with exponential backoff retry to poll the operation result. The
223    /// metadata contains the metadata for the long-running operation.
224    ///
225    /// [google.cloud.asset.v1.AnalyzeIamPolicyResponse]: crate::model::AnalyzeIamPolicyResponse
226    /// [google.longrunning.Operation]: longrunning::model::Operation
227    ///
228    /// # Long running operations
229    ///
230    /// This method is used to start, and/or poll a [long-running Operation].
231    /// The [Working with long-running operations] chapter in the [user guide]
232    /// covers these operations in detail.
233    ///
234    /// [long-running operation]: https://google.aip.dev/151
235    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
236    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
237    pub fn analyze_iam_policy_longrunning(
238        &self,
239    ) -> super::builder::asset_service::AnalyzeIamPolicyLongrunning {
240        super::builder::asset_service::AnalyzeIamPolicyLongrunning::new(self.inner.clone())
241    }
242
243    /// Analyze moving a resource to a specified destination without kicking off
244    /// the actual move. The analysis is best effort depending on the user's
245    /// permissions of viewing different hierarchical policies and configurations.
246    /// The policies and configuration are subject to change before the actual
247    /// resource migration takes place.
248    pub fn analyze_move(&self) -> super::builder::asset_service::AnalyzeMove {
249        super::builder::asset_service::AnalyzeMove::new(self.inner.clone())
250    }
251
252    /// Issue a job that queries assets using a SQL statement compatible with
253    /// [BigQuery SQL](https://cloud.google.com/bigquery/docs/introduction-sql).
254    ///
255    /// If the query execution finishes within timeout and there's no pagination,
256    /// the full query results will be returned in the `QueryAssetsResponse`.
257    ///
258    /// Otherwise, full query results can be obtained by issuing extra requests
259    /// with the `job_reference` from the a previous `QueryAssets` call.
260    ///
261    /// Note, the query result has approximately 10 GB limitation enforced by
262    /// [BigQuery](https://cloud.google.com/bigquery/docs/best-practices-performance-output).
263    /// Queries return larger results will result in errors.
264    pub fn query_assets(&self) -> super::builder::asset_service::QueryAssets {
265        super::builder::asset_service::QueryAssets::new(self.inner.clone())
266    }
267
268    /// Creates a saved query in a parent project/folder/organization.
269    pub fn create_saved_query(&self) -> super::builder::asset_service::CreateSavedQuery {
270        super::builder::asset_service::CreateSavedQuery::new(self.inner.clone())
271    }
272
273    /// Gets details about a saved query.
274    pub fn get_saved_query(&self) -> super::builder::asset_service::GetSavedQuery {
275        super::builder::asset_service::GetSavedQuery::new(self.inner.clone())
276    }
277
278    /// Lists all saved queries in a parent project/folder/organization.
279    pub fn list_saved_queries(&self) -> super::builder::asset_service::ListSavedQueries {
280        super::builder::asset_service::ListSavedQueries::new(self.inner.clone())
281    }
282
283    /// Updates a saved query.
284    pub fn update_saved_query(&self) -> super::builder::asset_service::UpdateSavedQuery {
285        super::builder::asset_service::UpdateSavedQuery::new(self.inner.clone())
286    }
287
288    /// Deletes a saved query.
289    pub fn delete_saved_query(&self) -> super::builder::asset_service::DeleteSavedQuery {
290        super::builder::asset_service::DeleteSavedQuery::new(self.inner.clone())
291    }
292
293    /// Gets effective IAM policies for a batch of resources.
294    pub fn batch_get_effective_iam_policies(
295        &self,
296    ) -> super::builder::asset_service::BatchGetEffectiveIamPolicies {
297        super::builder::asset_service::BatchGetEffectiveIamPolicies::new(self.inner.clone())
298    }
299
300    /// Analyzes organization policies under a scope.
301    pub fn analyze_org_policies(&self) -> super::builder::asset_service::AnalyzeOrgPolicies {
302        super::builder::asset_service::AnalyzeOrgPolicies::new(self.inner.clone())
303    }
304
305    /// Analyzes organization policies governed containers (projects, folders or
306    /// organization) under a scope.
307    pub fn analyze_org_policy_governed_containers(
308        &self,
309    ) -> super::builder::asset_service::AnalyzeOrgPolicyGovernedContainers {
310        super::builder::asset_service::AnalyzeOrgPolicyGovernedContainers::new(self.inner.clone())
311    }
312
313    /// Analyzes organization policies governed assets (Google Cloud resources or
314    /// policies) under a scope. This RPC supports custom constraints and the
315    /// following canned constraints:
316    ///
317    /// * constraints/ainotebooks.accessMode
318    /// * constraints/ainotebooks.disableFileDownloads
319    /// * constraints/ainotebooks.disableRootAccess
320    /// * constraints/ainotebooks.disableTerminal
321    /// * constraints/ainotebooks.environmentOptions
322    /// * constraints/ainotebooks.requireAutoUpgradeSchedule
323    /// * constraints/ainotebooks.restrictVpcNetworks
324    /// * constraints/compute.disableGuestAttributesAccess
325    /// * constraints/compute.disableInstanceDataAccessApis
326    /// * constraints/compute.disableNestedVirtualization
327    /// * constraints/compute.disableSerialPortAccess
328    /// * constraints/compute.disableSerialPortLogging
329    /// * constraints/compute.disableVpcExternalIpv6
330    /// * constraints/compute.requireOsLogin
331    /// * constraints/compute.requireShieldedVm
332    /// * constraints/compute.restrictLoadBalancerCreationForTypes
333    /// * constraints/compute.restrictProtocolForwardingCreationForTypes
334    /// * constraints/compute.restrictXpnProjectLienRemoval
335    /// * constraints/compute.setNewProjectDefaultToZonalDNSOnly
336    /// * constraints/compute.skipDefaultNetworkCreation
337    /// * constraints/compute.trustedImageProjects
338    /// * constraints/compute.vmCanIpForward
339    /// * constraints/compute.vmExternalIpAccess
340    /// * constraints/gcp.detailedAuditLoggingMode
341    /// * constraints/gcp.resourceLocations
342    /// * constraints/iam.allowedPolicyMemberDomains
343    /// * constraints/iam.automaticIamGrantsForDefaultServiceAccounts
344    /// * constraints/iam.disableServiceAccountCreation
345    /// * constraints/iam.disableServiceAccountKeyCreation
346    /// * constraints/iam.disableServiceAccountKeyUpload
347    /// * constraints/iam.restrictCrossProjectServiceAccountLienRemoval
348    /// * constraints/iam.serviceAccountKeyExpiryHours
349    /// * constraints/resourcemanager.accessBoundaries
350    /// * constraints/resourcemanager.allowedExportDestinations
351    /// * constraints/sql.restrictAuthorizedNetworks
352    /// * constraints/sql.restrictNoncompliantDiagnosticDataAccess
353    /// * constraints/sql.restrictNoncompliantResourceCreation
354    /// * constraints/sql.restrictPublicIp
355    /// * constraints/storage.publicAccessPrevention
356    /// * constraints/storage.restrictAuthTypes
357    /// * constraints/storage.uniformBucketLevelAccess
358    ///
359    /// This RPC only returns either resources of types [supported by search
360    /// APIs](https://cloud.google.com/asset-inventory/docs/supported-asset-types)
361    /// or IAM policies.
362    pub fn analyze_org_policy_governed_assets(
363        &self,
364    ) -> super::builder::asset_service::AnalyzeOrgPolicyGovernedAssets {
365        super::builder::asset_service::AnalyzeOrgPolicyGovernedAssets::new(self.inner.clone())
366    }
367
368    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
369    ///
370    /// [google.longrunning.Operations]: longrunning::client::Operations
371    pub fn get_operation(&self) -> super::builder::asset_service::GetOperation {
372        super::builder::asset_service::GetOperation::new(self.inner.clone())
373    }
374}