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