Skip to content
This repository was archived by the owner on Oct 29, 2023. It is now read-only.

Commit fe43469

Browse files
changes without context
autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters.
1 parent 51c5a19 commit fe43469

File tree

14 files changed

+1221
-682
lines changed

14 files changed

+1221
-682
lines changed

docs/conf.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
# -- General configuration ------------------------------------------------
3030

3131
# If your documentation needs a minimal Sphinx version, state it here.
32-
needs_sphinx = "1.5.5"
32+
needs_sphinx = "1.6.3"
3333

3434
# Add any Sphinx extension module names here, as strings. They can be
3535
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
@@ -39,7 +39,6 @@
3939
"sphinx.ext.autosummary",
4040
"sphinx.ext.intersphinx",
4141
"sphinx.ext.coverage",
42-
"sphinx.ext.doctest",
4342
"sphinx.ext.napoleon",
4443
"sphinx.ext.todo",
4544
"sphinx.ext.viewcode",
@@ -339,11 +338,10 @@
339338

340339
# Example configuration for intersphinx: refer to the Python standard library.
341340
intersphinx_mapping = {
342-
"python": ("https://python.readthedocs.org/en/latest/", None),
343-
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
341+
"python": ("http://python.readthedocs.org/en/latest/", None),
342+
"google-auth": ("https://google-auth.readthedocs.io/en/stable", None),
344343
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
345-
"grpc": ("https://grpc.github.io/grpc/python/", None),
346-
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
344+
"grpc": ("https://grpc.io/grpc/python/", None),
347345
}
348346

349347

docs/iot_v1/types.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ Types for Google Cloud Iot v1 API
33

44
.. automodule:: google.cloud.iot_v1.types
55
:members:
6+
:show-inheritance:

google/cloud/iot_v1/services/device_manager/async_client.py

Lines changed: 104 additions & 62 deletions
Large diffs are not rendered by default.

google/cloud/iot_v1/services/device_manager/client.py

Lines changed: 132 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
#
1717

1818
from collections import OrderedDict
19+
from distutils import util
1920
import os
2021
import re
21-
from typing import Callable, Dict, Sequence, Tuple, Type, Union
22+
from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union
2223
import pkg_resources
2324

24-
import google.api_core.client_options as ClientOptions # type: ignore
25+
from google.api_core import client_options as client_options_lib # type: ignore
2526
from google.api_core import exceptions # type: ignore
2627
from google.api_core import gapic_v1 # type: ignore
2728
from google.api_core import retry as retries # type: ignore
2829
from google.auth import credentials # type: ignore
2930
from google.auth.transport import mtls # type: ignore
31+
from google.auth.transport.grpc import SslCredentials # type: ignore
3032
from google.auth.exceptions import MutualTLSChannelError # type: ignore
3133
from google.oauth2 import service_account # type: ignore
3234

@@ -134,6 +136,15 @@ def from_service_account_file(cls, filename: str, *args, **kwargs):
134136

135137
from_service_account_json = from_service_account_file
136138

139+
@property
140+
def transport(self) -> DeviceManagerTransport:
141+
"""Return the transport used by the client instance.
142+
143+
Returns:
144+
DeviceManagerTransport: The transport used by the client instance.
145+
"""
146+
return self._transport
147+
137148
@staticmethod
138149
def device_path(project: str, location: str, registry: str, device: str,) -> str:
139150
"""Return a fully-qualified device string."""
@@ -166,12 +177,71 @@ def parse_registry_path(path: str) -> Dict[str, str]:
166177
)
167178
return m.groupdict() if m else {}
168179

