google_cloud_functions_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 Cloud Functions API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_functions_v2::client::FunctionService;
25/// let client = FunctionService::builder().build().await?;
26/// // use `client` to make requests to the Cloud Functions API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Google Cloud Functions is used to deploy functions that are executed by
33/// Google in response to various events. Data connected with that event is
34/// passed to a function as the input data.
35///
36/// A **function** is a resource which describes a function that should be
37/// executed and how it is triggered.
38///
39/// # Configuration
40///
41/// To configure `FunctionService` use the `with_*` methods in the type returned
42/// by [builder()][FunctionService::builder]. The default configuration should
43/// work for most applications. Common configuration changes include
44///
45/// * [with_endpoint()]: by default this client uses the global default endpoint
46/// (`https://cloudfunctions.googleapis.com`). Applications using regional
47/// endpoints or running in restricted networks (e.g. a network configured
48// with [Private Google Access with VPC Service Controls]) may want to
49/// override this default.
50/// * [with_credentials()]: by default this client uses
51/// [Application Default Credentials]. Applications using custom
52/// authentication may need to override this default.
53///
54/// [with_endpoint()]: super::builder::function_service::ClientBuilder::with_endpoint
55/// [with_credentials()]: super::builder::function_service::ClientBuilder::credentials
56/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
57/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
58///
59/// # Pooling and Cloning
60///
61/// `FunctionService` holds a connection pool internally, it is advised to
62/// create one and the reuse it. You do not need to wrap `FunctionService` in
63/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
64/// already uses an `Arc` internally.
65#[derive(Clone, Debug)]
66pub struct FunctionService {
67 inner: std::sync::Arc<dyn super::stub::dynamic::FunctionService>,
68}
69
70impl FunctionService {
71 /// Returns a builder for [FunctionService].
72 ///
73 /// ```
74 /// # tokio_test::block_on(async {
75 /// # use google_cloud_functions_v2::client::FunctionService;
76 /// let client = FunctionService::builder().build().await?;
77 /// # gax::client_builder::Result::<()>::Ok(()) });
78 /// ```
79 pub fn builder() -> super::builder::function_service::ClientBuilder {
80 gax::client_builder::internal::new_builder(
81 super::builder::function_service::client::Factory,
82 )
83 }
84
85 /// Creates a new client from the provided stub.
86 ///
87 /// The most common case for calling this function is in tests mocking the
88 /// client's behavior.
89 pub fn from_stub<T>(stub: T) -> Self
90 where
91 T: super::stub::FunctionService + 'static,
92 {
93 Self {
94 inner: std::sync::Arc::new(stub),
95 }
96 }
97
98 pub(crate) async fn new(
99 config: gaxi::options::ClientConfig,
100 ) -> gax::client_builder::Result<Self> {
101 let inner = Self::build_inner(config).await?;
102 Ok(Self { inner })
103 }
104
105 async fn build_inner(
106 conf: gaxi::options::ClientConfig,
107 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::FunctionService>>
108 {
109 if gaxi::options::tracing_enabled(&conf) {
110 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111 }
112 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113 }
114
115 async fn build_transport(
116 conf: gaxi::options::ClientConfig,
117 ) -> gax::client_builder::Result<impl super::stub::FunctionService> {
118 super::transport::FunctionService::new(conf).await
119 }
120
121 async fn build_with_tracing(
122 conf: gaxi::options::ClientConfig,
123 ) -> gax::client_builder::Result<impl super::stub::FunctionService> {
124 Self::build_transport(conf)
125 .await
126 .map(super::tracing::FunctionService::new)
127 }
128
129 /// Returns a function with the given name from the requested project.
130 pub fn get_function(&self) -> super::builder::function_service::GetFunction {
131 super::builder::function_service::GetFunction::new(self.inner.clone())
132 }
133
134 /// Returns a list of functions that belong to the requested project.
135 pub fn list_functions(&self) -> super::builder::function_service::ListFunctions {
136 super::builder::function_service::ListFunctions::new(self.inner.clone())
137 }
138
139 /// Creates a new function. If a function with the given name already exists in
140 /// the specified project, the long running operation will return
141 /// `ALREADY_EXISTS` error.
142 ///
143 /// # Long running operations
144 ///
145 /// This method is used to start, and/or poll a [long-running Operation].
146 /// The [Working with long-running operations] chapter in the [user guide]
147 /// covers these operations in detail.
148 ///
149 /// [long-running operation]: https://google.aip.dev/151
150 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
151 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
152 pub fn create_function(&self) -> super::builder::function_service::CreateFunction {
153 super::builder::function_service::CreateFunction::new(self.inner.clone())
154 }
155
156 /// Updates existing function.
157 ///
158 /// # Long running operations
159 ///
160 /// This method is used to start, and/or poll a [long-running Operation].
161 /// The [Working with long-running operations] chapter in the [user guide]
162 /// covers these operations in detail.
163 ///
164 /// [long-running operation]: https://google.aip.dev/151
165 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
166 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
167 pub fn update_function(&self) -> super::builder::function_service::UpdateFunction {
168 super::builder::function_service::UpdateFunction::new(self.inner.clone())
169 }
170
171 /// Deletes a function with the given name from the specified project. If the
172 /// given function is used by some trigger, the trigger will be updated to
173 /// remove this function.
174 ///
175 /// # Long running operations
176 ///
177 /// This method is used to start, and/or poll a [long-running Operation].
178 /// The [Working with long-running operations] chapter in the [user guide]
179 /// covers these operations in detail.
180 ///
181 /// [long-running operation]: https://google.aip.dev/151
182 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
183 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
184 pub fn delete_function(&self) -> super::builder::function_service::DeleteFunction {
185 super::builder::function_service::DeleteFunction::new(self.inner.clone())
186 }
187
188 /// Returns a signed URL for uploading a function source code.
189 /// For more information about the signed URL usage see:
190 /// <https://cloud.google.com/storage/docs/access-control/signed-urls>.
191 /// Once the function source code upload is complete, the used signed
192 /// URL should be provided in CreateFunction or UpdateFunction request
193 /// as a reference to the function source code.
194 ///
195 /// When uploading source code to the generated signed URL, please follow
196 /// these restrictions:
197 ///
198 /// * Source file type should be a zip file.
199 /// * No credentials should be attached - the signed URLs provide access to the
200 /// target bucket using internal service identity; if credentials were
201 /// attached, the identity from the credentials would be used, but that
202 /// identity does not have permissions to upload files to the URL.
203 ///
204 /// When making a HTTP PUT request, specify this header:
205 ///
206 /// * `content-type: application/zip`
207 ///
208 /// Do not specify this header:
209 ///
210 /// * `Authorization: Bearer YOUR_TOKEN`
211 pub fn generate_upload_url(&self) -> super::builder::function_service::GenerateUploadUrl {
212 super::builder::function_service::GenerateUploadUrl::new(self.inner.clone())
213 }
214
215 /// Returns a signed URL for downloading deployed function source code.
216 /// The URL is only valid for a limited period and should be used within
217 /// 30 minutes of generation.
218 /// For more information about the signed URL usage see:
219 /// <https://cloud.google.com/storage/docs/access-control/signed-urls>
220 pub fn generate_download_url(&self) -> super::builder::function_service::GenerateDownloadUrl {
221 super::builder::function_service::GenerateDownloadUrl::new(self.inner.clone())
222 }
223
224 /// Returns a list of runtimes that are supported for the requested project.
225 pub fn list_runtimes(&self) -> super::builder::function_service::ListRuntimes {
226 super::builder::function_service::ListRuntimes::new(self.inner.clone())
227 }
228
229 /// Lists information about the supported locations for this service.
230 pub fn list_locations(&self) -> super::builder::function_service::ListLocations {
231 super::builder::function_service::ListLocations::new(self.inner.clone())
232 }
233
234 /// Sets the access control policy on the specified resource. Replaces
235 /// any existing policy.
236 ///
237 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
238 /// errors.
239 pub fn set_iam_policy(&self) -> super::builder::function_service::SetIamPolicy {
240 super::builder::function_service::SetIamPolicy::new(self.inner.clone())
241 }
242
243 /// Gets the access control policy for a resource. Returns an empty policy
244 /// if the resource exists and does not have a policy set.
245 pub fn get_iam_policy(&self) -> super::builder::function_service::GetIamPolicy {
246 super::builder::function_service::GetIamPolicy::new(self.inner.clone())
247 }
248
249 /// Returns permissions that a caller has on the specified resource. If the
250 /// resource does not exist, this will return an empty set of
251 /// permissions, not a `NOT_FOUND` error.
252 ///
253 /// Note: This operation is designed to be used for building
254 /// permission-aware UIs and command-line tools, not for authorization
255 /// checking. This operation may "fail open" without warning.
256 pub fn test_iam_permissions(&self) -> super::builder::function_service::TestIamPermissions {
257 super::builder::function_service::TestIamPermissions::new(self.inner.clone())
258 }
259
260 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
261 ///
262 /// [google.longrunning.Operations]: longrunning::client::Operations
263 pub fn list_operations(&self) -> super::builder::function_service::ListOperations {
264 super::builder::function_service::ListOperations::new(self.inner.clone())
265 }
266
267 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
268 ///
269 /// [google.longrunning.Operations]: longrunning::client::Operations
270 pub fn get_operation(&self) -> super::builder::function_service::GetOperation {
271 super::builder::function_service::GetOperation::new(self.inner.clone())
272 }
273}