google_cloud_bigquery_datapolicies_v2/
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 BigQuery Data Policy API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_bigquery_datapolicies_v2::client::DataPolicyService;
25/// let client = DataPolicyService::builder().build().await?;
26/// // use `client` to make requests to the BigQuery Data Policy API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Data Policy Service provides APIs for managing the BigQuery Data Policy.
33///
34/// # Configuration
35///
36/// To configure `DataPolicyService` use the `with_*` methods in the type returned
37/// by [builder()][DataPolicyService::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://bigquerydatapolicy.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::data_policy_service::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::data_policy_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/// `DataPolicyService` holds a connection pool internally, it is advised to
57/// create one and the reuse it.  You do not need to wrap `DataPolicyService` 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 DataPolicyService {
62    inner: std::sync::Arc<dyn super::stub::dynamic::DataPolicyService>,
63}
64
65impl DataPolicyService {
66    /// Returns a builder for [DataPolicyService].
67    ///
68    /// ```
69    /// # tokio_test::block_on(async {
70    /// # use google_cloud_bigquery_datapolicies_v2::client::DataPolicyService;
71    /// let client = DataPolicyService::builder().build().await?;
72    /// # gax::client_builder::Result::<()>::Ok(()) });
73    /// ```
74    pub fn builder() -> super::builder::data_policy_service::ClientBuilder {
75        gax::client_builder::internal::new_builder(
76            super::builder::data_policy_service::client::Factory,
77        )
78    }
79
80    /// Creates a new client from the provided stub.
81    ///
82    /// The most common case for calling this function is in tests mocking the
83    /// client's behavior.
84    pub fn from_stub<T>(stub: T) -> Self
85    where
86        T: super::stub::DataPolicyService + 'static,
87    {
88        Self {
89            inner: std::sync::Arc::new(stub),
90        }
91    }
92
93    pub(crate) async fn new(
94        config: gaxi::options::ClientConfig,
95    ) -> gax::client_builder::Result<Self> {
96        let inner = Self::build_inner(config).await?;
97        Ok(Self { inner })
98    }
99
100    async fn build_inner(
101        conf: gaxi::options::ClientConfig,
102    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::DataPolicyService>>
103    {
104        if gaxi::options::tracing_enabled(&conf) {
105            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
106        }
107        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
108    }
109
110    async fn build_transport(
111        conf: gaxi::options::ClientConfig,
112    ) -> gax::client_builder::Result<impl super::stub::DataPolicyService> {
113        super::transport::DataPolicyService::new(conf).await
114    }
115
116    async fn build_with_tracing(
117        conf: gaxi::options::ClientConfig,
118    ) -> gax::client_builder::Result<impl super::stub::DataPolicyService> {
119        Self::build_transport(conf)
120            .await
121            .map(super::tracing::DataPolicyService::new)
122    }
123
124    /// Creates a new data policy under a project with the given `data_policy_id`
125    /// (used as the display name), and data policy type.
126    pub fn create_data_policy(&self) -> super::builder::data_policy_service::CreateDataPolicy {
127        super::builder::data_policy_service::CreateDataPolicy::new(self.inner.clone())
128    }
129
130    /// Adds new grantees to a data policy.
131    /// The new grantees will be added to the existing grantees.
132    /// If the request contains a duplicate grantee, the grantee will be ignored.
133    /// If the request contains a grantee that already exists, the grantee will be
134    /// ignored.
135    pub fn add_grantees(&self) -> super::builder::data_policy_service::AddGrantees {
136        super::builder::data_policy_service::AddGrantees::new(self.inner.clone())
137    }
138
139    /// Removes grantees from a data policy.
140    /// The grantees will be removed from the existing grantees.
141    /// If the request contains a grantee that does not exist, the grantee will be
142    /// ignored.
143    pub fn remove_grantees(&self) -> super::builder::data_policy_service::RemoveGrantees {
144        super::builder::data_policy_service::RemoveGrantees::new(self.inner.clone())
145    }
146
147    /// Updates the metadata for an existing data policy. The target data policy
148    /// can be specified by the resource name.
149    pub fn update_data_policy(&self) -> super::builder::data_policy_service::UpdateDataPolicy {
150        super::builder::data_policy_service::UpdateDataPolicy::new(self.inner.clone())
151    }
152
153    /// Deletes the data policy specified by its resource name.
154    pub fn delete_data_policy(&self) -> super::builder::data_policy_service::DeleteDataPolicy {
155        super::builder::data_policy_service::DeleteDataPolicy::new(self.inner.clone())
156    }
157
158    /// Gets the data policy specified by its resource name.
159    pub fn get_data_policy(&self) -> super::builder::data_policy_service::GetDataPolicy {
160        super::builder::data_policy_service::GetDataPolicy::new(self.inner.clone())
161    }
162
163    /// List all of the data policies in the specified parent project.
164    pub fn list_data_policies(&self) -> super::builder::data_policy_service::ListDataPolicies {
165        super::builder::data_policy_service::ListDataPolicies::new(self.inner.clone())
166    }
167
168    /// Gets the IAM policy for the specified data policy.
169    pub fn get_iam_policy(&self) -> super::builder::data_policy_service::GetIamPolicy {
170        super::builder::data_policy_service::GetIamPolicy::new(self.inner.clone())
171    }
172
173    /// Sets the IAM policy for the specified data policy.
174    pub fn set_iam_policy(&self) -> super::builder::data_policy_service::SetIamPolicy {
175        super::builder::data_policy_service::SetIamPolicy::new(self.inner.clone())
176    }
177
178    /// Returns the caller's permission on the specified data policy resource.
179    pub fn test_iam_permissions(&self) -> super::builder::data_policy_service::TestIamPermissions {
180        super::builder::data_policy_service::TestIamPermissions::new(self.inner.clone())
181    }
182}