|
6 | 6 | # Changes may cause incorrect behavior and will be lost if the code is regenerated.
|
7 | 7 | # --------------------------------------------------------------------------
|
8 | 8 |
|
9 |
| -from typing import TYPE_CHECKING |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any, Optional, TYPE_CHECKING |
10 | 11 |
|
| 12 | +from azure.core.rest import HttpRequest, HttpResponse |
11 | 13 | from azure.mgmt.core import ARMPipelineClient
|
12 | 14 | from msrest import Deserializer, Serializer
|
13 | 15 |
|
| 16 | +from . import models |
| 17 | +from ._configuration import IotDpsClientConfiguration |
| 18 | +from .operations import DpsCertificateOperations, IotDpsResourceOperations, Operations |
| 19 | + |
14 | 20 | if TYPE_CHECKING:
|
15 | 21 | # pylint: disable=unused-import,ungrouped-imports
|
16 |
| - from typing import Any, Optional |
17 |
| - |
18 | 22 | from azure.core.credentials import TokenCredential
|
19 |
| - from azure.core.pipeline.transport import HttpRequest, HttpResponse |
20 |
| - |
21 |
| -from ._configuration import IotDpsClientConfiguration |
22 |
| -from .operations import Operations |
23 |
| -from .operations import DpsCertificateOperations |
24 |
| -from .operations import IotDpsResourceOperations |
25 |
| -from . import models |
26 | 23 |
|
27 |
| - |
28 |
| -class IotDpsClient(object): |
| 24 | +class IotDpsClient: |
29 | 25 | """API for using the Azure IoT Hub Device Provisioning Service features.
|
30 | 26 |
|
31 | 27 | :ivar operations: Operations operations
|
32 | 28 | :vartype operations: azure.mgmt.iothubprovisioningservices.operations.Operations
|
33 | 29 | :ivar dps_certificate: DpsCertificateOperations operations
|
34 |
| - :vartype dps_certificate: azure.mgmt.iothubprovisioningservices.operations.DpsCertificateOperations |
| 30 | + :vartype dps_certificate: |
| 31 | + azure.mgmt.iothubprovisioningservices.operations.DpsCertificateOperations |
35 | 32 | :ivar iot_dps_resource: IotDpsResourceOperations operations
|
36 |
| - :vartype iot_dps_resource: azure.mgmt.iothubprovisioningservices.operations.IotDpsResourceOperations |
| 33 | + :vartype iot_dps_resource: |
| 34 | + azure.mgmt.iothubprovisioningservices.operations.IotDpsResourceOperations |
37 | 35 | :param credential: Credential needed for the client to connect to Azure.
|
38 | 36 | :type credential: ~azure.core.credentials.TokenCredential
|
39 | 37 | :param subscription_id: The subscription identifier.
|
40 | 38 | :type subscription_id: str
|
41 |
| - :param str base_url: Service URL |
42 |
| - :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present. |
| 39 | + :param base_url: Service URL. Default value is 'https://management.azure.com'. |
| 40 | + :type base_url: str |
| 41 | + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
| 42 | + Retry-After header is present. |
43 | 43 | """
|
44 | 44 |
|
45 | 45 | def __init__(
|
46 | 46 | self,
|
47 |
| - credential, # type: "TokenCredential" |
48 |
| - subscription_id, # type: str |
49 |
| - base_url=None, # type: Optional[str] |
50 |
| - **kwargs # type: Any |
51 |
| - ): |
52 |
| - # type: (...) -> None |
53 |
| - if not base_url: |
54 |
| - base_url = 'https://management.azure.com' |
55 |
| - self._config = IotDpsClientConfiguration(credential, subscription_id, **kwargs) |
| 47 | + credential: "TokenCredential", |
| 48 | + subscription_id: str, |
| 49 | + base_url: str = "https://management.azure.com", |
| 50 | + **kwargs: Any |
| 51 | + ) -> None: |
| 52 | + self._config = IotDpsClientConfiguration(credential=credential, subscription_id=subscription_id, **kwargs) |
56 | 53 | self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
|
57 | 54 |
|
58 | 55 | client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
|
59 | 56 | self._serialize = Serializer(client_models)
|
60 |
| - self._serialize.client_side_validation = False |
61 | 57 | self._deserialize = Deserializer(client_models)
|
| 58 | + self._serialize.client_side_validation = False |
| 59 | + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) |
| 60 | + self.dps_certificate = DpsCertificateOperations(self._client, self._config, self._serialize, self._deserialize) |
| 61 | + self.iot_dps_resource = IotDpsResourceOperations(self._client, self._config, self._serialize, self._deserialize) |
62 | 62 |
|
63 |
| - self.operations = Operations( |
64 |
| - self._client, self._config, self._serialize, self._deserialize) |
65 |
| - self.dps_certificate = DpsCertificateOperations( |
66 |
| - self._client, self._config, self._serialize, self._deserialize) |
67 |
| - self.iot_dps_resource = IotDpsResourceOperations( |
68 |
| - self._client, self._config, self._serialize, self._deserialize) |
69 | 63 |
|
70 |
| - def _send_request(self, http_request, **kwargs): |
71 |
| - # type: (HttpRequest, Any) -> HttpResponse |
| 64 | + def _send_request( |
| 65 | + self, |
| 66 | + request, # type: HttpRequest |
| 67 | + **kwargs: Any |
| 68 | + ) -> HttpResponse: |
72 | 69 | """Runs the network request through the client's chained policies.
|
73 | 70 |
|
74 |
| - :param http_request: The network request you want to make. Required. |
75 |
| - :type http_request: ~azure.core.pipeline.transport.HttpRequest |
76 |
| - :keyword bool stream: Whether the response payload will be streamed. Defaults to True. |
| 71 | + >>> from azure.core.rest import HttpRequest |
| 72 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 73 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 74 | + >>> response = client._send_request(request) |
| 75 | + <HttpResponse: 200 OK> |
| 76 | +
|
| 77 | + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart |
| 78 | +
|
| 79 | + :param request: The network request you want to make. Required. |
| 80 | + :type request: ~azure.core.rest.HttpRequest |
| 81 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
77 | 82 | :return: The response of your network call. Does not do error handling on your response.
|
78 |
| - :rtype: ~azure.core.pipeline.transport.HttpResponse |
| 83 | + :rtype: ~azure.core.rest.HttpResponse |
79 | 84 | """
|
80 |
| - path_format_arguments = { |
81 |
| - 'subscriptionId': self._serialize.url("self._config.subscription_id", self._config.subscription_id, 'str'), |
82 |
| - } |
83 |
| - http_request.url = self._client.format_url(http_request.url, **path_format_arguments) |
84 |
| - stream = kwargs.pop("stream", True) |
85 |
| - pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) |
86 |
| - return pipeline_response.http_response |
| 85 | + |
| 86 | + request_copy = deepcopy(request) |
| 87 | + request_copy.url = self._client.format_url(request_copy.url) |
| 88 | + return self._client.send_request(request_copy, **kwargs) |
87 | 89 |
|
88 | 90 | def close(self):
|
89 | 91 | # type: () -> None
|
|
0 commit comments