Skip to content
This repository was archived by the owner on Mar 2, 2026. It is now read-only.

Commit 403afb0

Browse files
feat(gapic): support mTLS certificates when available (#1140)
Autogenerated gapic update Includes: - support for mTLS by default when the environment detects it - support for pipelines protos
1 parent d1c730d commit 403afb0

53 files changed

Lines changed: 2740 additions & 493 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.librarian/state.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:ce48ed695c727f7e13efd1fd68f466a55a0d772c87b69158720cec39965bc8b2
1+
image: us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator@sha256:eec191fc4904c204cd717c79812cd66997b5559776483ee223f69c8f43e99224
22
libraries:
33
- id: google-cloud-firestore
44
version: 2.21.0

‎google/cloud/firestore_admin_v1/services/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
17+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18+
# The source of truth for this file is `.librarian/generator-input`

‎google/cloud/firestore_admin_v1/services/firestore_admin/__init__.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
from .clientimportFirestoreAdminClient
16+
17+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18+
# The source of truth for this file is `.librarian/generator-input`
19+
1720
from .async_clientimportFirestoreAdminAsyncClient
21+
from .clientimportFirestoreAdminClient
1822

1923
__all__= (
2024
"FirestoreAdminClient",

‎google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
importloggingasstd_logging
16+
17+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18+
# The source of truth for this file is `.librarian/generator-input`
19+
1720
fromcollectionsimportOrderedDict
21+
importloggingasstd_logging
1822
importre
1923
fromtypingimport (
20-
Dict,
2124
Callable,
25+
Dict,
2226
Mapping,
2327
MutableMapping,
2428
MutableSequence,
@@ -29,16 +33,15 @@
2933
Union,
3034
)
3135

32-
fromgoogle.cloud.firestore_admin_v1importgapic_versionaspackage_version
33-
34-
fromgoogle.api_core.client_optionsimportClientOptions
3536
fromgoogle.api_coreimportexceptionsascore_exceptions
3637
fromgoogle.api_coreimportgapic_v1
3738
fromgoogle.api_coreimportretry_asyncasretries
39+
fromgoogle.api_core.client_optionsimportClientOptions
3840
fromgoogle.authimportcredentialsasga_credentials# type: ignore
3941
fromgoogle.oauth2importservice_account# type: ignore
4042
importgoogle.protobuf
4143

44+
fromgoogle.cloud.firestore_admin_v1importgapic_versionaspackage_version
4245

4346
try:
4447
OptionalRetry=Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None]
@@ -47,6 +50,13 @@
4750

4851
fromgoogle.api_coreimportoperationasgac_operation# type: ignore
4952
fromgoogle.api_coreimportoperation_async# type: ignore
53+
fromgoogle.cloud.locationimportlocations_pb2# type: ignore
54+
fromgoogle.longrunningimportoperations_pb2# type: ignore
55+
fromgoogle.protobufimportduration_pb2# type: ignore
56+
fromgoogle.protobufimportempty_pb2# type: ignore
57+
fromgoogle.protobufimportfield_mask_pb2# type: ignore
58+
fromgoogle.protobufimporttimestamp_pb2# type: ignore
59+
5060
fromgoogle.cloud.firestore_admin_v1.services.firestore_adminimportpagers
5161
fromgoogle.cloud.firestore_admin_v1.typesimportbackup
5262
fromgoogle.cloud.firestore_admin_v1.typesimportdatabase
@@ -60,15 +70,10 @@
6070
fromgoogle.cloud.firestore_admin_v1.typesimportschedule
6171
fromgoogle.cloud.firestore_admin_v1.typesimportuser_creds
6272
fromgoogle.cloud.firestore_admin_v1.typesimportuser_credsasgfa_user_creds
63-
fromgoogle.cloud.locationimportlocations_pb2# type: ignore
64-
fromgoogle.longrunningimportoperations_pb2# type: ignore
65-
fromgoogle.protobufimportduration_pb2# type: ignore
66-
fromgoogle.protobufimportempty_pb2# type: ignore
67-
fromgoogle.protobufimportfield_mask_pb2# type: ignore
68-
fromgoogle.protobufimporttimestamp_pb2# type: ignore
69-
from .transports.baseimportFirestoreAdminTransport, DEFAULT_CLIENT_INFO
70-
from .transports.grpc_asyncioimportFirestoreAdminGrpcAsyncIOTransport
73+
7174
from .clientimportFirestoreAdminClient
75+
from .transports.baseimportDEFAULT_CLIENT_INFO, FirestoreAdminTransport
76+
from .transports.grpc_asyncioimportFirestoreAdminGrpcAsyncIOTransport
7277

7378
try:
7479
fromgoogle.api_coreimportclient_logging# type: ignore

‎google/cloud/firestore_admin_v1/services/firestore_admin/client.py‎

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,19 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
17+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18+
# The source of truth for this file is `.librarian/generator-input`
19+
1620
fromcollectionsimportOrderedDict
1721
fromhttpimportHTTPStatus
1822
importjson
1923
importloggingasstd_logging
2024
importos
2125
importre
2226
fromtypingimport (
23-
Dict,
2427
Callable,
28+
Dict,
2529
Mapping,
2630
MutableMapping,
2731
MutableSequence,
@@ -34,19 +38,19 @@
3438
)
3539
importwarnings
3640

37-
fromgoogle.cloud.firestore_admin_v1importgapic_versionaspackage_version
38-
3941
fromgoogle.api_coreimportclient_optionsasclient_options_lib
4042
fromgoogle.api_coreimportexceptionsascore_exceptions
4143
fromgoogle.api_coreimportgapic_v1
4244
fromgoogle.api_coreimportretryasretries
4345
fromgoogle.authimportcredentialsasga_credentials# type: ignore
46+
fromgoogle.auth.exceptionsimportMutualTLSChannelError# type: ignore
4447
fromgoogle.auth.transportimportmtls# type: ignore
4548
fromgoogle.auth.transport.grpcimportSslCredentials# type: ignore
46-
fromgoogle.auth.exceptionsimportMutualTLSChannelError# type: ignore
4749
fromgoogle.oauth2importservice_account# type: ignore
4850
importgoogle.protobuf
4951

52+
fromgoogle.cloud.firestore_admin_v1importgapic_versionaspackage_version
53+
5054
try:
5155
OptionalRetry=Union[retries.Retry, gapic_v1.method._MethodDefault, None]
5256
exceptAttributeError: # pragma: NO COVER
@@ -63,6 +67,13 @@
6367

6468
fromgoogle.api_coreimportoperationasgac_operation# type: ignore
6569
fromgoogle.api_coreimportoperation_async# type: ignore
70+
fromgoogle.cloud.locationimportlocations_pb2# type: ignore
71+
fromgoogle.longrunningimportoperations_pb2# type: ignore
72+
fromgoogle.protobufimportduration_pb2# type: ignore
73+
fromgoogle.protobufimportempty_pb2# type: ignore
74+
fromgoogle.protobufimportfield_mask_pb2# type: ignore
75+
fromgoogle.protobufimporttimestamp_pb2# type: ignore
76+
6677
fromgoogle.cloud.firestore_admin_v1.services.firestore_adminimportpagers
6778
fromgoogle.cloud.firestore_admin_v1.typesimportbackup
6879
fromgoogle.cloud.firestore_admin_v1.typesimportdatabase
@@ -76,13 +87,8 @@
7687
fromgoogle.cloud.firestore_admin_v1.typesimportschedule
7788
fromgoogle.cloud.firestore_admin_v1.typesimportuser_creds
7889
fromgoogle.cloud.firestore_admin_v1.typesimportuser_credsasgfa_user_creds
79-
fromgoogle.cloud.locationimportlocations_pb2# type: ignore
80-
fromgoogle.longrunningimportoperations_pb2# type: ignore
81-
fromgoogle.protobufimportduration_pb2# type: ignore
82-
fromgoogle.protobufimportempty_pb2# type: ignore
83-
fromgoogle.protobufimportfield_mask_pb2# type: ignore
84-
fromgoogle.protobufimporttimestamp_pb2# type: ignore
85-
from .transports.baseimportFirestoreAdminTransport, DEFAULT_CLIENT_INFO
90+
91+
from .transports.baseimportDEFAULT_CLIENT_INFO, FirestoreAdminTransport
8692
from .transports.grpcimportFirestoreAdminGrpcTransport
8793
from .transports.grpc_asyncioimportFirestoreAdminGrpcAsyncIOTransport
8894
from .transports.restimportFirestoreAdminRestTransport
@@ -198,6 +204,34 @@ def _get_default_mtls_endpoint(api_endpoint):
198204
_DEFAULT_ENDPOINT_TEMPLATE="firestore.{UNIVERSE_DOMAIN}"
199205
_DEFAULT_UNIVERSE="googleapis.com"
200206

207+
@staticmethod
208+
def_use_client_cert_effective():
209+
"""Returns whether client certificate should be used for mTLS if the
210+
google-auth version supports should_use_client_cert automatic mTLS enablement.
211+
212+
Alternatively, read from the GOOGLE_API_USE_CLIENT_CERTIFICATE env var.
213+
214+
Returns:
215+
bool: whether client certificate should be used for mTLS
216+
Raises:
217+
ValueError: (If using a version of google-auth without should_use_client_cert and
218+
GOOGLE_API_USE_CLIENT_CERTIFICATE is set to an unexpected value.)
219+
"""
220+
# check if google-auth version supports should_use_client_cert for automatic mTLS enablement
221+
ifhasattr(mtls, "should_use_client_cert"): # pragma: NO COVER
222+
returnmtls.should_use_client_cert()
223+
else: # pragma: NO COVER
224+
# if unsupported, fallback to reading from env var
225+
use_client_cert_str=os.getenv(
226+
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
227+
).lower()
228+
ifuse_client_cert_strnotin ("true", "false"):
229+
raiseValueError(
230+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be"
231+
" either `true` or `false`"
232+
)
233+
returnuse_client_cert_str=="true"
234+
201235
@classmethod
202236
deffrom_service_account_info(cls, info: dict, *args, **kwargs):
203237
"""Creates an instance of this client using the provided credentials
@@ -555,20 +589,16 @@ def get_mtls_endpoint_and_cert_source(
555589
)
556590
ifclient_optionsisNone:
557591
client_options=client_options_lib.ClientOptions()
558-
use_client_cert=os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
592+
use_client_cert=FirestoreAdminClient._use_client_cert_effective()
559593
use_mtls_endpoint=os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
560-
ifuse_client_certnotin ("true", "false"):
561-
raiseValueError(
562-
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
563-
)
564594
ifuse_mtls_endpointnotin ("auto", "never", "always"):
565595
raiseMutualTLSChannelError(
566596
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
567597
)
568598

569599
# Figure out the client cert source to use.
570600
client_cert_source=None
571-
ifuse_client_cert=="true":
601+
ifuse_client_cert:
572602
ifclient_options.client_cert_source:
573603
client_cert_source=client_options.client_cert_source
574604
elifmtls.has_default_client_cert_source():
@@ -600,20 +630,14 @@ def _read_environment_variables():
600630
google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
601631
is not any of ["auto", "never", "always"].
602632
"""
603-
use_client_cert=os.getenv(
604-
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
605-
).lower()
633+
use_client_cert=FirestoreAdminClient._use_client_cert_effective()
606634
use_mtls_endpoint=os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
607635
universe_domain_env=os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
608-
ifuse_client_certnotin ("true", "false"):
609-
raiseValueError(
610-
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
611-
)
612636
ifuse_mtls_endpointnotin ("auto", "never", "always"):
613637
raiseMutualTLSChannelError(
614638
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
615639
)
616-
returnuse_client_cert=="true", use_mtls_endpoint, universe_domain_env
640+
returnuse_client_cert, use_mtls_endpoint, universe_domain_env
617641

618642
@staticmethod
619643
def_get_client_cert_source(provided_cert_source, use_cert_flag):

‎google/cloud/firestore_admin_v1/services/firestore_admin/pagers.py‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,26 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16-
fromgoogle.api_coreimportgapic_v1
17-
fromgoogle.api_coreimportretryasretries
18-
fromgoogle.api_coreimportretry_asyncasretries_async
16+
17+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18+
# The source of truth for this file is `.librarian/generator-input`
19+
1920
fromtypingimport (
2021
Any,
2122
AsyncIterator,
2223
Awaitable,
2324
Callable,
25+
Iterator,
26+
Optional,
2427
Sequence,
2528
Tuple,
26-
Optional,
27-
Iterator,
2829
Union,
2930
)
3031

32+
fromgoogle.api_coreimportgapic_v1
33+
fromgoogle.api_coreimportretryasretries
34+
fromgoogle.api_coreimportretry_asyncasretries_async
35+
3136
try:
3237
OptionalRetry=Union[retries.Retry, gapic_v1.method._MethodDefault, None]
3338
OptionalAsyncRetry=Union[
@@ -37,9 +42,7 @@
3742
OptionalRetry=Union[retries.Retry, object, None] # type: ignore
3843
OptionalAsyncRetry=Union[retries_async.AsyncRetry, object, None] # type: ignore
3944

40-
fromgoogle.cloud.firestore_admin_v1.typesimportfield
41-
fromgoogle.cloud.firestore_admin_v1.typesimportfirestore_admin
42-
fromgoogle.cloud.firestore_admin_v1.typesimportindex
45+
fromgoogle.cloud.firestore_admin_v1.typesimportfield, firestore_admin, index
4346

4447

4548
classListIndexesPager:

‎google/cloud/firestore_admin_v1/services/firestore_admin/transports/README.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
2+
# The source of truth for this file is `.librarian/generator-input`
3+
14

25
transport inheritance structure
36
_______________________________

‎google/cloud/firestore_admin_v1/services/firestore_admin/transports/__init__.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
17+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18+
# The source of truth for this file is `.librarian/generator-input`
19+
1620
fromcollectionsimportOrderedDict
1721
fromtypingimportDict, Type
1822

1923
from .baseimportFirestoreAdminTransport
2024
from .grpcimportFirestoreAdminGrpcTransport
2125
from .grpc_asyncioimportFirestoreAdminGrpcAsyncIOTransport
22-
from .restimportFirestoreAdminRestTransport
23-
from .restimportFirestoreAdminRestInterceptor
24-
26+
from .restimportFirestoreAdminRestInterceptor, FirestoreAdminRestTransport
2527

2628
# Compile a registry of transports.
2729
_transport_registry=OrderedDict() # type: Dict[str, Type[FirestoreAdminTransport]]

‎google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,36 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
17+
# DO NOT EDIT THIS FILE OUTSIDE OF `.librarian/generator-input`
18+
# The source of truth for this file is `.librarian/generator-input`
19+
1620
importabc
1721
fromtypingimportAwaitable, Callable, Dict, Optional, Sequence, Union
1822

19-
fromgoogle.cloud.firestore_admin_v1importgapic_versionaspackage_version
20-
21-
importgoogle.auth# type: ignore
2223
importgoogle.api_core
2324
fromgoogle.api_coreimportexceptionsascore_exceptions
24-
fromgoogle.api_coreimportgapic_v1
25+
fromgoogle.api_coreimportgapic_v1, operations_v1
2526
fromgoogle.api_coreimportretryasretries
26-
fromgoogle.api_coreimportoperations_v1
27+
importgoogle.auth# type: ignore
2728
fromgoogle.authimportcredentialsasga_credentials# type: ignore
29+
fromgoogle.cloud.locationimportlocations_pb2# type: ignore
30+
fromgoogle.longrunningimportoperations_pb2# type: ignore
2831
fromgoogle.oauth2importservice_account# type: ignore
2932
importgoogle.protobuf
33+
fromgoogle.protobufimportempty_pb2# type: ignore
3034

31-
fromgoogle.cloud.firestore_admin_v1.typesimportbackup
32-
fromgoogle.cloud.firestore_admin_v1.typesimportdatabase
33-
fromgoogle.cloud.firestore_admin_v1.typesimportfield
34-
fromgoogle.cloud.firestore_admin_v1.typesimportfirestore_admin
35-
fromgoogle.cloud.firestore_admin_v1.typesimportindex
36-
fromgoogle.cloud.firestore_admin_v1.typesimportschedule
35+
fromgoogle.cloud.firestore_admin_v1importgapic_versionaspackage_version
36+
fromgoogle.cloud.firestore_admin_v1.typesimport (
37+
backup,
38+
database,
39+
field,
40+
firestore_admin,
41+
index,
42+
schedule,
43+
)
3744
fromgoogle.cloud.firestore_admin_v1.typesimportuser_creds
3845
fromgoogle.cloud.firestore_admin_v1.typesimportuser_credsasgfa_user_creds
39-
fromgoogle.cloud.locationimportlocations_pb2# type: ignore
40-
fromgoogle.longrunningimportoperations_pb2# type: ignore
41-
fromgoogle.protobufimportempty_pb2# type: ignore
4246

4347
DEFAULT_CLIENT_INFO=gapic_v1.client_info.ClientInfo(
4448
gapic_version=package_version.__version__

0 commit comments

Comments
 (0)