180+
@staticmethod
181+
def common_billing_account_path(billing_account: str,) -> str:
182+
"""Return a fully-qualified billing_account string."""
183+
return "billingAccounts/{billing_account}".format(
184+
billing_account=billing_account,
185+
)
186+
187+
@staticmethod
188+
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
189+
"""Parse a billing_account path into its component segments."""
190+
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
191+
return m.groupdict() if m else {}
192+
193+
@staticmethod
194+
def common_folder_path(folder: str,) -> str:
195+
"""Return a fully-qualified folder string."""
196+
return "folders/{folder}".format(folder=folder,)
197+
198+
@staticmethod
199+
def parse_common_folder_path(path: str) -> Dict[str, str]:
200+
"""Parse a folder path into its component segments."""
201+
m = re.match(r"^folders/(?P<folder>.+?)$", path)
202+
return m.groupdict() if m else {}
203+
204+
@staticmethod
205+
def common_organization_path(organization: str,) -> str:
206+
"""Return a fully-qualified organization string."""
207+
return "organizations/{organization}".format(organization=organization,)
208+
209+
@staticmethod
210+
def parse_common_organization_path(path: str) -> Dict[str, str]:
211+
"""Parse a organization path into its component segments."""
212+
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
213+
return m.groupdict() if m else {}
214+
215+
@staticmethod
216+
def common_project_path(project: str,) -> str:
217+
"""Return a fully-qualified project string."""
218+
return "projects/{project}".format(project=project,)
219+
220+
@staticmethod
221+
def parse_common_project_path(path: str) -> Dict[str, str]:
222+
"""Parse a project path into its component segments."""
223+
m = re.match(r"^projects/(?P<project>.+?)$", path)
224+
return m.groupdict() if m else {}
225+
226+
@staticmethod
227+
def common_location_path(project: str, location: str,) -> str:
228+
"""Return a fully-qualified location string."""
229+
return "projects/{project}/locations/{location}".format(
230+
project=project, location=location,
231+
)
232+
233+
@staticmethod
234+
def parse_common_location_path(path: str) -> Dict[str, str]:
235+
"""Parse a location path into its component segments."""
236+
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
237+
return m.groupdict() if m else {}
238+
169239
def __init__(
170240
self,
171241
*,
172-
credentials: credentials.Credentials = None,
173-
transport: Union[str, DeviceManagerTransport] = None,
174-
client_options: ClientOptions = None,
242+
credentials: Optional[credentials.Credentials] = None,
243+
transport: Union[str, DeviceManagerTransport, None] = None,
244+
client_options: Optional[client_options_lib.ClientOptions] = None,
175245
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
176246
) -> None:
177247
"""Instantiate the device manager client.
@@ -185,53 +255,74 @@ def __init__(
185255
transport (Union[str, ~.DeviceManagerTransport]): The
186256
transport to use. If set to None, a transport is chosen
187257
automatically.
188-
client_options (ClientOptions): Custom options for the client. It
189-
won't take effect if a ``transport`` instance is provided.
258+
client_options (client_options_lib.ClientOptions): Custom options for the
259+
client. It won't take effect if a ``transport`` instance is provided.
190260
(1) The ``api_endpoint`` property can be used to override the
191-
default endpoint provided by the client. GOOGLE_API_USE_MTLS
261+
default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT
192262
environment variable can also be used to override the endpoint:
193263
"always" (always use the default mTLS endpoint), "never" (always
194-
use the default regular endpoint, this is the default value for
195-
the environment variable) and "auto" (auto switch to the default
196-
mTLS endpoint if client SSL credentials is present). However,
197-
the ``api_endpoint`` property takes precedence if provided.
198-
(2) The ``client_cert_source`` property is used to provide client
199-
SSL credentials for mutual TLS transport. If not provided, the
200-
default SSL credentials will be used if present.
201-
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
202-
The client info used to send a user-agent string along with
203-
API requests. If ``None``, then default info will be used.
204-
Generally, you only need to set this if you're developing
264+
use the default regular endpoint) and "auto" (auto switch to the
265+
default mTLS endpoint if client certificate is present, this is
266+
the default value). However, the ``api_endpoint`` property takes
267+
precedence if provided.
268+
(2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
269+
is "true", then the ``client_cert_source`` property can be used
270+
to provide client certificate for mutual TLS transport. If
271+
not provided, the default SSL client certificate will be used if
272+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
273+
set, no client certificate will be used.
274+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
275+
The client info used to send a user-agent string along with
276+
API requests. If ``None``, then default info will be used.
277+
Generally, you only need to set this if you're developing
205278
your own client library.
206279
207280
Raises:
208281
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
209282
creation failed for any reason.
210283
"""
211284
if isinstance(client_options, dict):
212-
client_options = ClientOptions.from_dict(client_options)
285+
client_options = client_options_lib.from_dict(client_options)
213286
if client_options is None:
214-
client_options = ClientOptions.ClientOptions()
287+
client_options = client_options_lib.ClientOptions()
288+
289+
# Create SSL credentials for mutual TLS if needed.
290+
use_client_cert = bool(
291+
util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))
292+
)
293+
294+
ssl_credentials = None
295+
is_mtls = False
296+
if use_client_cert:
297+
if client_options.client_cert_source:
298+
import grpc # type: ignore
215299

