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/// # use google_cloud_functions_v2::client::FunctionService;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// async fn sample(
26/// project_id: &str,
27/// location_id: &str,
28/// ) -> anyhow::Result<()> {
29/// let client = FunctionService::builder().build().await?;
30/// let mut list = client.list_functions()
31/// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
32/// .by_item();
33/// while let Some(item) = list.next().await.transpose()? {
34/// println!("{:?}", item);
35/// }
36/// Ok(())
37/// }
38/// ```
39///
40/// # Service Description
41///
42/// Google Cloud Functions is used to deploy functions that are executed by
43/// Google in response to various events. Data connected with that event is
44/// passed to a function as the input data.
45///
46/// A **function** is a resource which describes a function that should be
47/// executed and how it is triggered.
48///
49/// # Configuration
50///
51/// To configure `FunctionService` use the `with_*` methods in the type returned
52/// by [builder()][FunctionService::builder]. The default configuration should
53/// work for most applications. Common configuration changes include
54///
55/// * [with_endpoint()]: by default this client uses the global default endpoint
56/// (`https://cloudfunctions.googleapis.com`). Applications using regional
57/// endpoints or running in restricted networks (e.g. a network configured
58// with [Private Google Access with VPC Service Controls]) may want to
59/// override this default.
60/// * [with_credentials()]: by default this client uses
61/// [Application Default Credentials]. Applications using custom
62/// authentication may need to override this default.
63///
64/// [with_endpoint()]: super::builder::function_service::ClientBuilder::with_endpoint
65/// [with_credentials()]: super::builder::function_service::ClientBuilder::with_credentials
66/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
67/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
68///
69/// # Pooling and Cloning
70///
71/// `FunctionService` holds a connection pool internally, it is advised to
72/// create one and reuse it. You do not need to wrap `FunctionService` in
73/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
74/// already uses an `Arc` internally.
75#[derive(Clone, Debug)]
76pub struct FunctionService {
77 inner: std::sync::Arc<dyn super::stub::dynamic::FunctionService>,
78}
79
80impl FunctionService {
81 /// Returns a builder for [FunctionService].
82 ///
83 /// ```
84 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
85 /// # use google_cloud_functions_v2::client::FunctionService;
86 /// let client = FunctionService::builder().build().await?;
87 /// # Ok(()) }
88 /// ```
89 pub fn builder() -> super::builder::function_service::ClientBuilder {
90 crate::new_client_builder(super::builder::function_service::client::Factory)
91 }
92
93 /// Creates a new client from the provided stub.
94 ///
95 /// The most common case for calling this function is in tests mocking the
96 /// client's behavior.
97 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
98 where
99 T: super::stub::FunctionService + 'static,
100 {
101 Self { inner: stub.into() }
102 }
103
104 pub(crate) async fn new(
105 config: gaxi::options::ClientConfig,
106 ) -> crate::ClientBuilderResult<Self> {
107 let inner = Self::build_inner(config).await?;
108 Ok(Self { inner })
109 }
110
111 async fn build_inner(
112 conf: gaxi::options::ClientConfig,
113 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::FunctionService>> {
114 if gaxi::options::tracing_enabled(&conf) {
115 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
116 }
117 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
118 }
119
120 async fn build_transport(
121 conf: gaxi::options::ClientConfig,
122 ) -> crate::ClientBuilderResult<impl super::stub::FunctionService> {
123 super::transport::FunctionService::new(conf).await
124 }
125
126 async fn build_with_tracing(
127 conf: gaxi::options::ClientConfig,
128 ) -> crate::ClientBuilderResult<impl super::stub::FunctionService> {
129 Self::build_transport(conf)
130 .await
131 .map(super::tracing::FunctionService::new)
132 }
133
134 /// Returns a function with the given name from the requested project.
135 ///
136 /// # Example
137 /// ```
138 /// # use google_cloud_functions_v2::client::FunctionService;
139 /// use google_cloud_functions_v2::Result;
140 /// async fn sample(
141 /// client: &FunctionService, project_id: &str, location_id: &str, function_id: &str
142 /// ) -> Result<()> {
143 /// let response = client.get_function()
144 /// .set_name(format!("projects/{project_id}/locations/{location_id}/functions/{function_id}"))
145 /// .send().await?;
146 /// println!("response {:?}", response);
147 /// Ok(())
148 /// }
149 /// ```
150 pub fn get_function(&self) -> super::builder::function_service::GetFunction {
151 super::builder::function_service::GetFunction::new(self.inner.clone())
152 }
153
154 /// Returns a list of functions that belong to the requested project.
155 ///
156 /// # Example
157 /// ```
158 /// # use google_cloud_functions_v2::client::FunctionService;
159 /// use google_cloud_gax::paginator::ItemPaginator as _;
160 /// use google_cloud_functions_v2::Result;
161 /// async fn sample(
162 /// client: &FunctionService, project_id: &str, location_id: &str
163 /// ) -> Result<()> {
164 /// let mut list = client.list_functions()
165 /// .set_parent(format!("projects/{project_id}/locations/{location_id}"))
166 /// .by_item();
167 /// while let Some(item) = list.next().await.transpose()? {
168 /// println!("{:?}", item);
169 /// }
170 /// Ok(())
171 /// }
172 /// ```
173 pub fn list_functions(&self) -> super::builder::function_service::ListFunctions {
174 super::builder::function_service::ListFunctions::new(self.inner.clone())
175 }
176
177 /// Creates a new function. If a function with the given name already exists in
178 /// the specified project, the long running operation will return
179 /// `ALREADY_EXISTS` error.
180 ///
181 /// # Long running operations
182 ///
183 /// This method is used to start, and/or poll a [long-running Operation].
184 /// The [Working with long-running operations] chapter in the [user guide]
185 /// covers these operations in detail.
186 ///
187 /// [long-running operation]: https://google.aip.dev/151
188 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
189 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
190 ///
191 /// # Example
192 /// ```
193 /// # use google_cloud_functions_v2::client::FunctionService;
194 /// use google_cloud_lro::Poller;
195 /// use google_cloud_functions_v2::model::Function;
196 /// use google_cloud_functions_v2::Result;
197 /// async fn sample(
198 /// client: &FunctionService, parent: &str
199 /// ) -> Result<()> {
200 /// let response = client.create_function()
201 /// .set_parent(parent)
202 /// .set_function_id("function_id_value")
203 /// .set_function(
204 /// Function::new()/* set fields */
205 /// )
206 /// .poller().until_done().await?;
207 /// println!("response {:?}", response);
208 /// Ok(())
209 /// }
210 /// ```
211 pub fn create_function(&self) -> super::builder::function_service::CreateFunction {
212 super::builder::function_service::CreateFunction::new(self.inner.clone())
213 }
214
215 /// Updates existing function.
216 ///
217 /// # Long running operations
218 ///
219 /// This method is used to start, and/or poll a [long-running Operation].
220 /// The [Working with long-running operations] chapter in the [user guide]
221 /// covers these operations in detail.
222 ///
223 /// [long-running operation]: https://google.aip.dev/151
224 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
225 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
226 ///
227 /// # Example
228 /// ```
229 /// # use google_cloud_functions_v2::client::FunctionService;
230 /// use google_cloud_lro::Poller;
231 /// # extern crate wkt as google_cloud_wkt;
232 /// use google_cloud_wkt::FieldMask;
233 /// use google_cloud_functions_v2::model::Function;
234 /// use google_cloud_functions_v2::Result;
235 /// async fn sample(
236 /// client: &FunctionService, project_id: &str, location_id: &str, function_id: &str
237 /// ) -> Result<()> {
238 /// let response = client.update_function()
239 /// .set_function(
240 /// Function::new().set_name(format!("projects/{project_id}/locations/{location_id}/functions/{function_id}"))/* set fields */
241 /// )
242 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
243 /// .poller().until_done().await?;
244 /// println!("response {:?}", response);
245 /// Ok(())
246 /// }
247 /// ```
248 pub fn update_function(&self) -> super::builder::function_service::UpdateFunction {
249 super::builder::function_service::UpdateFunction::new(self.inner.clone())
250 }
251
252 /// Deletes a function with the given name from the specified project. If the
253 /// given function is used by some trigger, the trigger will be updated to
254 /// remove this function.
255 ///
256 /// # Long running operations
257 ///
258 /// This method is used to start, and/or poll a [long-running Operation].
259 /// The [Working with long-running operations] chapter in the [user guide]
260 /// covers these operations in detail.
261 ///
262 /// [long-running operation]: https://google.aip.dev/151
263 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
264 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
265 ///
266 /// # Example
267 /// ```
268 /// # use google_cloud_functions_v2::client::FunctionService;
269 /// use google_cloud_lro::Poller;
270 /// use google_cloud_functions_v2::Result;
271 /// async fn sample(
272 /// client: &FunctionService, project_id: &str, location_id: &str, function_id: &str
273 /// ) -> Result<()> {
274 /// client.delete_function()
275 /// .set_name(format!("projects/{project_id}/locations/{location_id}/functions/{function_id}"))
276 /// .poller().until_done().await?;
277 /// Ok(())
278 /// }
279 /// ```
280 pub fn delete_function(&self) -> super::builder::function_service::DeleteFunction {
281 super::builder::function_service::DeleteFunction::new(self.inner.clone())
282 }
283
284 /// Returns a signed URL for uploading a function source code.
285 /// For more information about the signed URL usage see:
286 /// <https://cloud.google.com/storage/docs/access-control/signed-urls>.
287 /// Once the function source code upload is complete, the used signed
288 /// URL should be provided in CreateFunction or UpdateFunction request
289 /// as a reference to the function source code.
290 ///
291 /// When uploading source code to the generated signed URL, please follow
292 /// these restrictions:
293 ///
294 /// * Source file type should be a zip file.
295 /// * No credentials should be attached - the signed URLs provide access to the
296 /// target bucket using internal service identity; if credentials were
297 /// attached, the identity from the credentials would be used, but that
298 /// identity does not have permissions to upload files to the URL.
299 ///
300 /// When making a HTTP PUT request, specify this header:
301 ///
302 /// * `content-type: application/zip`
303 ///
304 /// Do not specify this header:
305 ///
306 /// * `Authorization: Bearer YOUR_TOKEN`
307 ///
308 /// # Example
309 /// ```
310 /// # use google_cloud_functions_v2::client::FunctionService;
311 /// use google_cloud_functions_v2::Result;
312 /// async fn sample(
313 /// client: &FunctionService
314 /// ) -> Result<()> {
315 /// let response = client.generate_upload_url()
316 /// /* set fields */
317 /// .send().await?;
318 /// println!("response {:?}", response);
319 /// Ok(())
320 /// }
321 /// ```
322 pub fn generate_upload_url(&self) -> super::builder::function_service::GenerateUploadUrl {
323 super::builder::function_service::GenerateUploadUrl::new(self.inner.clone())
324 }
325
326 /// Returns a signed URL for downloading deployed function source code.
327 /// The URL is only valid for a limited period and should be used within
328 /// 30 minutes of generation.
329 /// For more information about the signed URL usage see:
330 /// <https://cloud.google.com/storage/docs/access-control/signed-urls>
331 ///
332 /// # Example
333 /// ```
334 /// # use google_cloud_functions_v2::client::FunctionService;
335 /// use google_cloud_functions_v2::Result;
336 /// async fn sample(
337 /// client: &FunctionService
338 /// ) -> Result<()> {
339 /// let response = client.generate_download_url()
340 /// /* set fields */
341 /// .send().await?;
342 /// println!("response {:?}", response);
343 /// Ok(())
344 /// }
345 /// ```
346 pub fn generate_download_url(&self) -> super::builder::function_service::GenerateDownloadUrl {
347 super::builder::function_service::GenerateDownloadUrl::new(self.inner.clone())
348 }
349
350 /// Returns a list of runtimes that are supported for the requested project.
351 ///
352 /// # Example
353 /// ```
354 /// # use google_cloud_functions_v2::client::FunctionService;
355 /// use google_cloud_functions_v2::Result;
356 /// async fn sample(
357 /// client: &FunctionService
358 /// ) -> Result<()> {
359 /// let response = client.list_runtimes()
360 /// /* set fields */
361 /// .send().await?;
362 /// println!("response {:?}", response);
363 /// Ok(())
364 /// }
365 /// ```
366 pub fn list_runtimes(&self) -> super::builder::function_service::ListRuntimes {
367 super::builder::function_service::ListRuntimes::new(self.inner.clone())
368 }
369
370 /// Lists information about the supported locations for this service.
371 ///
372 /// # Example
373 /// ```
374 /// # use google_cloud_functions_v2::client::FunctionService;
375 /// use google_cloud_gax::paginator::ItemPaginator as _;
376 /// use google_cloud_functions_v2::Result;
377 /// async fn sample(
378 /// client: &FunctionService
379 /// ) -> Result<()> {
380 /// let mut list = client.list_locations()
381 /// /* set fields */
382 /// .by_item();
383 /// while let Some(item) = list.next().await.transpose()? {
384 /// println!("{:?}", item);
385 /// }
386 /// Ok(())
387 /// }
388 /// ```
389 pub fn list_locations(&self) -> super::builder::function_service::ListLocations {
390 super::builder::function_service::ListLocations::new(self.inner.clone())
391 }
392
393 /// Sets the access control policy on the specified resource. Replaces
394 /// any existing policy.
395 ///
396 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
397 /// errors.
398 ///
399 /// # Example
400 /// ```
401 /// # use google_cloud_functions_v2::client::FunctionService;
402 /// use google_cloud_functions_v2::Result;
403 /// async fn sample(
404 /// client: &FunctionService
405 /// ) -> Result<()> {
406 /// let response = client.set_iam_policy()
407 /// /* set fields */
408 /// .send().await?;
409 /// println!("response {:?}", response);
410 /// Ok(())
411 /// }
412 /// ```
413 pub fn set_iam_policy(&self) -> super::builder::function_service::SetIamPolicy {
414 super::builder::function_service::SetIamPolicy::new(self.inner.clone())
415 }
416
417 /// Gets the access control policy for a resource. Returns an empty policy
418 /// if the resource exists and does not have a policy set.
419 ///
420 /// # Example
421 /// ```
422 /// # use google_cloud_functions_v2::client::FunctionService;
423 /// use google_cloud_functions_v2::Result;
424 /// async fn sample(
425 /// client: &FunctionService
426 /// ) -> Result<()> {
427 /// let response = client.get_iam_policy()
428 /// /* set fields */
429 /// .send().await?;
430 /// println!("response {:?}", response);
431 /// Ok(())
432 /// }
433 /// ```
434 pub fn get_iam_policy(&self) -> super::builder::function_service::GetIamPolicy {
435 super::builder::function_service::GetIamPolicy::new(self.inner.clone())
436 }
437
438 /// Returns permissions that a caller has on the specified resource. If the
439 /// resource does not exist, this will return an empty set of
440 /// permissions, not a `NOT_FOUND` error.
441 ///
442 /// Note: This operation is designed to be used for building
443 /// permission-aware UIs and command-line tools, not for authorization
444 /// checking. This operation may "fail open" without warning.
445 ///
446 /// # Example
447 /// ```
448 /// # use google_cloud_functions_v2::client::FunctionService;
449 /// use google_cloud_functions_v2::Result;
450 /// async fn sample(
451 /// client: &FunctionService
452 /// ) -> Result<()> {
453 /// let response = client.test_iam_permissions()
454 /// /* set fields */
455 /// .send().await?;
456 /// println!("response {:?}", response);
457 /// Ok(())
458 /// }
459 /// ```
460 pub fn test_iam_permissions(&self) -> super::builder::function_service::TestIamPermissions {
461 super::builder::function_service::TestIamPermissions::new(self.inner.clone())
462 }
463
464 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
465 ///
466 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
467 ///
468 /// # Example
469 /// ```
470 /// # use google_cloud_functions_v2::client::FunctionService;
471 /// use google_cloud_gax::paginator::ItemPaginator as _;
472 /// use google_cloud_functions_v2::Result;
473 /// async fn sample(
474 /// client: &FunctionService
475 /// ) -> Result<()> {
476 /// let mut list = client.list_operations()
477 /// /* set fields */
478 /// .by_item();
479 /// while let Some(item) = list.next().await.transpose()? {
480 /// println!("{:?}", item);
481 /// }
482 /// Ok(())
483 /// }
484 /// ```
485 pub fn list_operations(&self) -> super::builder::function_service::ListOperations {
486 super::builder::function_service::ListOperations::new(self.inner.clone())
487 }
488
489 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
490 ///
491 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
492 ///
493 /// # Example
494 /// ```
495 /// # use google_cloud_functions_v2::client::FunctionService;
496 /// use google_cloud_functions_v2::Result;
497 /// async fn sample(
498 /// client: &FunctionService
499 /// ) -> Result<()> {
500 /// let response = client.get_operation()
501 /// /* set fields */
502 /// .send().await?;
503 /// println!("response {:?}", response);
504 /// Ok(())
505 /// }
506 /// ```
507 pub fn get_operation(&self) -> super::builder::function_service::GetOperation {
508 super::builder::function_service::GetOperation::new(self.inner.clone())
509 }
510}