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/// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
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/// # 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 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
75 /// # use google_cloud_functions_v2::client::FunctionService;
76 /// let client = FunctionService::builder().build().await?;
77 /// # Ok(()) }
78 /// ```
79 pub fn builder() -> super::builder::function_service::ClientBuilder {
80 crate::new_client_builder(super::builder::function_service::client::Factory)
81 }
82
83 /// Creates a new client from the provided stub.
84 ///
85 /// The most common case for calling this function is in tests mocking the
86 /// client's behavior.
87 pub fn from_stub<T>(stub: T) -> Self
88 where
89 T: super::stub::FunctionService + 'static,
90 {
91 Self {
92 inner: std::sync::Arc::new(stub),
93 }
94 }
95
96 pub(crate) async fn new(
97 config: gaxi::options::ClientConfig,
98 ) -> crate::ClientBuilderResult<Self> {
99 let inner = Self::build_inner(config).await?;
100 Ok(Self { inner })
101 }
102
103 async fn build_inner(
104 conf: gaxi::options::ClientConfig,
105 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::FunctionService>> {
106 if gaxi::options::tracing_enabled(&conf) {
107 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
108 }
109 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
110 }
111
112 async fn build_transport(
113 conf: gaxi::options::ClientConfig,
114 ) -> crate::ClientBuilderResult<impl super::stub::FunctionService> {
115 super::transport::FunctionService::new(conf).await
116 }
117
118 async fn build_with_tracing(
119 conf: gaxi::options::ClientConfig,
120 ) -> crate::ClientBuilderResult<impl super::stub::FunctionService> {
121 Self::build_transport(conf)
122 .await
123 .map(super::tracing::FunctionService::new)
124 }
125
126 /// Returns a function with the given name from the requested project.
127 pub fn get_function(&self) -> super::builder::function_service::GetFunction {
128 super::builder::function_service::GetFunction::new(self.inner.clone())
129 }
130
131 /// Returns a list of functions that belong to the requested project.
132 pub fn list_functions(&self) -> super::builder::function_service::ListFunctions {
133 super::builder::function_service::ListFunctions::new(self.inner.clone())
134 }
135
136 /// Creates a new function. If a function with the given name already exists in
137 /// the specified project, the long running operation will return
138 /// `ALREADY_EXISTS` error.
139 ///
140 /// # Long running operations
141 ///
142 /// This method is used to start, and/or poll a [long-running Operation].
143 /// The [Working with long-running operations] chapter in the [user guide]
144 /// covers these operations in detail.
145 ///
146 /// [long-running operation]: https://google.aip.dev/151
147 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
148 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
149 pub fn create_function(&self) -> super::builder::function_service::CreateFunction {
150 super::builder::function_service::CreateFunction::new(self.inner.clone())
151 }
152
153 /// Updates existing function.
154 ///
155 /// # Long running operations
156 ///
157 /// This method is used to start, and/or poll a [long-running Operation].
158 /// The [Working with long-running operations] chapter in the [user guide]
159 /// covers these operations in detail.
160 ///
161 /// [long-running operation]: https://google.aip.dev/151
162 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
163 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
164 pub fn update_function(&self) -> super::builder::function_service::UpdateFunction {
165 super::builder::function_service::UpdateFunction::new(self.inner.clone())
166 }
167
168 /// Deletes a function with the given name from the specified project. If the
169 /// given function is used by some trigger, the trigger will be updated to
170 /// remove this function.
171 ///
172 /// # Long running operations
173 ///
174 /// This method is used to start, and/or poll a [long-running Operation].
175 /// The [Working with long-running operations] chapter in the [user guide]
176 /// covers these operations in detail.
177 ///
178 /// [long-running operation]: https://google.aip.dev/151
179 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
180 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
181 pub fn delete_function(&self) -> super::builder::function_service::DeleteFunction {
182 super::builder::function_service::DeleteFunction::new(self.inner.clone())
183 }
184
185 /// Returns a signed URL for uploading a function source code.
186 /// For more information about the signed URL usage see:
187 /// <https://cloud.google.com/storage/docs/access-control/signed-urls>.
188 /// Once the function source code upload is complete, the used signed
189 /// URL should be provided in CreateFunction or UpdateFunction request
190 /// as a reference to the function source code.
191 ///
192 /// When uploading source code to the generated signed URL, please follow
193 /// these restrictions:
194 ///
195 /// * Source file type should be a zip file.
196 /// * No credentials should be attached - the signed URLs provide access to the
197 /// target bucket using internal service identity; if credentials were
198 /// attached, the identity from the credentials would be used, but that
199 /// identity does not have permissions to upload files to the URL.
200 ///
201 /// When making a HTTP PUT request, specify this header:
202 ///
203 /// * `content-type: application/zip`
204 ///
205 /// Do not specify this header:
206 ///
207 /// * `Authorization: Bearer YOUR_TOKEN`
208 pub fn generate_upload_url(&self) -> super::builder::function_service::GenerateUploadUrl {
209 super::builder::function_service::GenerateUploadUrl::new(self.inner.clone())
210 }
211
212 /// Returns a signed URL for downloading deployed function source code.
213 /// The URL is only valid for a limited period and should be used within
214 /// 30 minutes of generation.
215 /// For more information about the signed URL usage see:
216 /// <https://cloud.google.com/storage/docs/access-control/signed-urls>
217 pub fn generate_download_url(&self) -> super::builder::function_service::GenerateDownloadUrl {
218 super::builder::function_service::GenerateDownloadUrl::new(self.inner.clone())
219 }
220
221 /// Returns a list of runtimes that are supported for the requested project.
222 pub fn list_runtimes(&self) -> super::builder::function_service::ListRuntimes {
223 super::builder::function_service::ListRuntimes::new(self.inner.clone())
224 }
225
226 /// Lists information about the supported locations for this service.
227 pub fn list_locations(&self) -> super::builder::function_service::ListLocations {
228 super::builder::function_service::ListLocations::new(self.inner.clone())
229 }
230
231 /// Sets the access control policy on the specified resource. Replaces
232 /// any existing policy.
233 ///
234 /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
235 /// errors.
236 pub fn set_iam_policy(&self) -> super::builder::function_service::SetIamPolicy {
237 super::builder::function_service::SetIamPolicy::new(self.inner.clone())
238 }
239
240 /// Gets the access control policy for a resource. Returns an empty policy
241 /// if the resource exists and does not have a policy set.
242 pub fn get_iam_policy(&self) -> super::builder::function_service::GetIamPolicy {
243 super::builder::function_service::GetIamPolicy::new(self.inner.clone())
244 }
245
246 /// Returns permissions that a caller has on the specified resource. If the
247 /// resource does not exist, this will return an empty set of
248 /// permissions, not a `NOT_FOUND` error.
249 ///
250 /// Note: This operation is designed to be used for building
251 /// permission-aware UIs and command-line tools, not for authorization
252 /// checking. This operation may "fail open" without warning.
253 pub fn test_iam_permissions(&self) -> super::builder::function_service::TestIamPermissions {
254 super::builder::function_service::TestIamPermissions::new(self.inner.clone())
255 }
256
257 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
258 ///
259 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
260 pub fn list_operations(&self) -> super::builder::function_service::ListOperations {
261 super::builder::function_service::ListOperations::new(self.inner.clone())
262 }
263
264 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
265 ///
266 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
267 pub fn get_operation(&self) -> super::builder::function_service::GetOperation {
268 super::builder::function_service::GetOperation::new(self.inner.clone())
269 }
270}