1# -*- coding: utf-8 -*-
2# Copyright 2026 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import abc
17from typing import Awaitable, Callable, Dict, Optional, Sequence, Union
18
19import google.api_core
20import google.auth # type: ignore
21import google.iam.v1.iam_policy_pb2 as iam_policy_pb2 # type: ignore
22import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore
23import google.protobuf
24import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
25from google.api_core import exceptions as core_exceptions
26from google.api_core import gapic_v1
27from google.api_core import retry as retries
28from google.auth import credentials as ga_credentials # type: ignore
29from google.cloud.location import locations_pb2 # type: ignore
30from google.oauth2 import service_account # type: ignore
31
32from google.cloud.secretmanager_v1beta1 import gapic_version as package_version
33from google.cloud.secretmanager_v1beta1.types import resources, service
34
35DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
36 gapic_version=package_version.__version__
37)
38DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
39
40
41class SecretManagerServiceTransport(abc.ABC):
42 """Abstract transport class for SecretManagerService."""
43
44 AUTH_SCOPES = ("https://www.googleapis.com/auth/cloud-platform",)
45
46 DEFAULT_HOST: str = "secretmanager.googleapis.com"
47
48 def __init__(
49 self,
50 *,
51 host: str = DEFAULT_HOST,
52 credentials: Optional[ga_credentials.Credentials] = None,
53 credentials_file: Optional[str] = None,
54 scopes: Optional[Sequence[str]] = None,
55 quota_project_id: Optional[str] = None,
56 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
57 always_use_jwt_access: Optional[bool] = False,
58 api_audience: Optional[str] = None,
59 **kwargs,
60 ) -> None:
61 """Instantiate the transport.
62
63 Args:
64 host (Optional[str]):
65 The hostname to connect to (default: 'secretmanager.googleapis.com').
66 credentials (Optional[google.auth.credentials.Credentials]): The
67 authorization credentials to attach to requests. These
68 credentials identify the application to the service; if none
69 are specified, the client will attempt to ascertain the
70 credentials from the environment.
71 credentials_file (Optional[str]): Deprecated. A file with credentials that can
72 be loaded with :func:`google.auth.load_credentials_from_file`.
73 This argument is mutually exclusive with credentials. This argument will be
74 removed in the next major version of this library.
75 scopes (Optional[Sequence[str]]): A list of scopes.
76 quota_project_id (Optional[str]): An optional project to use for billing
77 and quota.
78 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
79 The client info used to send a user-agent string along with
80 API requests. If ``None``, then default info will be used.
81 Generally, you only need to set this if you're developing
82 your own client library.
83 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
84 be used for service account credentials.
85 api_audience (Optional[str]): The intended audience for the API calls
86 to the service that will be set when using certain 3rd party
87 authentication flows. Audience is typically a resource identifier.
88 If not set, the host value will be used as a default.
89 """
90
91 # Save the scopes.
92 self._scopes = scopes
93 if not hasattr(self, "_ignore_credentials"):
94 self._ignore_credentials: bool = False
95
96 # If no credentials are provided, then determine the appropriate
97 # defaults.
98 if credentials and credentials_file:
99 raise core_exceptions.DuplicateCredentialArgs(
100 "'credentials_file' and 'credentials' are mutually exclusive"
101 )
102
103 if credentials_file is not None:
104 credentials, _ = google.auth.load_credentials_from_file(
105 credentials_file,
106 scopes=scopes,
107 quota_project_id=quota_project_id,
108 default_scopes=self.AUTH_SCOPES,
109 )
110 elif credentials is None and not self._ignore_credentials:
111 credentials, _ = google.auth.default(
112 scopes=scopes,
113 quota_project_id=quota_project_id,
114 default_scopes=self.AUTH_SCOPES,
115 )
116 # Don't apply audience if the credentials file passed from user.
117 if hasattr(credentials, "with_gdch_audience"):
118 credentials = credentials.with_gdch_audience(
119 api_audience if api_audience else host
120 )
121
122 # If the credentials are service account credentials, then always try to use self signed JWT.
123 if (
124 always_use_jwt_access
125 and isinstance(credentials, service_account.Credentials)
126 and hasattr(service_account.Credentials, "with_always_use_jwt_access")
127 ):
128 credentials = credentials.with_always_use_jwt_access(True)
129
130 # Save the credentials.
131 self._credentials = credentials
132
133 # Save the hostname. Default to port 443 (HTTPS) if none is specified.
134 if ":" not in host:
135 host += ":443"
136 self._host = host
137
138 self._wrapped_methods: Dict[Callable, Callable] = {}
139
140 @property
141 def host(self):
142 return self._host
143
144 def _prep_wrapped_messages(self, client_info):
145 # Precompute the wrapped methods.
146 self._wrapped_methods = {
147 self.list_secrets: gapic_v1.method.wrap_method(
148 self.list_secrets,
149 default_timeout=60.0,
150 client_info=client_info,
151 ),
152 self.create_secret: gapic_v1.method.wrap_method(
153 self.create_secret,
154 default_timeout=60.0,
155 client_info=client_info,
156 ),
157 self.add_secret_version: gapic_v1.method.wrap_method(
158 self.add_secret_version,
159 default_timeout=60.0,
160 client_info=client_info,
161 ),
162 self.get_secret: gapic_v1.method.wrap_method(
163 self.get_secret,
164 default_timeout=60.0,
165 client_info=client_info,
166 ),
167 self.update_secret: gapic_v1.method.wrap_method(
168 self.update_secret,
169 default_timeout=60.0,
170 client_info=client_info,
171 ),
172 self.delete_secret: gapic_v1.method.wrap_method(
173 self.delete_secret,
174 default_timeout=60.0,
175 client_info=client_info,
176 ),
177 self.list_secret_versions: gapic_v1.method.wrap_method(
178 self.list_secret_versions,
179 default_timeout=60.0,
180 client_info=client_info,
181 ),
182 self.get_secret_version: gapic_v1.method.wrap_method(
183 self.get_secret_version,
184 default_timeout=60.0,
185 client_info=client_info,
186 ),
187 self.access_secret_version: gapic_v1.method.wrap_method(
188 self.access_secret_version,
189 default_retry=retries.Retry(
190 initial=1.0,
191 maximum=60.0,
192 multiplier=1.3,
193 predicate=retries.if_exception_type(
194 core_exceptions.ServiceUnavailable,
195 core_exceptions.Unknown,
196 ),
197 deadline=60.0,
198 ),
199 default_timeout=60.0,
200 client_info=client_info,
201 ),
202 self.disable_secret_version: gapic_v1.method.wrap_method(
203 self.disable_secret_version,
204 default_timeout=60.0,
205 client_info=client_info,
206 ),
207 self.enable_secret_version: gapic_v1.method.wrap_method(
208 self.enable_secret_version,
209 default_timeout=60.0,
210 client_info=client_info,
211 ),
212 self.destroy_secret_version: gapic_v1.method.wrap_method(
213 self.destroy_secret_version,
214 default_timeout=60.0,
215 client_info=client_info,
216 ),
217 self.set_iam_policy: gapic_v1.method.wrap_method(
218 self.set_iam_policy,
219 default_timeout=60.0,
220 client_info=client_info,
221 ),
222 self.get_iam_policy: gapic_v1.method.wrap_method(
223 self.get_iam_policy,
224 default_timeout=60.0,
225 client_info=client_info,
226 ),
227 self.test_iam_permissions: gapic_v1.method.wrap_method(
228 self.test_iam_permissions,
229 default_timeout=60.0,
230 client_info=client_info,
231 ),
232 self.get_location: gapic_v1.method.wrap_method(
233 self.get_location,
234 default_timeout=None,
235 client_info=client_info,
236 ),
237 self.list_locations: gapic_v1.method.wrap_method(
238 self.list_locations,
239 default_timeout=None,
240 client_info=client_info,
241 ),
242 }
243
244 def close(self):
245 """Closes resources associated with the transport.
246
247 .. warning::
248 Only call this method if the transport is NOT shared
249 with other clients - this may cause errors in other clients!
250 """
251 raise NotImplementedError()
252
253 @property
254 def list_secrets(
255 self,
256 ) -> Callable[
257 [service.ListSecretsRequest],
258 Union[service.ListSecretsResponse, Awaitable[service.ListSecretsResponse]],
259 ]:
260 raise NotImplementedError()
261
262 @property
263 def create_secret(
264 self,
265 ) -> Callable[
266 [service.CreateSecretRequest],
267 Union[resources.Secret, Awaitable[resources.Secret]],
268 ]:
269 raise NotImplementedError()
270
271 @property
272 def add_secret_version(
273 self,
274 ) -> Callable[
275 [service.AddSecretVersionRequest],
276 Union[resources.SecretVersion, Awaitable[resources.SecretVersion]],
277 ]:
278 raise NotImplementedError()
279
280 @property
281 def get_secret(
282 self,
283 ) -> Callable[
284 [service.GetSecretRequest], Union[resources.Secret, Awaitable[resources.Secret]]
285 ]:
286 raise NotImplementedError()
287
288 @property
289 def update_secret(
290 self,
291 ) -> Callable[
292 [service.UpdateSecretRequest],
293 Union[resources.Secret, Awaitable[resources.Secret]],
294 ]:
295 raise NotImplementedError()
296
297 @property
298 def delete_secret(
299 self,
300 ) -> Callable[
301 [service.DeleteSecretRequest],
302 Union[empty_pb2.Empty, Awaitable[empty_pb2.Empty]],
303 ]:
304 raise NotImplementedError()
305
306 @property
307 def list_secret_versions(
308 self,
309 ) -> Callable[
310 [service.ListSecretVersionsRequest],
311 Union[
312 service.ListSecretVersionsResponse,
313 Awaitable[service.ListSecretVersionsResponse],
314 ],
315 ]:
316 raise NotImplementedError()
317
318 @property
319 def get_secret_version(
320 self,
321 ) -> Callable[
322 [service.GetSecretVersionRequest],
323 Union[resources.SecretVersion, Awaitable[resources.SecretVersion]],
324 ]:
325 raise NotImplementedError()
326
327 @property
328 def access_secret_version(
329 self,
330 ) -> Callable[
331 [service.AccessSecretVersionRequest],
332 Union[
333 service.AccessSecretVersionResponse,
334 Awaitable[service.AccessSecretVersionResponse],
335 ],
336 ]:
337 raise NotImplementedError()
338
339 @property
340 def disable_secret_version(
341 self,
342 ) -> Callable[
343 [service.DisableSecretVersionRequest],
344 Union[resources.SecretVersion, Awaitable[resources.SecretVersion]],
345 ]:
346 raise NotImplementedError()
347
348 @property
349 def enable_secret_version(
350 self,
351 ) -> Callable[
352 [service.EnableSecretVersionRequest],
353 Union[resources.SecretVersion, Awaitable[resources.SecretVersion]],
354 ]:
355 raise NotImplementedError()
356
357 @property
358 def destroy_secret_version(
359 self,
360 ) -> Callable[
361 [service.DestroySecretVersionRequest],
362 Union[resources.SecretVersion, Awaitable[resources.SecretVersion]],
363 ]:
364 raise NotImplementedError()
365
366 @property
367 def set_iam_policy(
368 self,
369 ) -> Callable[
370 [iam_policy_pb2.SetIamPolicyRequest],
371 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
372 ]:
373 raise NotImplementedError()
374
375 @property
376 def get_iam_policy(
377 self,
378 ) -> Callable[
379 [iam_policy_pb2.GetIamPolicyRequest],
380 Union[policy_pb2.Policy, Awaitable[policy_pb2.Policy]],
381 ]:
382 raise NotImplementedError()
383
384 @property
385 def test_iam_permissions(
386 self,
387 ) -> Callable[
388 [iam_policy_pb2.TestIamPermissionsRequest],
389 Union[
390 iam_policy_pb2.TestIamPermissionsResponse,
391 Awaitable[iam_policy_pb2.TestIamPermissionsResponse],
392 ],
393 ]:
394 raise NotImplementedError()
395
396 @property
397 def get_location(
398 self,
399 ) -> Callable[
400 [locations_pb2.GetLocationRequest],
401 Union[locations_pb2.Location, Awaitable[locations_pb2.Location]],
402 ]:
403 raise NotImplementedError()
404
405 @property
406 def list_locations(
407 self,
408 ) -> Callable[
409 [locations_pb2.ListLocationsRequest],
410 Union[
411 locations_pb2.ListLocationsResponse,
412 Awaitable[locations_pb2.ListLocationsResponse],
413 ],
414 ]:
415 raise NotImplementedError()
416
417 @property
418 def kind(self) -> str:
419 raise NotImplementedError()
420
421
422__all__ = ("SecretManagerServiceTransport",)