google-cloud-devicestreaming 0.1.0__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.
Files changed (26) hide show
  1. google/cloud/devicestreaming/__init__.py +69 -0
  2. google/cloud/devicestreaming/gapic_version.py +16 -0
  3. google/cloud/devicestreaming/py.typed +2 -0
  4. google/cloud/devicestreaming_v1/__init__.py +67 -0
  5. google/cloud/devicestreaming_v1/gapic_metadata.json +118 -0
  6. google/cloud/devicestreaming_v1/gapic_version.py +16 -0
  7. google/cloud/devicestreaming_v1/py.typed +2 -0
  8. google/cloud/devicestreaming_v1/services/__init__.py +15 -0
  9. google/cloud/devicestreaming_v1/services/direct_access_service/__init__.py +22 -0
  10. google/cloud/devicestreaming_v1/services/direct_access_service/async_client.py +1001 -0
  11. google/cloud/devicestreaming_v1/services/direct_access_service/client.py +1410 -0
  12. google/cloud/devicestreaming_v1/services/direct_access_service/pagers.py +197 -0
  13. google/cloud/devicestreaming_v1/services/direct_access_service/transports/__init__.py +38 -0
  14. google/cloud/devicestreaming_v1/services/direct_access_service/transports/base.py +262 -0
  15. google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc.py +512 -0
  16. google/cloud/devicestreaming_v1/services/direct_access_service/transports/grpc_asyncio.py +592 -0
  17. google/cloud/devicestreaming_v1/services/direct_access_service/transports/rest.py +1234 -0
  18. google/cloud/devicestreaming_v1/services/direct_access_service/transports/rest_base.py +361 -0
  19. google/cloud/devicestreaming_v1/types/__init__.py +56 -0
  20. google/cloud/devicestreaming_v1/types/adb_service.py +317 -0
  21. google/cloud/devicestreaming_v1/types/service.py +410 -0
  22. google_cloud_devicestreaming-0.1.0.dist-info/LICENSE +202 -0
  23. google_cloud_devicestreaming-0.1.0.dist-info/METADATA +228 -0
  24. google_cloud_devicestreaming-0.1.0.dist-info/RECORD +26 -0
  25. google_cloud_devicestreaming-0.1.0.dist-info/WHEEL +5 -0
  26. google_cloud_devicestreaming-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1410 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2025 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
