py2docfx 0.1.22.dev2258230__py3-none-any.whl → 0.1.22.dev2270449__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- py2docfx/docfx_yaml/process_doctree.py +3 -23
- py2docfx/docfx_yaml/translator.py +6 -35
- py2docfx/docfx_yaml/type_mapping.py +102 -0
- py2docfx/venv/basevenv/Lib/site-packages/certifi/__init__.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/default.py +8 -9
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/imds.py +7 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/managed_identity.py +7 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_credentials/shared_cache.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/interactive.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_internal/msal_managed_identity_client.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/_version.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/default.py +8 -9
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/imds.py +7 -3
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/managed_identity.py +7 -1
- py2docfx/venv/venv1/Lib/site-packages/azure/identity/aio/_credentials/shared_cache.py +2 -2
- py2docfx/venv/venv1/Lib/site-packages/cachetools/__init__.py +96 -122
- py2docfx/venv/venv1/Lib/site-packages/cachetools/{_decorators.py → _cached.py} +106 -13
- py2docfx/venv/venv1/Lib/site-packages/cachetools/_cachedmethod.py +128 -0
- py2docfx/venv/venv1/Lib/site-packages/cachetools/func.py +5 -25
- py2docfx/venv/venv1/Lib/site-packages/certifi/__init__.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/cryptography/__about__.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/client_options.py +9 -2
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/general_helpers.py +36 -0
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/grpc_helpers.py +10 -7
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/grpc_helpers_async.py +8 -3
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/operations_v1/transports/base.py +13 -7
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/operations_v1/transports/rest.py +19 -12
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/operations_v1/transports/rest_asyncio.py +21 -0
- py2docfx/venv/venv1/Lib/site-packages/google/api_core/version.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/google/auth/_default.py +66 -12
- py2docfx/venv/venv1/Lib/site-packages/google/auth/_default_async.py +16 -10
- py2docfx/venv/venv1/Lib/site-packages/google/auth/_helpers.py +41 -0
- py2docfx/venv/venv1/Lib/site-packages/google/auth/compute_engine/credentials.py +67 -6
- py2docfx/venv/venv1/Lib/site-packages/google/auth/credentials.py +161 -18
- py2docfx/venv/venv1/Lib/site-packages/google/auth/environment_vars.py +4 -0
- py2docfx/venv/venv1/Lib/site-packages/google/auth/external_account.py +33 -10
- py2docfx/venv/venv1/Lib/site-packages/google/auth/external_account_authorized_user.py +24 -1
- py2docfx/venv/venv1/Lib/site-packages/google/auth/identity_pool.py +25 -1
- py2docfx/venv/venv1/Lib/site-packages/google/auth/impersonated_credentials.py +57 -9
- py2docfx/venv/venv1/Lib/site-packages/google/auth/pluggable.py +25 -1
- py2docfx/venv/venv1/Lib/site-packages/google/auth/version.py +1 -1
- py2docfx/venv/venv1/Lib/site-packages/google/oauth2/_client.py +117 -0
- py2docfx/venv/venv1/Lib/site-packages/google/oauth2/service_account.py +39 -4
- {py2docfx-0.1.22.dev2258230.dist-info → py2docfx-0.1.22.dev2270449.dist-info}/METADATA +1 -1
- {py2docfx-0.1.22.dev2258230.dist-info → py2docfx-0.1.22.dev2270449.dist-info}/RECORD +47 -45
- {py2docfx-0.1.22.dev2258230.dist-info → py2docfx-0.1.22.dev2270449.dist-info}/WHEEL +0 -0
- {py2docfx-0.1.22.dev2258230.dist-info → py2docfx-0.1.22.dev2270449.dist-info}/top_level.txt +0 -0
@@ -49,6 +49,9 @@ You can also pass a mapping object.
|
|
49
49
|
"""
|
50
50
|
|
51
51
|
from typing import Callable, Mapping, Optional, Sequence, Tuple
|
52
|
+
import warnings
|
53
|
+
|
54
|
+
from google.api_core import general_helpers
|
52
55
|
|
53
56
|
|
54
57
|
class ClientOptions(object):
|
@@ -67,8 +70,9 @@ class ClientOptions(object):
|
|
67
70
|
and ``client_encrypted_cert_source`` are mutually exclusive.
|
68
71
|
quota_project_id (Optional[str]): A project name that a client's
|
69
72
|
quota belongs to.
|
70
|
-
credentials_file (Optional[str]): A path to a file storing credentials.
|
71
|
-
``credentials_file` and ``api_key`` are mutually exclusive.
|
73
|
+
credentials_file (Optional[str]): Deprecated. A path to a file storing credentials.
|
74
|
+
``credentials_file` and ``api_key`` are mutually exclusive. This argument will be
|
75
|
+
removed in the next major version of `google-api-core`.
|
72
76
|
|
73
77
|
.. warning::
|
74
78
|
Important: If you accept a credential configuration (credential JSON/File/Stream)
|
@@ -114,6 +118,9 @@ class ClientOptions(object):
|
|
114
118
|
api_audience: Optional[str] = None,
|
115
119
|
universe_domain: Optional[str] = None,
|
116
120
|
):
|
121
|
+
if credentials_file is not None:
|
122
|
+
warnings.warn(general_helpers._CREDENTIALS_FILE_WARNING, DeprecationWarning)
|
123
|
+
|
117
124
|
if client_cert_source and client_encrypted_cert_source:
|
118
125
|
raise ValueError(
|
119
126
|
"client_cert_source and client_encrypted_cert_source are mutually exclusive"
|
@@ -14,3 +14,39 @@
|
|
14
14
|
|
15
15
|
# This import for backward compatibility only.
|
16
16
|
from functools import wraps # noqa: F401 pragma: NO COVER
|
17
|
+
|
18
|
+
_CREDENTIALS_FILE_WARNING = """\
|
19
|
+
The `credentials_file` argument is deprecated because of a potential security risk.
|
20
|
+
|
21
|
+
The `google.auth.load_credentials_from_file` method does not validate the credential
|
22
|
+
configuration. The security risk occurs when a credential configuration is accepted
|
23
|
+
from a source that is not under your control and used without validation on your side.
|
24
|
+
|
25
|
+
If you know that you will be loading credential configurations of a
|
26
|
+
specific type, it is recommended to use a credential-type-specific
|
27
|
+
load method.
|
28
|
+
|
29
|
+
This will ensure that an unexpected credential type with potential for
|
30
|
+
malicious intent is not loaded unintentionally. You might still have to do
|
31
|
+
validation for certain credential types. Please follow the recommendations
|
32
|
+
for that method. For example, if you want to load only service accounts,
|
33
|
+
you can create the service account credentials explicitly:
|
34
|
+
|
35
|
+
```
|
36
|
+
from google.cloud.vision_v1 import ImageAnnotatorClient
|
37
|
+
from google.oauth2 import service_account
|
38
|
+
|
39
|
+
credentials = service_account.Credentials.from_service_account_file(filename)
|
40
|
+
client = ImageAnnotatorClient(credentials=credentials)
|
41
|
+
```
|
42
|
+
|
43
|
+
If you are loading your credential configuration from an untrusted source and have
|
44
|
+
not mitigated the risks (e.g. by validating the configuration yourself), make
|
45
|
+
these changes as soon as possible to prevent security risks to your environment.
|
46
|
+
|
47
|
+
Regardless of the method used, it is always your responsibility to validate
|
48
|
+
configurations received from external sources.
|
49
|
+
|
50
|
+
Refer to https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
|
51
|
+
for more details.
|
52
|
+
"""
|
@@ -13,20 +13,19 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
"""Helpers for :mod:`grpc`."""
|
16
|
-
from typing import Generic, Iterator, Optional, TypeVar
|
17
|
-
|
18
16
|
import collections
|
19
17
|
import functools
|
18
|
+
from typing import Generic, Iterator, Optional, TypeVar
|
20
19
|
import warnings
|
21
20
|
|
22
|
-
import grpc
|
23
|
-
|
24
|
-
from google.api_core import exceptions
|
25
21
|
import google.auth
|
26
22
|
import google.auth.credentials
|
27
23
|
import google.auth.transport.grpc
|
28
24
|
import google.auth.transport.requests
|
29
25
|
import google.protobuf
|
26
|
+
import grpc
|
27
|
+
|
28
|
+
from google.api_core import exceptions, general_helpers
|
30
29
|
|
31
30
|
PROTOBUF_VERSION = google.protobuf.__version__
|
32
31
|
|
@@ -213,9 +212,10 @@ def _create_composite_credentials(
|
|
213
212
|
credentials (google.auth.credentials.Credentials): The credentials. If
|
214
213
|
not specified, then this function will attempt to ascertain the
|
215
214
|
credentials from the environment using :func:`google.auth.default`.
|
216
|
-
credentials_file (str): A file with credentials that can be loaded with
|
215
|
+
credentials_file (str): Deprecated. A file with credentials that can be loaded with
|
217
216
|
:func:`google.auth.load_credentials_from_file`. This argument is
|
218
|
-
mutually exclusive with credentials.
|
217
|
+
mutually exclusive with credentials. This argument will be
|
218
|
+
removed in the next major version of `google-api-core`.
|
219
219
|
|
220
220
|
.. warning::
|
221
221
|
Important: If you accept a credential configuration (credential JSON/File/Stream)
|
@@ -245,6 +245,9 @@ def _create_composite_credentials(
|
|
245
245
|
Raises:
|
246
246
|
google.api_core.DuplicateCredentialArgs: If both a credentials object and credentials_file are passed.
|
247
247
|
"""
|
248
|
+
if credentials_file is not None:
|
249
|
+
warnings.warn(general_helpers._CREDENTIALS_FILE_WARNING, DeprecationWarning)
|
250
|
+
|
248
251
|
if credentials and credentials_file:
|
249
252
|
raise exceptions.DuplicateCredentialArgs(
|
250
253
|
"'credentials' and 'credentials_file' are mutually exclusive."
|
@@ -20,13 +20,14 @@ functions. This module is implementing the same surface with AsyncIO semantics.
|
|
20
20
|
|
21
21
|
import asyncio
|
22
22
|
import functools
|
23
|
+
import warnings
|
23
24
|
|
24
25
|
from typing import AsyncGenerator, Generic, Iterator, Optional, TypeVar
|
25
26
|
|
26
27
|
import grpc
|
27
28
|
from grpc import aio
|
28
29
|
|
29
|
-
from google.api_core import exceptions, grpc_helpers
|
30
|
+
from google.api_core import exceptions, general_helpers, grpc_helpers
|
30
31
|
|
31
32
|
# denotes the proto response type for grpc calls
|
32
33
|
P = TypeVar("P")
|
@@ -233,9 +234,10 @@ def create_channel(
|
|
233
234
|
are passed to :func:`google.auth.default`.
|
234
235
|
ssl_credentials (grpc.ChannelCredentials): Optional SSL channel
|
235
236
|
credentials. This can be used to specify different certificates.
|
236
|
-
credentials_file (str): A file with credentials that can be loaded with
|
237
|
+
credentials_file (str): Deprecated. A file with credentials that can be loaded with
|
237
238
|
:func:`google.auth.load_credentials_from_file`. This argument is
|
238
|
-
mutually exclusive with credentials.
|
239
|
+
mutually exclusive with credentials. This argument will be
|
240
|
+
removed in the next major version of `google-api-core`.
|
239
241
|
|
240
242
|
.. warning::
|
241
243
|
Important: If you accept a credential configuration (credential JSON/File/Stream)
|
@@ -280,6 +282,9 @@ def create_channel(
|
|
280
282
|
ValueError: If `ssl_credentials` is set and `attempt_direct_path` is set to `True`.
|
281
283
|
"""
|
282
284
|
|
285
|
+
if credentials_file is not None:
|
286
|
+
warnings.warn(general_helpers._CREDENTIALS_FILE_WARNING, DeprecationWarning)
|
287
|
+
|
283
288
|
# If `ssl_credentials` is set and `attempt_direct_path` is set to `True`,
|
284
289
|
# raise ValueError as this is not yet supported.
|
285
290
|
# See https://github.com/googleapis/python-api-core/issues/590
|
@@ -16,12 +16,8 @@
|
|
16
16
|
import abc
|
17
17
|
import re
|
18
18
|
from typing import Awaitable, Callable, Optional, Sequence, Union
|
19
|
+
import warnings
|
19
20
|
|
20
|
-
import google.api_core # type: ignore
|
21
|
-
from google.api_core import exceptions as core_exceptions # type: ignore
|
22
|
-
from google.api_core import gapic_v1 # type: ignore
|
23
|
-
from google.api_core import retry as retries # type: ignore
|
24
|
-
from google.api_core import version
|
25
21
|
import google.auth # type: ignore
|
26
22
|
from google.auth import credentials as ga_credentials # type: ignore
|
27
23
|
from google.longrunning import operations_pb2
|
@@ -30,6 +26,12 @@ import google.protobuf
|
|
30
26
|
from google.protobuf import empty_pb2, json_format # type: ignore
|
31
27
|
from grpc import Compression
|
32
28
|
|
29
|
+
import google.api_core # type: ignore
|
30
|
+
from google.api_core import exceptions as core_exceptions # type: ignore
|
31
|
+
from google.api_core import gapic_v1 # type: ignore
|
32
|
+
from google.api_core import general_helpers
|
33
|
+
from google.api_core import retry as retries # type: ignore
|
34
|
+
from google.api_core import version
|
33
35
|
|
34
36
|
PROTOBUF_VERSION = google.protobuf.__version__
|
35
37
|
|
@@ -69,9 +71,10 @@ class OperationsTransport(abc.ABC):
|
|
69
71
|
credentials identify the application to the service; if none
|
70
72
|
are specified, the client will attempt to ascertain the
|
71
73
|
credentials from the environment.
|
72
|
-
credentials_file (Optional[str]): A file with credentials that can
|
74
|
+
credentials_file (Optional[str]): Deprecated. A file with credentials that can
|
73
75
|
be loaded with :func:`google.auth.load_credentials_from_file`.
|
74
|
-
This argument is mutually exclusive with credentials.
|
76
|
+
This argument is mutually exclusive with credentials. This argument will be
|
77
|
+
removed in the next major version of `google-api-core`.
|
75
78
|
|
76
79
|
.. warning::
|
77
80
|
Important: If you accept a credential configuration (credential JSON/File/Stream)
|
@@ -98,6 +101,9 @@ class OperationsTransport(abc.ABC):
|
|
98
101
|
"https", but for testing or local servers,
|
99
102
|
"http" can be specified.
|
100
103
|
"""
|
104
|
+
if credentials_file is not None:
|
105
|
+
warnings.warn(general_helpers._CREDENTIALS_FILE_WARNING, DeprecationWarning)
|
106
|
+
|
101
107
|
maybe_url_match = re.match("^(?P<scheme>http(?:s)?://)?(?P<host>.*)$", host)
|
102
108
|
if maybe_url_match is None:
|
103
109
|
raise ValueError(
|
@@ -15,23 +15,26 @@
|
|
15
15
|
#
|
16
16
|
|
17
17
|
from typing import Callable, Dict, Optional, Sequence, Tuple, Union
|
18
|
+
import warnings
|
18
19
|
|
20
|
+
from google.auth import credentials as ga_credentials # type: ignore
|
21
|
+
from google.auth.transport.requests import AuthorizedSession # type: ignore
|
22
|
+
from google.longrunning import operations_pb2 # type: ignore
|
23
|
+
import google.protobuf
|
24
|
+
from google.protobuf import empty_pb2 # type: ignore
|
25
|
+
from google.protobuf import json_format # type: ignore
|
26
|
+
import grpc
|
19
27
|
from requests import __version__ as requests_version
|
20
28
|
|
21
29
|
from google.api_core import exceptions as core_exceptions # type: ignore
|
22
30
|
from google.api_core import gapic_v1 # type: ignore
|
31
|
+
from google.api_core import general_helpers
|
23
32
|
from google.api_core import path_template # type: ignore
|
24
33
|
from google.api_core import rest_helpers # type: ignore
|
25
34
|
from google.api_core import retry as retries # type: ignore
|
26
|
-
from google.auth import credentials as ga_credentials # type: ignore
|
27
|
-
from google.auth.transport.requests import AuthorizedSession # type: ignore
|
28
|
-
from google.longrunning import operations_pb2 # type: ignore
|
29
|
-
from google.protobuf import empty_pb2 # type: ignore
|
30
|
-
from google.protobuf import json_format # type: ignore
|
31
|
-
import google.protobuf
|
32
35
|
|
33
|
-
import
|
34
|
-
from .base import
|
36
|
+
from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
|
37
|
+
from .base import OperationsTransport
|
35
38
|
|
36
39
|
PROTOBUF_VERSION = google.protobuf.__version__
|
37
40
|
|
@@ -91,9 +94,10 @@ class OperationsRestTransport(OperationsTransport):
|
|
91
94
|
are specified, the client will attempt to ascertain the
|
92
95
|
credentials from the environment.
|
93
96
|
|
94
|
-
credentials_file (Optional[str]): A file with credentials that can
|
97
|
+
credentials_file (Optional[str]): Deprecated. A file with credentials that can
|
95
98
|
be loaded with :func:`google.auth.load_credentials_from_file`.
|
96
|
-
This argument is ignored if ``channel`` is provided.
|
99
|
+
This argument is ignored if ``channel`` is provided. This argument will be
|
100
|
+
removed in the next major version of `google-api-core`.
|
97
101
|
|
98
102
|
.. warning::
|
99
103
|
Important: If you accept a credential configuration (credential JSON/File/Stream)
|
@@ -101,9 +105,9 @@ class OperationsRestTransport(OperationsTransport):
|
|
101
105
|
validate it before providing it to any Google API or client library. Providing an
|
102
106
|
unvalidated credential configuration to Google APIs or libraries can compromise
|
103
107
|
the security of your systems and data. For more information, refer to
|
104
|
-
`Validate credential
|
108
|
+
`Validate credential configuration from external sources`_.
|
105
109
|
|
106
|
-
.. _Validate credential
|
110
|
+
.. _Validate credential configuration from external sources:
|
107
111
|
|
108
112
|
https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
|
109
113
|
scopes (Optional(Sequence[str])): A list of scopes. This argument is
|
@@ -130,6 +134,9 @@ class OperationsRestTransport(OperationsTransport):
|
|
130
134
|
"v1" by default.
|
131
135
|
|
132
136
|
"""
|
137
|
+
if credentials_file is not None:
|
138
|
+
warnings.warn(general_helpers._CREDENTIALS_FILE_WARNING, DeprecationWarning)
|
139
|
+
|
133
140
|
# Run the base constructor
|
134
141
|
# TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
|
135
142
|
# TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
|
py2docfx/venv/venv1/Lib/site-packages/google/api_core/operations_v1/transports/rest_asyncio.py
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
import json
|
18
18
|
from typing import Any, Callable, Coroutine, Dict, Optional, Sequence, Tuple
|
19
|
+
import warnings
|
19
20
|
|
20
21
|
from google.auth import __version__ as auth_version
|
21
22
|
|
@@ -29,6 +30,7 @@ except ImportError as e: # pragma: NO COVER
|
|
29
30
|
|
30
31
|
from google.api_core import exceptions as core_exceptions # type: ignore
|
31
32
|
from google.api_core import gapic_v1 # type: ignore
|
33
|
+
from google.api_core import general_helpers
|
32
34
|
from google.api_core import path_template # type: ignore
|
33
35
|
from google.api_core import rest_helpers # type: ignore
|
34
36
|
from google.api_core import retry_async as retries_async # type: ignore
|
@@ -96,6 +98,22 @@ class AsyncOperationsRestTransport(OperationsTransport):
|
|
96
98
|
credentials identify the application to the service; if none
|
97
99
|
are specified, the client will attempt to ascertain the
|
98
100
|
credentials from the environment.
|
101
|
+
credentials_file (Optional[str]): Deprecated. A file with credentials that can
|
102
|
+
be loaded with :func:`google.auth.load_credentials_from_file`.
|
103
|
+
This argument is ignored if ``channel`` is provided. This argument will be
|
104
|
+
removed in the next major version of `google-api-core`.
|
105
|
+
|
106
|
+
.. warning::
|
107
|
+
Important: If you accept a credential configuration (credential JSON/File/Stream)
|
108
|
+
from an external source for authentication to Google Cloud Platform, you must
|
109
|
+
validate it before providing it to any Google API or client library. Providing an
|
110
|
+
unvalidated credential configuration to Google APIs or libraries can compromise
|
111
|
+
the security of your systems and data. For more information, refer to
|
112
|
+
`Validate credential configurations from external sources`_.
|
113
|
+
|
114
|
+
.. _Validate credential configurations from external sources:
|
115
|
+
|
116
|
+
https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
|
99
117
|
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
100
118
|
The client info used to send a user-agent string along with
|
101
119
|
API requests. If ``None``, then default info will be used.
|
@@ -113,6 +131,9 @@ class AsyncOperationsRestTransport(OperationsTransport):
|
|
113
131
|
"v1" by default.
|
114
132
|
|
115
133
|
"""
|
134
|
+
if credentials_file is not None:
|
135
|
+
warnings.warn(general_helpers._CREDENTIALS_FILE_WARNING, DeprecationWarning)
|
136
|
+
|
116
137
|
unsupported_params = {
|
117
138
|
# TODO(https://github.com/googleapis/python-api-core/issues/715): Add support for `credentials_file` to async REST transport.
|
118
139
|
"google.api_core.client_options.ClientOptions.credentials_file": credentials_file,
|
@@ -59,6 +59,38 @@ or "API not enabled" error. See the following page for troubleshooting: \
|
|
59
59
|
https://cloud.google.com/docs/authentication/adc-troubleshooting/user-creds. \
|
60
60
|
"""
|
61
61
|
|
62
|
+
_GENERIC_LOAD_METHOD_WARNING = """\
|
63
|
+
The {} method is deprecated because of a potential security risk.
|
64
|
+
|
65
|
+
This method does not validate the credential configuration. The security
|
66
|
+
risk occurs when a credential configuration is accepted from a source that
|
67
|
+
is not under your control and used without validation on your side.
|
68
|
+
|
69
|
+
If you know that you will be loading credential configurations of a
|
70
|
+
specific type, it is recommended to use a credential-type-specific
|
71
|
+
load method.
|
72
|
+
This will ensure that an unexpected credential type with potential for
|
73
|
+
malicious intent is not loaded unintentionally. You might still have to do
|
74
|
+
validation for certain credential types. Please follow the recommendations
|
75
|
+
for that method. For example, if you want to load only service accounts,
|
76
|
+
you can create the service account credentials explicitly:
|
77
|
+
|
78
|
+
```
|
79
|
+
from google.oauth2 import service_account
|
80
|
+
creds = service_account.Credentials.from_service_account_file(filename)
|
81
|
+
```
|
82
|
+
|
83
|
+
If you are loading your credential configuration from an untrusted source and have
|
84
|
+
not mitigated the risks (e.g. by validating the configuration yourself), make
|
85
|
+
these changes as soon as possible to prevent security risks to your environment.
|
86
|
+
|
87
|
+
Regardless of the method used, it is always your responsibility to validate
|
88
|
+
configurations received from external sources.
|
89
|
+
|
90
|
+
Refer to https://cloud.google.com/docs/authentication/external/externally-sourced-credentials
|
91
|
+
for more details.
|
92
|
+
"""
|
93
|
+
|
62
94
|
# The subject token type used for AWS external_account credentials.
|
63
95
|
_AWS_SUBJECT_TOKEN_TYPE = "urn:ietf:params:aws:token-type:aws4_request"
|
64
96
|
|
@@ -76,6 +108,20 @@ def _warn_about_problematic_credentials(credentials):
|
|
76
108
|
warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
|
77
109
|
|
78
110
|
|
111
|
+
def _warn_about_generic_load_method(method_name): # pragma: NO COVER
|
112
|
+
"""Warns that a generic load method is being used.
|
113
|
+
|
114
|
+
This is to discourage use of the generic load methods in favor of
|
115
|
+
more specific methods. The generic methods are more likely to lead to
|
116
|
+
security issues if the input is not validated.
|
117
|
+
|
118
|
+
Args:
|
119
|
+
method_name (str): The name of the method being used.
|
120
|
+
"""
|
121
|
+
|
122
|
+
warnings.warn(_GENERIC_LOAD_METHOD_WARNING.format(method_name), DeprecationWarning)
|
123
|
+
|
124
|
+
|
79
125
|
def load_credentials_from_file(
|
80
126
|
filename, scopes=None, default_scopes=None, quota_project_id=None, request=None
|
81
127
|
):
|
@@ -121,6 +167,8 @@ def load_credentials_from_file(
|
|
121
167
|
google.auth.exceptions.DefaultCredentialsError: if the file is in the
|
122
168
|
wrong format or is missing.
|
123
169
|
"""
|
170
|
+
_warn_about_generic_load_method("load_credentials_from_file")
|
171
|
+
|
124
172
|
if not os.path.exists(filename):
|
125
173
|
raise exceptions.DefaultCredentialsError(
|
126
174
|
"File {} was not found.".format(filename)
|
@@ -184,6 +232,7 @@ def load_credentials_from_dict(
|
|
184
232
|
google.auth.exceptions.DefaultCredentialsError: if the file is in the
|
185
233
|
wrong format or is missing.
|
186
234
|
"""
|
235
|
+
_warn_about_generic_load_method("load_credentials_from_dict")
|
187
236
|
if not isinstance(info, dict):
|
188
237
|
raise exceptions.DefaultCredentialsError(
|
189
238
|
"info object was of type {} but dict type was expected.".format(type(info))
|
@@ -256,15 +305,17 @@ def _get_gcloud_sdk_credentials(quota_project_id=None):
|
|
256
305
|
_LOGGER.debug("Cloud SDK credentials not found on disk; not using them")
|
257
306
|
return None, None
|
258
307
|
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
308
|
+
with warnings.catch_warnings():
|
309
|
+
warnings.simplefilter("ignore", DeprecationWarning)
|
310
|
+
credentials, project_id = load_credentials_from_file(
|
311
|
+
credentials_filename, quota_project_id=quota_project_id
|
312
|
+
)
|
313
|
+
credentials._cred_file_path = credentials_filename
|
263
314
|
|
264
|
-
|
265
|
-
|
315
|
+
if not project_id:
|
316
|
+
project_id = _cloud_sdk.get_project_id()
|
266
317
|
|
267
|
-
|
318
|
+
return credentials, project_id
|
268
319
|
|
269
320
|
|
270
321
|
def _get_explicit_environ_credentials(quota_project_id=None):
|
@@ -290,12 +341,15 @@ def _get_explicit_environ_credentials(quota_project_id=None):
|
|
290
341
|
return _get_gcloud_sdk_credentials(quota_project_id=quota_project_id)
|
291
342
|
|
292
343
|
if explicit_file is not None:
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
344
|
+
with warnings.catch_warnings():
|
345
|
+
warnings.simplefilter("ignore", DeprecationWarning)
|
346
|
+
credentials, project_id = load_credentials_from_file(
|
347
|
+
os.environ[environment_vars.CREDENTIALS],
|
348
|
+
quota_project_id=quota_project_id,
|
349
|
+
)
|
350
|
+
credentials._cred_file_path = f"{explicit_file} file via the GOOGLE_APPLICATION_CREDENTIALS environment variable"
|
297
351
|
|
298
|
-
|
352
|
+
return credentials, project_id
|
299
353
|
|
300
354
|
else:
|
301
355
|
return None, None
|
@@ -20,6 +20,7 @@ Implements application default credentials and project ID detection.
|
|
20
20
|
import io
|
21
21
|
import json
|
22
22
|
import os
|
23
|
+
import warnings
|
23
24
|
|
24
25
|
from google.auth import _default
|
25
26
|
from google.auth import environment_vars
|
@@ -116,14 +117,16 @@ def _get_gcloud_sdk_credentials(quota_project_id=None):
|
|
116
117
|
if not os.path.isfile(credentials_filename):
|
117
118
|
return None, None
|
118
119
|
|
119
|
-
|
120
|
-
|
121
|
-
|
120
|
+
with warnings.catch_warnings():
|
121
|
+
warnings.simplefilter("ignore", DeprecationWarning)
|
122
|
+
credentials, project_id = load_credentials_from_file(
|
123
|
+
credentials_filename, quota_project_id=quota_project_id
|
124
|
+
)
|
122
125
|
|
123
|
-
|
124
|
-
|
126
|
+
if not project_id:
|
127
|
+
project_id = _cloud_sdk.get_project_id()
|
125
128
|
|
126
|
-
|
129
|
+
return credentials, project_id
|
127
130
|
|
128
131
|
|
129
132
|
def _get_explicit_environ_credentials(quota_project_id=None):
|
@@ -141,11 +144,14 @@ def _get_explicit_environ_credentials(quota_project_id=None):
|
|
141
144
|
return _get_gcloud_sdk_credentials(quota_project_id=quota_project_id)
|
142
145
|
|
143
146
|
if explicit_file is not None:
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
+
with warnings.catch_warnings():
|
148
|
+
warnings.simplefilter("ignore", DeprecationWarning)
|
149
|
+
credentials, project_id = load_credentials_from_file(
|
150
|
+
os.environ[environment_vars.CREDENTIALS],
|
151
|
+
quota_project_id=quota_project_id,
|
152
|
+
)
|
147
153
|
|
148
|
-
|
154
|
+
return credentials, project_id
|
149
155
|
|
150
156
|
else:
|
151
157
|
return None, None
|
@@ -21,6 +21,7 @@ from email.message import Message
|
|
21
21
|
import hashlib
|
22
22
|
import json
|
23
23
|
import logging
|
24
|
+
import os
|
24
25
|
import sys
|
25
26
|
from typing import Any, Dict, Mapping, Optional, Union
|
26
27
|
import urllib
|
@@ -287,6 +288,46 @@ def unpadded_urlsafe_b64encode(value):
|
|
287
288
|
return base64.urlsafe_b64encode(value).rstrip(b"=")
|
288
289
|
|
289
290
|
|
291
|
+
def get_bool_from_env(variable_name, default=False):
|
292
|
+
"""Gets a boolean value from an environment variable.
|
293
|
+
|
294
|
+
The environment variable is interpreted as a boolean with the following
|
295
|
+
(case-insensitive) rules:
|
296
|
+
- "true", "1" are considered true.
|
297
|
+
- "false", "0" are considered false.
|
298
|
+
Any other values will raise an exception.
|
299
|
+
|
300
|
+
Args:
|
301
|
+
variable_name (str): The name of the environment variable.
|
302
|
+
default (bool): The default value if the environment variable is not
|
303
|
+
set.
|
304
|
+
|
305
|
+
Returns:
|
306
|
+
bool: The boolean value of the environment variable.
|
307
|
+
|
308
|
+
Raises:
|
309
|
+
google.auth.exceptions.InvalidValue: If the environment variable is
|
310
|
+
set to a value that can not be interpreted as a boolean.
|
311
|
+
"""
|
312
|
+
value = os.environ.get(variable_name)
|
313
|
+
|
314
|
+
if value is None:
|
315
|
+
return default
|
316
|
+
|
317
|
+
value = value.lower()
|
318
|
+
|
319
|
+
if value in ("true", "1"):
|
320
|
+
return True
|
321
|
+
elif value in ("false", "0"):
|
322
|
+
return False
|
323
|
+
else:
|
324
|
+
raise exceptions.InvalidValue(
|
325
|
+
'Environment variable "{}" must be one of "true", "false", "1", or "0".'.format(
|
326
|
+
variable_name
|
327
|
+
)
|
328
|
+
)
|
329
|
+
|
330
|
+
|
290
331
|
def is_python_3():
|
291
332
|
"""Check if the Python interpreter is Python 2 or 3.
|
292
333
|
|