|
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, TYPE_CHECKING |
10 | 11 |
|
| 12 | +from azure.core.rest import HttpRequest, HttpResponse |
11 | 13 | from azure.mgmt.core import ARMPipelineClient |
12 | | -from msrest import Deserializer, Serializer |
| 14 | + |
| 15 | +from . import models |
| 16 | +from ._configuration import ResourceGraphClientConfiguration |
| 17 | +from ._serialization import Deserializer, Serializer |
| 18 | +from .operations import Operations, ResourceGraphClientOperationsMixin |
13 | 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 ResourceGraphClientConfiguration |
22 | | -from .operations import ResourceGraphClientOperationsMixin |
23 | | -from .operations import Operations |
24 | | -from . import models |
25 | 23 |
|
26 | 24 |
|
27 | | -class ResourceGraphClient(ResourceGraphClientOperationsMixin): |
| 25 | +class ResourceGraphClient(ResourceGraphClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword |
28 | 26 | """Azure Resource Graph API Reference. |
29 | 27 |
|
30 | 28 | :ivar operations: Operations operations |
31 | 29 | :vartype operations: azure.mgmt.resourcegraph.operations.Operations |
32 | | - :param credential: Credential needed for the client to connect to Azure. |
| 30 | + :param credential: Credential needed for the client to connect to Azure. Required. |
33 | 31 | :type credential: ~azure.core.credentials.TokenCredential |
34 | | - :param str base_url: Service URL |
| 32 | + :param base_url: Service URL. Default value is "https://management.azure.com". |
| 33 | + :type base_url: str |
35 | 34 | """ |
36 | 35 |
|
37 | 36 | def __init__( |
38 | | - self, |
39 | | - credential, # type: "TokenCredential" |
40 | | - base_url=None, # type: Optional[str] |
41 | | - **kwargs # type: Any |
42 | | - ): |
43 | | - # type: (...) -> None |
44 | | - if not base_url: |
45 | | - base_url = 'https://management.azure.com' |
46 | | - self._config = ResourceGraphClientConfiguration(credential, **kwargs) |
| 37 | + self, credential: "TokenCredential", base_url: str = "https://management.azure.com", **kwargs: Any |
| 38 | + ) -> None: |
| 39 | + self._config = ResourceGraphClientConfiguration(credential=credential, **kwargs) |
47 | 40 | self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) |
48 | 41 |
|
49 | 42 | client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} |
50 | 43 | self._serialize = Serializer(client_models) |
51 | | - self._serialize.client_side_validation = False |
52 | 44 | self._deserialize = Deserializer(client_models) |
| 45 | + self._serialize.client_side_validation = False |
| 46 | + self.operations = Operations(self._client, self._config, self._serialize, self._deserialize) |
53 | 47 |
|
54 | | - self.operations = Operations( |
55 | | - self._client, self._config, self._serialize, self._deserialize) |
56 | | - |
57 | | - def _send_request(self, http_request, **kwargs): |
58 | | - # type: (HttpRequest, Any) -> HttpResponse |
| 48 | + def _send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: |
59 | 49 | """Runs the network request through the client's chained policies. |
60 | 50 |
|
61 | | - :param http_request: The network request you want to make. Required. |
62 | | - :type http_request: ~azure.core.pipeline.transport.HttpRequest |
63 | | - :keyword bool stream: Whether the response payload will be streamed. Defaults to True. |
| 51 | + >>> from azure.core.rest import HttpRequest |
| 52 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 53 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 54 | + >>> response = client._send_request(request) |
| 55 | + <HttpResponse: 200 OK> |
| 56 | +
|
| 57 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 58 | +
|
| 59 | + :param request: The network request you want to make. Required. |
| 60 | + :type request: ~azure.core.rest.HttpRequest |
| 61 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
64 | 62 | :return: The response of your network call. Does not do error handling on your response. |
65 | | - :rtype: ~azure.core.pipeline.transport.HttpResponse |
| 63 | + :rtype: ~azure.core.rest.HttpResponse |
66 | 64 | """ |
67 | | - http_request.url = self._client.format_url(http_request.url) |
68 | | - stream = kwargs.pop("stream", True) |
69 | | - pipeline_response = self._client._pipeline.run(http_request, stream=stream, **kwargs) |
70 | | - return pipeline_response.http_response |
| 65 | + |
| 66 | + request_copy = deepcopy(request) |
| 67 | + request_copy.url = self._client.format_url(request_copy.url) |
| 68 | + return self._client.send_request(request_copy, **kwargs) |
71 | 69 |
|
72 | 70 | def close(self): |
73 | 71 | # type: () -> None |
|
0 commit comments