Skip to main content

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