216-
if client_options.api_endpoint is None:
217-
use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS", "never")
300+
cert, key = client_options.client_cert_source()
301+
ssl_credentials = grpc.ssl_channel_credentials(
302+
certificate_chain=cert, private_key=key
303+
)
304+
is_mtls = True
305+
else:
306+
creds = SslCredentials()
307+
is_mtls = creds.is_mtls
308+
ssl_credentials = creds.ssl_credentials if is_mtls else None
309+
310+
# Figure out which api endpoint to use.
311+
if client_options.api_endpoint is not None:
312+
api_endpoint = client_options.api_endpoint
313+
else:
314+
use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
218315
if use_mtls_env == "never":
219-
client_options.api_endpoint = self.DEFAULT_ENDPOINT
316+
api_endpoint = self.DEFAULT_ENDPOINT
220317
elif use_mtls_env == "always":
221-
client_options.api_endpoint = self.DEFAULT_MTLS_ENDPOINT
318+
api_endpoint = self.DEFAULT_MTLS_ENDPOINT
222319
elif use_mtls_env == "auto":
223-
has_client_cert_source = (
224-
client_options.client_cert_source is not None
225-
or mtls.has_default_client_cert_source()
226-
)
227-
client_options.api_endpoint = (
228-
self.DEFAULT_MTLS_ENDPOINT
229-
if has_client_cert_source
230-
else self.DEFAULT_ENDPOINT
320+
api_endpoint = (
321+
self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT
231322
)
232323
else:
233324
raise MutualTLSChannelError(
234-
"Unsupported GOOGLE_API_USE_MTLS value. Accepted values: never, auto, always"
325+
"Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always"
235326
)
236327

237328
# Save or instantiate the transport.
@@ -255,10 +346,9 @@ def __init__(
255346
self._transport = Transport(
256347
credentials=credentials,
257348
credentials_file=client_options.credentials_file,
258-
host=client_options.api_endpoint,
349+
host=api_endpoint,
259350
scopes=client_options.scopes,
260-
api_mtls_endpoint=client_options.api_endpoint,
261-
client_cert_source=client_options.client_cert_source,
351+
ssl_channel_credentials=ssl_credentials,
262352
quota_project_id=client_options.quota_project_id,
263353
client_info=client_info,
264354
)
@@ -1390,13 +1480,7 @@ def set_iam_policy(
13901480
request = iam_policy.SetIamPolicyRequest(**request)
13911481

13921482
elif not request:
1393-
request = iam_policy.SetIamPolicyRequest()
1394-
1395-
# If we have keyword arguments corresponding to fields on the
1396-
# request, apply these.
1397-
1398-
if resource is not None:
1399-
request.resource = resource
1483+
request = iam_policy.SetIamPolicyRequest(resource=resource,)
14001484

14011485
# Wrap the RPC method; this adds retry and timeout information,
14021486
# and friendly error handling.
@@ -1531,13 +1615,7 @@ def get_iam_policy(
15311615
request = iam_policy.GetIamPolicyRequest(**request)
15321616

15331617
elif not request:
1534-
request = iam_policy.GetIamPolicyRequest()
1535-
1536-
# If we have keyword arguments corresponding to fields on the
1537-
# request, apply these.
1538-
1539-
if resource is not None:
1540-
request.resource = resource
1618+
request = iam_policy.GetIamPolicyRequest(resource=resource,)
15411619

15421620
# Wrap the RPC method; this adds retry and timeout information,
15431621
# and friendly error handling.
@@ -1616,16 +1694,9 @@ def test_iam_permissions(
16161694
request = iam_policy.TestIamPermissionsRequest(**request)
16171695

16181696
elif not request:
1619-
request = iam_policy.TestIamPermissionsRequest()
1620-
1621-
# If we have keyword arguments corresponding to fields on the
1622-
# request, apply these.
1623-
1624-
if resource is not None:
1625-
request.resource = resource
1626-
1627-
if permissions:
1628-
request.permissions.extend(permissions)
1697+
request = iam_policy.TestIamPermissionsRequest(
1698+
resource=resource, permissions=permissions,
1699+
)
16291700

16301701
# Wrap the RPC method; this adds retry and timeout information,
16311702
# and friendly error handling.

google/cloud/iot_v1/services/device_manager/transports/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
_transport_registry["grpc"] = DeviceManagerGrpcTransport
2929
_transport_registry["grpc_asyncio"] = DeviceManagerGrpcAsyncIOTransport
3030

31-
3231
__all__ = (
3332
"DeviceManagerTransport",
3433
"DeviceManagerGrpcTransport",

0 commit comments

Comments
 (0)