+ #
16
+ from collections import OrderedDict
17
+ from http import HTTPStatus
18
+ import json
19
+ import logging as std_logging
20
+ import os
21
+ import re
22
+ from typing import (
23
+ Callable,
24
+ Dict,
25
+ Iterable,
26
+ Iterator,
27
+ Mapping,
28
+ MutableMapping,
29
+ MutableSequence,
30
+ Optional,
31
+ Sequence,
32
+ Tuple,
33
+ Type,
34
+ Union,
35
+ cast,
36
+ )
37
+ import warnings
38
+
39
+ from google.api_core import client_options as client_options_lib
40
+ from google.api_core import exceptions as core_exceptions
41
+ from google.api_core import gapic_v1
42
+ from google.api_core import retry as retries
43
+ from google.auth import credentials as ga_credentials # type: ignore
44
+ from google.auth.exceptions import MutualTLSChannelError # type: ignore
45
+ from google.auth.transport import mtls # type: ignore
46
+ from google.auth.transport.grpc import SslCredentials # type: ignore
47
+ from google.oauth2 import service_account # type: ignore
48
+
49
+ from google.cloud.devicestreaming_v1 import gapic_version as package_version
50
+
51
+ try:
52
+ OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
53
+ except AttributeError: # pragma: NO COVER
54
+ OptionalRetry = Union[retries.Retry, object, None] # type: ignore
55
+
56
+ try:
57
+ from google.api_core import client_logging # type: ignore
58
+
59
+ CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
60
+ except ImportError: # pragma: NO COVER
61
+ CLIENT_LOGGING_SUPPORTED = False
62
+
63
+ _LOGGER = std_logging.getLogger(__name__)
64
+
65
+ from google.protobuf import duration_pb2 # type: ignore
66
+ from google.protobuf import field_mask_pb2 # type: ignore
67
+ from google.protobuf import timestamp_pb2 # type: ignore
68
+
69
+ from google.cloud.devicestreaming_v1.services.direct_access_service import pagers
70
+ from google.cloud.devicestreaming_v1.types import adb_service, service
71
+
72
+ from .transports.base import DEFAULT_CLIENT_INFO, DirectAccessServiceTransport
73
+ from .transports.grpc import DirectAccessServiceGrpcTransport
74
+ from .transports.grpc_asyncio import DirectAccessServiceGrpcAsyncIOTransport
75
+ from .transports.rest import DirectAccessServiceRestTransport
76
+
77
+
78
+ class DirectAccessServiceClientMeta(type):
79
+ """Metaclass for the DirectAccessService client.
80
+
81
+ This provides class-level methods for building and retrieving
82
+ support objects (e.g. transport) without polluting the client instance
83
+ objects.
84
+ """
85
+
86
+ _transport_registry = (
87
+ OrderedDict()
88
+ ) # type: Dict[str, Type[DirectAccessServiceTransport]]
89
+ _transport_registry["grpc"] = DirectAccessServiceGrpcTransport
90
+ _transport_registry["grpc_asyncio"] = DirectAccessServiceGrpcAsyncIOTransport
91
+ _transport_registry["rest"] = DirectAccessServiceRestTransport
92
+
93
+ def get_transport_class(
94
+ cls,
95
+ label: Optional[str] = None,
96
+ ) -> Type[DirectAccessServiceTransport]:
97
+ """Returns an appropriate transport class.
98
+
99
+ Args:
100
+ label: The name of the desired transport. If none is
101
+ provided, then the first transport in the registry is used.
102
+
103
+ Returns:
104
+ The transport class to use.
105
+ """
106
+ # If a specific transport is requested, return that one.
107
+ if label:
108
+ return cls._transport_registry[label]
109
+
110
+ # No transport is requested; return the default (that is, the first one
111
+ # in the dictionary).
112
+ return next(iter(cls._transport_registry.values()))
113
+
114
+
115
+ class DirectAccessServiceClient(metaclass=DirectAccessServiceClientMeta):
116
+ """A service for allocating Android devices and interacting with
117
+ the live-allocated devices.
118
+
119
+ Each Session will wait for available capacity, at a higher
120
+ priority over Test Execution. When allocated, the session will
121
+ be exposed through a stream for integration.
122
+
123
+ DirectAccessService is currently available as a preview to
124
+ select developers. You can register today on behalf of you and
125
+ your team at
126
+ https://developer.android.com/studio/preview/android-device-streaming
127
+ """
128
+
129
+ @staticmethod
130
+ def _get_default_mtls_endpoint(api_endpoint):
131
+ """Converts api endpoint to mTLS endpoint.
132
+
133
+ Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
134
+ "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
135
+ Args:
136
+ api_endpoint (Optional[str]): the api endpoint to convert.
137
+ Returns:
138
+ str: converted mTLS api endpoint.
139
+ """
140
+ if not api_endpoint:
141
+ return api_endpoint
142
+
143
+ mtls_endpoint_re = re.compile(
144
+ r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
145
+ )
146
+
147
+ m = mtls_endpoint_re.match(api_endpoint)
148
+ name, mtls, sandbox, googledomain = m.groups()
149
+ if mtls or not googledomain:
150
+ return api_endpoint
151
+
152
+ if sandbox:
153
+ return api_endpoint.replace(
154
+ "sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
155
+ )
156
+
157
+ return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
158
+
159
+ # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
160
+ DEFAULT_ENDPOINT = "devicestreaming.googleapis.com"
161
+ DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
162
+ DEFAULT_ENDPOINT
163
+ )
164
+
165
+ _DEFAULT_ENDPOINT_TEMPLATE = "devicestreaming.{UNIVERSE_DOMAIN}"
166
+ _DEFAULT_UNIVERSE = "googleapis.com"
167
+
168
+ @classmethod
169
+ def from_service_account_info(cls, info: dict, *args, **kwargs):
170
+ """Creates an instance of this client using the provided credentials
171
+ info.
172
+
173
+ Args:
174
+ info (dict): The service account private key info.
175
+ args: Additional arguments to pass to the constructor.
176
+ kwargs: Additional arguments to pass to the constructor.
177
+
178
+ Returns:
179
+ DirectAccessServiceClient: The constructed client.
180
+ """
181
+ credentials = service_account.Credentials.from_service_account_info(info)
182
+ kwargs["credentials"] = credentials
183
+ return cls(*args, **kwargs)
184
+
185
+ @classmethod
186
+ def from_service_account_file(cls, filename: str, *args, **kwargs):
187
+ """Creates an instance of this client using the provided credentials
188
+ file.
189
+
190
+ Args:
191
+ filename (str): The path to the service account private key json
192
+ file.
193
+ args: Additional arguments to pass to the constructor.
194
+ kwargs: Additional arguments to pass to the constructor.
195
+
196
+ Returns:
197
+ DirectAccessServiceClient: The constructed client.
198
+ """
199
+ credentials = service_account.Credentials.from_service_account_file(filename)
200
+ kwargs["credentials"] = credentials
201
+ return cls(*args, **kwargs)
202
+
203
+ from_service_account_json = from_service_account_file
204
+
205
+ @property
206
+ def transport(self) -> DirectAccessServiceTransport:
207
+ """Returns the transport used by the client instance.
208
+
209
+ Returns:
210
+ DirectAccessServiceTransport: The transport used by the client
211
+ instance.
212
+ """
213
+ return self._transport
214
+
215
+ @staticmethod
216
+ def device_session_path(
217
+ project: str,
218
+ device_session: str,
219
+ ) -> str:
220
+ """Returns a fully-qualified device_session string."""
221
+ return "projects/{project}/deviceSessions/{device_session}".format(
222
+ project=project,
223
+ device_session=device_session,
224
+ )
225
+
226
+ @staticmethod
227
+ def parse_device_session_path(path: str) -> Dict[str, str]:
228
+ """Parses a device_session path into its component segments."""
229
+ m = re.match(
230
+ r"^projects/(?P<project>.+?)/deviceSessions/(?P<device_session>.+?)$", path
231
+ )
232
+ return m.groupdict() if m else {}
233
+
234
+ @staticmethod
235
+ def common_billing_account_path(
236
+ billing_account: str,
237
+ ) -> str:
238
+ """Returns a fully-qualified billing_account string."""
239
+ return "billingAccounts/{billing_account}".format(
240
+ billing_account=billing_account,
241
+ )
242
+
243
+ @staticmethod
244
+ def parse_common_billing_account_path(path: str) -> Dict[str, str]:
245
+ """Parse a billing_account path into its component segments."""
246
+ m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
247
+ return m.groupdict() if m else {}
248
+
249
+ @staticmethod
250
+ def common_folder_path(
251
+ folder: str,
252
+ ) -> str:
253
+ """Returns a fully-qualified folder string."""
254
+ return "folders/{folder}".format(
255
+ folder=folder,
256
+ )
257
+
258
+ @staticmethod
259
+ def parse_common_folder_path(path: str) -> Dict[str, str]:
260
+ """Parse a folder path into its component segments."""
261
+ m = re.match(r"^folders/(?P<folder>.+?)$", path)
262
+ return m.groupdict() if m else {}
263
+
264
+ @staticmethod
265
+ def common_organization_path(
266
+ organization: str,
267
+ ) -> str:
268
+ """Returns a fully-qualified organization string."""
269
+ return "organizations/{organization}".format(
270
+ organization=organization,
271
+ )
272
+
273
+ @staticmethod
274
+ def parse_common_organization_path(path: str) -> Dict[str, str]:
275
+ """Parse a organization path into its component segments."""
276
+ m = re.match(r"^organizations/(?P<organization>.+?)$", path)
277
+ return m.groupdict() if m else {}
278
+
279
+ @staticmethod
280
+ def common_project_path(
281
+ project: str,
282
+ ) -> str:
283
+ """Returns a fully-qualified project string."""
284
+ return "projects/{project}".format(
285
+ project=project,
286
+ )
287
+
288
+ @staticmethod
289
+ def parse_common_project_path(path: str) -> Dict[str, str]:
290
+ """Parse a project path into its component segments."""
291
+ m = re.match(r"^projects/(?P<project>.+?)$", path)
292
+ return m.groupdict() if m else {}
293
+
294
+ @staticmethod
295
+ def common_location_path(
296
+ project: str,
297
+ location: str,
298
+ ) -> str:
299
+ """Returns a fully-qualified location string."""
300
+ return "projects/{project}/locations/{location}".format(
301
+ project=project,
302
+ location=location,
303
+ )
304
+
305
+ @staticmethod
306
+ def parse_common_location_path(path: str) -> Dict[str, str]:
307
+ """Parse a location path into its component segments."""
308
+ m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
309
+ return m.groupdict() if m else {}
310
+
311
+ @classmethod
312
+ def get_mtls_endpoint_and_cert_source(
313
+ cls, client_options: Optional[client_options_lib.ClientOptions] = None
314
+ ):
315
+ """Deprecated. Return the API endpoint and client cert source for mutual TLS.
316
+
317
+ The client cert source is determined in the following order:
318
+ (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
319
+ client cert source is None.
320
+ (2) if `client_options.client_cert_source` is provided, use the provided one; if the
321
+ default client cert source exists, use the default one; otherwise the client cert
322
+ source is None.
323
+
324
+ The API endpoint is determined in the following order:
325
+ (1) if `client_options.api_endpoint` if provided, use the provided one.
326
+ (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
327
+ default mTLS endpoint; if the environment variable is "never", use the default API
328
+ endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
329
+ use the default API endpoint.
330
+
331
+ More details can be found at https://google.aip.dev/auth/4114.
332
+
333
+ Args:
334
+ client_options (google.api_core.client_options.ClientOptions): Custom options for the
335
+ client. Only the `api_endpoint` and `client_cert_source` properties may be used
336
+ in this method.
337
+
338
+ Returns:
339
+ Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
340
+ client cert source to use.
341
+
342
+ Raises:
343
+ google.auth.exceptions.MutualTLSChannelError: If any errors happen.
344
+ """
345
+
346
+ warnings.warn(
347
+ "get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
348
+ DeprecationWarning,
349
+ )
350
+ if client_options is None:
351
+ client_options = client_options_lib.ClientOptions()
352
+ use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
353
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
354
+ if use_client_cert not in ("true", "false"):
355
+ raise ValueError(
356
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
357
+ )
358
+ if use_mtls_endpoint not in ("auto", "never", "always"):
359
+ raise MutualTLSChannelError(
360
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
361
+ )
362
+
363
+ # Figure out the client cert source to use.
364
+ client_cert_source = None
365
+ if use_client_cert == "true":
366
+ if client_options.client_cert_source:
367
+ client_cert_source = client_options.client_cert_source
368
+ elif mtls.has_default_client_cert_source():
369
+ client_cert_source = mtls.default_client_cert_source()
370
+
371
+ # Figure out which api endpoint to use.
372
+ if client_options.api_endpoint is not None:
373
+ api_endpoint = client_options.api_endpoint
374
+ elif use_mtls_endpoint == "always" or (
375
+ use_mtls_endpoint == "auto" and client_cert_source
376
+ ):
377
+ api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
378
+ else:
379
+ api_endpoint = cls.DEFAULT_ENDPOINT
380
+
381
+ return api_endpoint, client_cert_source
382
+
383
+ @staticmethod
384
+ def _read_environment_variables():
385
+ """Returns the environment variables used by the client.
386
+
387
+ Returns:
388
+ Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
389
+ GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
390
+
391
+ Raises:
392
+ ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
393
+ any of ["true", "false"].
394
+ google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
395
+ is not any of ["auto", "never", "always"].
396
+ """
397
+ use_client_cert = os.getenv(
398
+ "GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
399
+ ).lower()
400
+ use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
401
+ universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
402
+ if use_client_cert not in ("true", "false"):
403
+ raise ValueError(
404
+ "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
405
+ )
406
+ if use_mtls_endpoint not in ("auto", "never", "always"):
407
+ raise MutualTLSChannelError(
408
+ "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
409
+ )
410
+ return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
411
+
412
+ @staticmethod
413
+ def _get_client_cert_source(provided_cert_source, use_cert_flag):
414
+ """Return the client cert source to be used by the client.
415
+
416
+ Args:
417
+ provided_cert_source (bytes): The client certificate source provided.
418
+ use_cert_flag (bool): A flag indicating whether to use the client certificate.
419
+
420
+ Returns:
421
+ bytes or None: The client cert source to be used by the client.
422
+ """
423
+ client_cert_source = None
424
+ if use_cert_flag:
425
+ if provided_cert_source:
426
+ client_cert_source = provided_cert_source
427
+ elif mtls.has_default_client_cert_source():
428
+ client_cert_source = mtls.default_client_cert_source()
429
+ return client_cert_source
430
+
431
+ @staticmethod
432
+ def _get_api_endpoint(
433
+ api_override, client_cert_source, universe_domain, use_mtls_endpoint
434
+ ):
435
+ """Return the API endpoint used by the client.
436
+
437
+ Args:
438
+ api_override (str): The API endpoint override. If specified, this is always
439
+ the return value of this function and the other arguments are not used.
440
+ client_cert_source (bytes): The client certificate source used by the client.
441
+ universe_domain (str): The universe domain used by the client.
442
+ use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
443
+ Possible values are "always", "auto", or "never".
444
+
445
+ Returns:
446
+ str: The API endpoint to be used by the client.
447
+ """
448
+ if api_override is not None:
449
+ api_endpoint = api_override
450
+ elif use_mtls_endpoint == "always" or (
451
+ use_mtls_endpoint == "auto" and client_cert_source
452
+ ):
453
+ _default_universe = DirectAccessServiceClient._DEFAULT_UNIVERSE
454
+ if universe_domain != _default_universe:
455
+ raise MutualTLSChannelError(
456
+ f"mTLS is not supported in any universe other than {_default_universe}."
457
+ )
458
+ api_endpoint = DirectAccessServiceClient.DEFAULT_MTLS_ENDPOINT
459
+ else:
460
+ api_endpoint = DirectAccessServiceClient._DEFAULT_ENDPOINT_TEMPLATE.format(
461
+ UNIVERSE_DOMAIN=universe_domain
462
+ )
463
+ return api_endpoint
464
+
465
+ @staticmethod
466
+ def _get_universe_domain(
467
+ client_universe_domain: Optional[str], universe_domain_env: Optional[str]
468
+ ) -> str:
469
+ """Return the universe domain used by the client.
470
+
471
+ Args:
472
+ client_universe_domain (Optional[str]): The universe domain configured via the client options.
473
+ universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
474
+
475
+ Returns:
476
+ str: The universe domain to be used by the client.
477
+
478
+ Raises:
479
+ ValueError: If the universe domain is an empty string.
480
+ """
481
+ universe_domain = DirectAccessServiceClient._DEFAULT_UNIVERSE
482
+ if client_universe_domain is not None:
483
+ universe_domain = client_universe_domain
484
+ elif universe_domain_env is not None:
485
+ universe_domain = universe_domain_env
486
+ if len(universe_domain.strip()) == 0:
487
+ raise ValueError("Universe Domain cannot be an empty string.")
488
+ return universe_domain
489
+
490
+ def _validate_universe_domain(self):
491
+ """Validates client's and credentials' universe domains are consistent.
492
+
493
+ Returns:
494
+ bool: True iff the configured universe domain is valid.
495
+
496
+ Raises:
497
+ ValueError: If the configured universe domain is not valid.
498
+ """
499
+
500
+ # NOTE (b/349488459): universe validation is disabled until further notice.
501
+ return True
502
+
503
+ def _add_cred_info_for_auth_errors(
504
+ self, error: core_exceptions.GoogleAPICallError
505
+ ) -> None:
506
+ """Adds credential info string to error details for 401/403/404 errors.
507
+
508
+ Args:
509
+ error (google.api_core.exceptions.GoogleAPICallError): The error to add the cred info.
510
+ """
511
+ if error.code not in [
512
+ HTTPStatus.UNAUTHORIZED,
513
+ HTTPStatus.FORBIDDEN,
514
+ HTTPStatus.NOT_FOUND,
515
+ ]:
516
+ return
517
+
518
+ cred = self._transport._credentials
519
+
520
+ # get_cred_info is only available in google-auth>=2.35.0
521
+ if not hasattr(cred, "get_cred_info"):
522
+ return
523
+
524
+ # ignore the type check since pypy test fails when get_cred_info
525
+ # is not available
526
+ cred_info = cred.get_cred_info() # type: ignore
527
+ if cred_info and hasattr(error._details, "append"):
528
+ error._details.append(json.dumps(cred_info))
529
+
530
+ @property
531
+ def api_endpoint(self):
532
+ """Return the API endpoint used by the client instance.
533
+
534
+ Returns:
535
+ str: The API endpoint used by the client instance.
536
+ """
537
+ return self._api_endpoint
538
+
539
+ @property
540
+ def universe_domain(self) -> str:
541
+ """Return the universe domain used by the client instance.
542
+
543
+ Returns:
544
+ str: The universe domain used by the client instance.
545
+ """
546
+ return self._universe_domain
547
+
548
+ def __init__(
549
+ self,
550
+ *,
551
+ credentials: Optional[ga_credentials.Credentials] = None,
552
+ transport: Optional[
553
+ Union[
554
+ str,
555
+ DirectAccessServiceTransport,
556
+ Callable[..., DirectAccessServiceTransport],
557
+ ]
558
+ ] = None,
559
+ client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
560
+ client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
561
+ ) -> None:
562
+ """Instantiates the direct access service client.
563
+
564
+ Args:
565
+ credentials (Optional[google.auth.credentials.Credentials]): The
566
+ authorization credentials to attach to requests. These
567
+ credentials identify the application to the service; if none
568
+ are specified, the client will attempt to ascertain the
569
+ credentials from the environment.
570
+ transport (Optional[Union[str,DirectAccessServiceTransport,Callable[..., DirectAccessServiceTransport]]]):
571
+ The transport to use, or a Callable that constructs and returns a new transport.
572
+ If a Callable is given, it will be called with the same set of initialization
573
+ arguments as used in the DirectAccessServiceTransport constructor.
574
+ If set to None, a transport is chosen automatically.
575
+ client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
576
+ Custom options for the client.
577
+
578
+ 1. The ``api_endpoint`` property can be used to override the
579
+ default endpoint provided by the client when ``transport`` is
580
+ not explicitly provided. Only if this property is not set and
581
+ ``transport`` was not explicitly provided, the endpoint is
582
+ determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
583
+ variable, which have one of the following values:
584
+ "always" (always use the default mTLS endpoint), "never" (always
585
+ use the default regular endpoint) and "auto" (auto-switch to the
586
+ default mTLS endpoint if client certificate is present; this is
587
+ the default value).
588
+
589
+ 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
590
+ is "true", then the ``client_cert_source`` property can be used
591
+ to provide a client certificate for mTLS transport. If
592
+ not provided, the default SSL client certificate will be used if
593
+ present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
594
+ set, no client certificate will be used.
595
+
596
+ 3. The ``universe_domain`` property can be used to override the
597
+ default "googleapis.com" universe. Note that the ``api_endpoint``
598
+ property still takes precedence; and ``universe_domain`` is
599
+ currently not supported for mTLS.
600
+
601
+ client_info (google.api_core.gapic_v1.client_info.ClientInfo):
602
+ The client info used to send a user-agent string along with
603
+ API requests. If ``None``, then default info will be used.
604
+ Generally, you only need to set this if you're developing
605
+ your own client library.
606
+
607
+ Raises:
608
+ google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
609
+ creation failed for any reason.
610
+ """
611
+ self._client_options = client_options
612
+ if isinstance(self._client_options, dict):
613
+ self._client_options = client_options_lib.from_dict(self._client_options)
614
+ if self._client_options is None:
615
+ self._client_options = client_options_lib.ClientOptions()
616
+ self._client_options = cast(
617
+ client_options_lib.ClientOptions, self._client_options
618
+ )
619
+
620
+ universe_domain_opt = getattr(self._client_options, "universe_domain", None)
621
+
622
+ (
623
+ self._use_client_cert,
624
+ self._use_mtls_endpoint,
625
+ self._universe_domain_env,
626
+ ) = DirectAccessServiceClient._read_environment_variables()
627
+ self._client_cert_source = DirectAccessServiceClient._get_client_cert_source(
628
+ self._client_options.client_cert_source, self._use_client_cert
629
+ )
630
+ self._universe_domain = DirectAccessServiceClient._get_universe_domain(
631
+ universe_domain_opt, self._universe_domain_env
632
+ )
633
+ self._api_endpoint = None # updated below, depending on `transport`
634
+
635
+ # Initialize the universe domain validation.
636
+ self._is_universe_domain_valid = False
637
+
638
+ if CLIENT_LOGGING_SUPPORTED: # pragma: NO COVER
639
+ # Setup logging.
640
+ client_logging.initialize_logging()
641
+
642
+ api_key_value = getattr(self._client_options, "api_key", None)
643
+ if api_key_value and credentials:
644
+ raise ValueError(
645
+ "client_options.api_key and credentials are mutually exclusive"
646
+ )
647
+
648
+ # Save or instantiate the transport.
649
+ # Ordinarily, we provide the transport, but allowing a custom transport
650
+ # instance provides an extensibility point for unusual situations.
651
+ transport_provided = isinstance(transport, DirectAccessServiceTransport)
652
+ if transport_provided:
653
+ # transport is a DirectAccessServiceTransport instance.
654
+ if credentials or self._client_options.credentials_file or api_key_value:
655
+ raise ValueError(
656
+ "When providing a transport instance, "
657
+ "provide its credentials directly."
658
+ )
659
+ if self._client_options.scopes:
660
+ raise ValueError(
661
+ "When providing a transport instance, provide its scopes "
662
+ "directly."
663
+ )
664
+ self._transport = cast(DirectAccessServiceTransport, transport)
665
+ self._api_endpoint = self._transport.host
666
+
667
+ self._api_endpoint = (
668
+ self._api_endpoint
669
+ or DirectAccessServiceClient._get_api_endpoint(
670
+ self._client_options.api_endpoint,
671
+ self._client_cert_source,
672
+ self._universe_domain,
673
+ self._use_mtls_endpoint,
674
+ )
675
+ )
676
+
677
+ if not transport_provided:
678
+ import google.auth._default # type: ignore
679
+
680
+ if api_key_value and hasattr(
681
+ google.auth._default, "get_api_key_credentials"
682
+ ):
683
+ credentials = google.auth._default.get_api_key_credentials(
684
+ api_key_value
685
+ )
686
+
687
+ transport_init: Union[
688
+ Type[DirectAccessServiceTransport],
689
+ Callable[..., DirectAccessServiceTransport],
690
+ ] = (
691
+ DirectAccessServiceClient.get_transport_class(transport)
692
+ if isinstance(transport, str) or transport is None
693
+ else cast(Callable[..., DirectAccessServiceTransport], transport)
694
+ )
695
+ # initialize with the provided callable or the passed in class
696
+ self._transport = transport_init(
697
+ credentials=credentials,
698
+ credentials_file=self._client_options.credentials_file,
699
+ host=self._api_endpoint,
700
+ scopes=self._client_options.scopes,
701
+ client_cert_source_for_mtls=self._client_cert_source,
702
+ quota_project_id=self._client_options.quota_project_id,
703
+ client_info=client_info,
704
+ always_use_jwt_access=True,
705
+ api_audience=self._client_options.api_audience,
706
+ )
707
+
708
+ if "async" not in str(self._transport):
709
+ if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
710
+ std_logging.DEBUG
711
+ ): # pragma: NO COVER
712
+ _LOGGER.debug(
713
+ "Created client `google.cloud.devicestreaming_v1.DirectAccessServiceClient`.",
714
+ extra={
715
+ "serviceName": "google.cloud.devicestreaming.v1.DirectAccessService",
716
+ "universeDomain": getattr(
717
+ self._transport._credentials, "universe_domain", ""
718
+ ),
719
+ "credentialsType": f"{type(self._transport._credentials).__module__}.{type(self._transport._credentials).__qualname__}",
720
+ "credentialsInfo": getattr(
721
+ self.transport._credentials, "get_cred_info", lambda: None
722
+ )(),
723
+ }
724
+ if hasattr(self._transport, "_credentials")
725
+ else {
726
+ "serviceName": "google.cloud.devicestreaming.v1.DirectAccessService",
727
+ "credentialsType": None,
728
+ },
729
+ )
730
+
731
+ def create_device_session(
732
+ self,
733
+ request: Optional[Union[service.CreateDeviceSessionRequest, dict]] = None,
734
+ *,
735
+ parent: Optional[str] = None,
736
+ device_session: Optional[service.DeviceSession] = None,
737
+ device_session_id: Optional[str] = None,
738
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
739
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
740
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
741
+ ) -> service.DeviceSession:
742
+ r"""Creates a DeviceSession.
743
+
744
+ .. code-block:: python
745
+
746
+ # This snippet has been automatically generated and should be regarded as a
747
+ # code template only.
748
+ # It will require modifications to work:
749
+ # - It may require correct/in-range values for request initialization.
750
+ # - It may require specifying regional endpoints when creating the service
751
+ # client as shown in:
752
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
753
+ from google.cloud import devicestreaming_v1
754
+
755
+ def sample_create_device_session():
756
+ # Create a client
757
+ client = devicestreaming_v1.DirectAccessServiceClient()
758
+
759
+ # Initialize request argument(s)
760
+ device_session = devicestreaming_v1.DeviceSession()
761
+ device_session.android_device.android_model_id = "android_model_id_value"
762
+ device_session.android_device.android_version_id = "android_version_id_value"
763
+
764
+ request = devicestreaming_v1.CreateDeviceSessionRequest(
765
+ parent="parent_value",
766
+ device_session=device_session,
767
+ )
768
+
769
+ # Make the request
770
+ response = client.create_device_session(request=request)
771
+
772
+ # Handle the response
773
+ print(response)
774
+
775
+ Args:
776
+ request (Union[google.cloud.devicestreaming_v1.types.CreateDeviceSessionRequest, dict]):
777
+ The request object. Request message for
778
+ DirectAccessService.CreateDeviceSession.
779
+ parent (str):
780
+ Required. The Compute Engine project under which this
781
+ device will be allocated. "projects/{project_id}"
782
+
783
+ This corresponds to the ``parent`` field
784
+ on the ``request`` instance; if ``request`` is provided, this
785
+ should not be set.
786
+ device_session (google.cloud.devicestreaming_v1.types.DeviceSession):
787
+ Required. A DeviceSession to create.
788
+ This corresponds to the ``device_session`` field
789
+ on the ``request`` instance; if ``request`` is provided, this
790
+ should not be set.
791
+ device_session_id (str):
792
+ Optional. The ID to use for the DeviceSession, which
793
+ will become the final component of the DeviceSession's
794
+ resource name.
795
+
796
+ This value should be 4-63 characters, and valid
797
+ characters are /[a-z][0-9]-/.
798
+
799
+ This corresponds to the ``device_session_id`` field
800
+ on the ``request`` instance; if ``request`` is provided, this
801
+ should not be set.
802
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
803
+ should be retried.
804
+ timeout (float): The timeout for this request.
805
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
806
+ sent along with the request as metadata. Normally, each value must be of type `str`,
807
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
808
+ be of type `bytes`.
809
+
810
+ Returns:
811
+ google.cloud.devicestreaming_v1.types.DeviceSession:
812
+ Protobuf message describing the
813
+ device message, used from several RPCs.
814
+
815
+ """
816
+ # Create or coerce a protobuf request object.
817
+ # - Quick check: If we got a request object, we should *not* have
818
+ # gotten any keyword arguments that map to the request.
819
+ flattened_params = [parent, device_session, device_session_id]
820
+ has_flattened_params = (
821
+ len([param for param in flattened_params if param is not None]) > 0
822
+ )
823
+ if request is not None and has_flattened_params:
824
+ raise ValueError(
825
+ "If the `request` argument is set, then none of "
826
+ "the individual field arguments should be set."
827
+ )
828
+
829
+ # - Use the request object if provided (there's no risk of modifying the input as
830
+ # there are no flattened fields), or create one.
831
+ if not isinstance(request, service.CreateDeviceSessionRequest):
832
+ request = service.CreateDeviceSessionRequest(request)
833
+ # If we have keyword arguments corresponding to fields on the
834
+ # request, apply these.
835
+ if parent is not None:
836
+ request.parent = parent
837
+ if device_session is not None:
838
+ request.device_session = device_session
839
+ if device_session_id is not None:
840
+ request.device_session_id = device_session_id
841
+
842
+ # Wrap the RPC method; this adds retry and timeout information,
843
+ # and friendly error handling.
844
+ rpc = self._transport._wrapped_methods[self._transport.create_device_session]
845
+
846
+ # Certain fields should be provided within the metadata header;
847
+ # add these here.
848
+ metadata = tuple(metadata) + (
849
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
850
+ )
851
+
852
+ # Validate the universe domain.
853
+ self._validate_universe_domain()
854
+
855
+ # Send the request.
856
+ response = rpc(
857
+ request,
858
+ retry=retry,
859
+ timeout=timeout,
860
+ metadata=metadata,
861
+ )
862
+
863
+ # Done; return the response.
864
+ return response
865
+
866
+ def list_device_sessions(
867
+ self,
868
+ request: Optional[Union[service.ListDeviceSessionsRequest, dict]] = None,
869
+ *,
870
+ parent: Optional[str] = None,
871
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
872
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
873
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
874
+ ) -> pagers.ListDeviceSessionsPager:
875
+ r"""Lists DeviceSessions owned by the project user.
876
+
877
+ .. code-block:: python
878
+
879
+ # This snippet has been automatically generated and should be regarded as a
880
+ # code template only.
881
+ # It will require modifications to work:
882
+ # - It may require correct/in-range values for request initialization.
883
+ # - It may require specifying regional endpoints when creating the service
884
+ # client as shown in:
885
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
886
+ from google.cloud import devicestreaming_v1
887
+
888
+ def sample_list_device_sessions():
889
+ # Create a client
890
+ client = devicestreaming_v1.DirectAccessServiceClient()
891
+
892
+ # Initialize request argument(s)
893
+ request = devicestreaming_v1.ListDeviceSessionsRequest(
894
+ parent="parent_value",
895
+ )
896
+
897
+ # Make the request
898
+ page_result = client.list_device_sessions(request=request)
899
+
900
+ # Handle the response
901
+ for response in page_result:
902
+ print(response)
903
+
904
+ Args:
905
+ request (Union[google.cloud.devicestreaming_v1.types.ListDeviceSessionsRequest, dict]):
906
+ The request object. Request message for
907
+ DirectAccessService.ListDeviceSessions.
908
+ parent (str):
909
+ Required. The name of the parent to request, e.g.
910
+ "projects/{project_id}"
911
+
912
+ This corresponds to the ``parent`` field
913
+ on the ``request`` instance; if ``request`` is provided, this
914
+ should not be set.
915
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
916
+ should be retried.
917
+ timeout (float): The timeout for this request.
918
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
919
+ sent along with the request as metadata. Normally, each value must be of type `str`,
920
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
921
+ be of type `bytes`.
922
+
923
+ Returns:
924
+ google.cloud.devicestreaming_v1.services.direct_access_service.pagers.ListDeviceSessionsPager:
925
+ Response message for
926
+ DirectAccessService.ListDeviceSessions.
927
+ Iterating over this object will yield
928
+ results and resolve additional pages
929
+ automatically.
930
+
931
+ """
932
+ # Create or coerce a protobuf request object.
933
+ # - Quick check: If we got a request object, we should *not* have
934
+ # gotten any keyword arguments that map to the request.
935
+ flattened_params = [parent]
936
+ has_flattened_params = (
937
+ len([param for param in flattened_params if param is not None]) > 0
938
+ )
939
+ if request is not None and has_flattened_params:
940
+ raise ValueError(
941
+ "If the `request` argument is set, then none of "
942
+ "the individual field arguments should be set."
943
+ )
944
+
945
+ # - Use the request object if provided (there's no risk of modifying the input as
946
+ # there are no flattened fields), or create one.
947
+ if not isinstance(request, service.ListDeviceSessionsRequest):
948
+ request = service.ListDeviceSessionsRequest(request)
949
+ # If we have keyword arguments corresponding to fields on the
950
+ # request, apply these.
951
+ if parent is not None:
952
+ request.parent = parent
953
+
954
+ # Wrap the RPC method; this adds retry and timeout information,
955
+ # and friendly error handling.
956
+ rpc = self._transport._wrapped_methods[self._transport.list_device_sessions]
957
+
958
+ # Certain fields should be provided within the metadata header;
959
+ # add these here.
960
+ metadata = tuple(metadata) + (
961
+ gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
962
+ )
963
+
964
+ # Validate the universe domain.
965
+ self._validate_universe_domain()
966
+
967
+ # Send the request.
968
+ response = rpc(
969
+ request,
970
+ retry=retry,
971
+ timeout=timeout,
972
+ metadata=metadata,
973
+ )
974
+
975
+ # This method is paged; wrap the response in a pager, which provides
976
+ # an `__iter__` convenience method.
977
+ response = pagers.ListDeviceSessionsPager(
978
+ method=rpc,
979
+ request=request,
980
+ response=response,
981
+ retry=retry,
982
+ timeout=timeout,
983
+ metadata=metadata,
984
+ )
985
+
986
+ # Done; return the response.
987
+ return response
988
+
989
+ def get_device_session(
990
+ self,
991
+ request: Optional[Union[service.GetDeviceSessionRequest, dict]] = None,
992
+ *,
993
+ name: Optional[str] = None,
994
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
995
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
996
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
997
+ ) -> service.DeviceSession:
998
+ r"""Gets a DeviceSession, which documents the allocation
999
+ status and whether the device is allocated. Clients
1000
+ making requests from this API must poll
1001
+ GetDeviceSession.
1002
+
1003
+ .. code-block:: python
1004
+
1005
+ # This snippet has been automatically generated and should be regarded as a
1006
+ # code template only.
1007
+ # It will require modifications to work:
1008
+ # - It may require correct/in-range values for request initialization.
1009
+ # - It may require specifying regional endpoints when creating the service
1010
+ # client as shown in:
1011
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1012
+ from google.cloud import devicestreaming_v1
1013
+
1014
+ def sample_get_device_session():
1015
+ # Create a client
1016
+ client = devicestreaming_v1.DirectAccessServiceClient()
1017
+
1018
+ # Initialize request argument(s)
1019
+ request = devicestreaming_v1.GetDeviceSessionRequest(
1020
+ name="name_value",
1021
+ )
1022
+
1023
+ # Make the request
1024
+ response = client.get_device_session(request=request)
1025
+
1026
+ # Handle the response
1027
+ print(response)
1028
+
1029
+ Args:
1030
+ request (Union[google.cloud.devicestreaming_v1.types.GetDeviceSessionRequest, dict]):
1031
+ The request object. Request message for
1032
+ DirectAccessService.GetDeviceSession.
1033
+ name (str):
1034
+ Required. Name of the DeviceSession, e.g.
1035
+ "projects/{project_id}/deviceSessions/{session_id}"
1036
+
1037
+ This corresponds to the ``name`` field
1038
+ on the ``request`` instance; if ``request`` is provided, this
1039
+ should not be set.
1040
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1041
+ should be retried.
1042
+ timeout (float): The timeout for this request.
1043
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1044
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1045
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1046
+ be of type `bytes`.
1047
+
1048
+ Returns:
1049
+ google.cloud.devicestreaming_v1.types.DeviceSession:
1050
+ Protobuf message describing the
1051
+ device message, used from several RPCs.
1052
+
1053
+ """
1054
+ # Create or coerce a protobuf request object.
1055
+ # - Quick check: If we got a request object, we should *not* have
1056
+ # gotten any keyword arguments that map to the request.
1057
+ flattened_params = [name]
1058
+ has_flattened_params = (
1059
+ len([param for param in flattened_params if param is not None]) > 0
1060
+ )
1061
+ if request is not None and has_flattened_params:
1062
+ raise ValueError(
1063
+ "If the `request` argument is set, then none of "
1064
+ "the individual field arguments should be set."
1065
+ )
1066
+
1067
+ # - Use the request object if provided (there's no risk of modifying the input as
1068
+ # there are no flattened fields), or create one.
1069
+ if not isinstance(request, service.GetDeviceSessionRequest):
1070
+ request = service.GetDeviceSessionRequest(request)
1071
+ # If we have keyword arguments corresponding to fields on the
1072
+ # request, apply these.
1073
+ if name is not None:
1074
+ request.name = name
1075
+
1076
+ # Wrap the RPC method; this adds retry and timeout information,
1077
+ # and friendly error handling.
1078
+ rpc = self._transport._wrapped_methods[self._transport.get_device_session]
1079
+
1080
+ # Certain fields should be provided within the metadata header;
1081
+ # add these here.
1082
+ metadata = tuple(metadata) + (
1083
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1084
+ )
1085
+
1086
+ # Validate the universe domain.
1087
+ self._validate_universe_domain()
1088
+
1089
+ # Send the request.
1090
+ response = rpc(
1091
+ request,
1092
+ retry=retry,
1093
+ timeout=timeout,
1094
+ metadata=metadata,
1095
+ )
1096
+
1097
+ # Done; return the response.
1098
+ return response
1099
+
1100
+ def cancel_device_session(
1101
+ self,
1102
+ request: Optional[Union[service.CancelDeviceSessionRequest, dict]] = None,
1103
+ *,
1104
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1105
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1106
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1107
+ ) -> None:
1108
+ r"""Cancel a DeviceSession.
1109
+ This RPC changes the DeviceSession to state FINISHED and
1110
+ terminates all connections.
1111
+ Canceled sessions are not deleted and can be retrieved
1112
+ or listed by the user until they expire based on the 28
1113
+ day deletion policy.
1114
+
1115
+ .. code-block:: python
1116
+
1117
+ # This snippet has been automatically generated and should be regarded as a
1118
+ # code template only.
1119
+ # It will require modifications to work:
1120
+ # - It may require correct/in-range values for request initialization.
1121
+ # - It may require specifying regional endpoints when creating the service
1122
+ # client as shown in:
1123
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1124
+ from google.cloud import devicestreaming_v1
1125
+
1126
+ def sample_cancel_device_session():
1127
+ # Create a client
1128
+ client = devicestreaming_v1.DirectAccessServiceClient()
1129
+
1130
+ # Initialize request argument(s)
1131
+ request = devicestreaming_v1.CancelDeviceSessionRequest(
1132
+ name="name_value",
1133
+ )
1134
+
1135
+ # Make the request
1136
+ client.cancel_device_session(request=request)
1137
+
1138
+ Args:
1139
+ request (Union[google.cloud.devicestreaming_v1.types.CancelDeviceSessionRequest, dict]):
1140
+ The request object. Request message for
1141
+ DirectAccessService.CancelDeviceSession.
1142
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1143
+ should be retried.
1144
+ timeout (float): The timeout for this request.
1145
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1146
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1147
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1148
+ be of type `bytes`.
1149
+ """
1150
+ # Create or coerce a protobuf request object.
1151
+ # - Use the request object if provided (there's no risk of modifying the input as
1152
+ # there are no flattened fields), or create one.
1153
+ if not isinstance(request, service.CancelDeviceSessionRequest):
1154
+ request = service.CancelDeviceSessionRequest(request)
1155
+
1156
+ # Wrap the RPC method; this adds retry and timeout information,
1157
+ # and friendly error handling.
1158
+ rpc = self._transport._wrapped_methods[self._transport.cancel_device_session]
1159
+
1160
+ # Certain fields should be provided within the metadata header;
1161
+ # add these here.
1162
+ metadata = tuple(metadata) + (
1163
+ gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
1164
+ )
1165
+
1166
+ # Validate the universe domain.
1167
+ self._validate_universe_domain()
1168
+
1169
+ # Send the request.
1170
+ rpc(
1171
+ request,
1172
+ retry=retry,
1173
+ timeout=timeout,
1174
+ metadata=metadata,
1175
+ )
1176
+
1177
+ def update_device_session(
1178
+ self,
1179
+ request: Optional[Union[service.UpdateDeviceSessionRequest, dict]] = None,
1180
+ *,
1181
+ device_session: Optional[service.DeviceSession] = None,
1182
+ update_mask: Optional[field_mask_pb2.FieldMask] = None,
1183
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1184
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1185
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1186
+ ) -> service.DeviceSession:
1187
+ r"""Updates the current DeviceSession to the fields described by the
1188
+ update_mask.
1189
+
1190
+ .. code-block:: python
1191
+
1192
+ # This snippet has been automatically generated and should be regarded as a
1193
+ # code template only.
1194
+ # It will require modifications to work:
1195
+ # - It may require correct/in-range values for request initialization.
1196
+ # - It may require specifying regional endpoints when creating the service
1197
+ # client as shown in:
1198
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1199
+ from google.cloud import devicestreaming_v1
1200
+
1201
+ def sample_update_device_session():
1202
+ # Create a client
1203
+ client = devicestreaming_v1.DirectAccessServiceClient()
1204
+
1205
+ # Initialize request argument(s)
1206
+ device_session = devicestreaming_v1.DeviceSession()
1207
+ device_session.android_device.android_model_id = "android_model_id_value"
1208
+ device_session.android_device.android_version_id = "android_version_id_value"
1209
+
1210
+ request = devicestreaming_v1.UpdateDeviceSessionRequest(
1211
+ device_session=device_session,
1212
+ )
1213
+
1214
+ # Make the request
1215
+ response = client.update_device_session(request=request)
1216
+
1217
+ # Handle the response
1218
+ print(response)
1219
+
1220
+ Args:
1221
+ request (Union[google.cloud.devicestreaming_v1.types.UpdateDeviceSessionRequest, dict]):
1222
+ The request object. Request message for
1223
+ DirectAccessService.UpdateDeviceSession.
1224
+ device_session (google.cloud.devicestreaming_v1.types.DeviceSession):
1225
+ Required. DeviceSession to update. The DeviceSession's
1226
+ ``name`` field is used to identify the session to update
1227
+ "projects/{project_id}/deviceSessions/{session_id}"
1228
+
1229
+ This corresponds to the ``device_session`` field
1230
+ on the ``request`` instance; if ``request`` is provided, this
1231
+ should not be set.
1232
+ update_mask (google.protobuf.field_mask_pb2.FieldMask):
1233
+ Optional. The list of fields to
1234
+ update.
1235
+
1236
+ This corresponds to the ``update_mask`` field
1237
+ on the ``request`` instance; if ``request`` is provided, this
1238
+ should not be set.
1239
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1240
+ should be retried.
1241
+ timeout (float): The timeout for this request.
1242
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1243
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1244
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1245
+ be of type `bytes`.
1246
+
1247
+ Returns:
1248
+ google.cloud.devicestreaming_v1.types.DeviceSession:
1249
+ Protobuf message describing the
1250
+ device message, used from several RPCs.
1251
+
1252
+ """
1253
+ # Create or coerce a protobuf request object.
1254
+ # - Quick check: If we got a request object, we should *not* have
1255
+ # gotten any keyword arguments that map to the request.
1256
+ flattened_params = [device_session, update_mask]
1257
+ has_flattened_params = (
1258
+ len([param for param in flattened_params if param is not None]) > 0
1259
+ )
1260
+ if request is not None and has_flattened_params:
1261
+ raise ValueError(
1262
+ "If the `request` argument is set, then none of "
1263
+ "the individual field arguments should be set."
1264
+ )
1265
+
1266
+ # - Use the request object if provided (there's no risk of modifying the input as
1267
+ # there are no flattened fields), or create one.
1268
+ if not isinstance(request, service.UpdateDeviceSessionRequest):
1269
+ request = service.UpdateDeviceSessionRequest(request)
1270
+ # If we have keyword arguments corresponding to fields on the
1271
+ # request, apply these.
1272
+ if device_session is not None:
1273
+ request.device_session = device_session
1274
+ if update_mask is not None:
1275
+ request.update_mask = update_mask
1276
+
1277
+ # Wrap the RPC method; this adds retry and timeout information,
1278
+ # and friendly error handling.
1279
+ rpc = self._transport._wrapped_methods[self._transport.update_device_session]
1280
+
1281
+ # Certain fields should be provided within the metadata header;
1282
+ # add these here.
1283
+ metadata = tuple(metadata) + (
1284
+ gapic_v1.routing_header.to_grpc_metadata(
1285
+ (("device_session.name", request.device_session.name),)
1286
+ ),
1287
+ )
1288
+
1289
+ # Validate the universe domain.
1290
+ self._validate_universe_domain()
1291
+
1292
+ # Send the request.
1293
+ response = rpc(
1294
+ request,
1295
+ retry=retry,
1296
+ timeout=timeout,
1297
+ metadata=metadata,
1298
+ )
1299
+
1300
+ # Done; return the response.
1301
+ return response
1302
+
1303
+ def adb_connect(
1304
+ self,
1305
+ requests: Optional[Iterator[adb_service.AdbMessage]] = None,
1306
+ *,
1307
+ retry: OptionalRetry = gapic_v1.method.DEFAULT,
1308
+ timeout: Union[float, object] = gapic_v1.method.DEFAULT,
1309
+ metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
1310
+ ) -> Iterable[adb_service.DeviceMessage]:
1311
+ r"""Exposes an ADB connection if the device supports ADB.
1312
+ gRPC headers are used to authenticate the Connect RPC,
1313
+ as well as associate to a particular DeviceSession.
1314
+ In particular, the user must specify the
1315
+ "X-Omnilab-Session-Name" header.
1316
+
1317
+ .. code-block:: python
1318
+
1319
+ # This snippet has been automatically generated and should be regarded as a
1320
+ # code template only.
1321
+ # It will require modifications to work:
1322
+ # - It may require correct/in-range values for request initialization.
1323
+ # - It may require specifying regional endpoints when creating the service
1324
+ # client as shown in:
1325
+ # https://googleapis.dev/python/google-api-core/latest/client_options.html
1326
+ from google.cloud import devicestreaming_v1
1327
+
1328
+ def sample_adb_connect():
1329
+ # Create a client
1330
+ client = devicestreaming_v1.DirectAccessServiceClient()
1331
+
1332
+ # Initialize request argument(s)
1333
+ open_ = devicestreaming_v1.Open()
1334
+ open_.stream_id = 952
1335
+
1336
+ request = devicestreaming_v1.AdbMessage(
1337
+ open_=open_,
1338
+ )
1339
+
1340
+ # This method expects an iterator which contains
1341
+ # 'devicestreaming_v1.AdbMessage' objects
1342
+ # Here we create a generator that yields a single `request` for
1343
+ # demonstrative purposes.
1344
+ requests = [request]
1345
+
1346
+ def request_generator():
1347
+ for request in requests:
1348
+ yield request
1349
+
1350
+ # Make the request
1351
+ stream = client.adb_connect(requests=request_generator())
1352
+
1353
+ # Handle the response
1354
+ for response in stream:
1355
+ print(response)
1356
+
1357
+ Args:
1358
+ requests (Iterator[google.cloud.devicestreaming_v1.types.AdbMessage]):
1359
+ The request object iterator. A message to an ADB server.
1360
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1361
+ should be retried.
1362
+ timeout (float): The timeout for this request.
1363
+ metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
1364
+ sent along with the request as metadata. Normally, each value must be of type `str`,
1365
+ but for metadata keys ending with the suffix `-bin`, the corresponding values must
1366
+ be of type `bytes`.
1367
+
1368
+ Returns:
1369
+ Iterable[google.cloud.devicestreaming_v1.types.DeviceMessage]:
1370
+ A message returned from a device.
1371
+ """
1372
+
1373
+ # Wrap the RPC method; this adds retry and timeout information,
1374
+ # and friendly error handling.
1375
+ rpc = self._transport._wrapped_methods[self._transport.adb_connect]
1376
+
1377
+ # Validate the universe domain.
1378
+ self._validate_universe_domain()
1379
+
1380
+ # Send the request.
1381
+ response = rpc(
1382
+ requests,
1383
+ retry=retry,
1384
+ timeout=timeout,
1385
+ metadata=metadata,
1386
+ )
1387
+
1388
+ # Done; return the response.
1389
+ return response
1390
+
1391
+ def __enter__(self) -> "DirectAccessServiceClient":
1392
+ return self
1393
+
1394
+ def __exit__(self, type, value, traceback):
1395
+ """Releases underlying transport's resources.
1396
+
1397
+ .. warning::
1398
+ ONLY use as a context manager if the transport is NOT shared
1399
+ with other clients! Exiting the with block will CLOSE the transport
1400
+ and may cause errors in other clients!
1401
+ """
1402
+ self.transport.close()
1403
+
1404
+
1405
+ DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
1406
+ gapic_version=package_version.__version__
1407
+ )
1408
+
1409
+
1410
+ __all__ = ("DirectAccessServiceClient",)