|
| 1 | +# coding=utf-8 |
| 2 | +# -------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 5 | +# Code generated by Microsoft (R) Python Code Generator. |
| 6 | +# Changes may cause incorrect behavior and will be lost if the code is regenerated. |
| 7 | +# -------------------------------------------------------------------------- |
| 8 | + |
| 9 | +from copy import deepcopy |
| 10 | +from typing import Any, TYPE_CHECKING |
| 11 | +from typing_extensions import Self |
| 12 | + |
| 13 | +from azure.core import PipelineClient |
| 14 | +from azure.core.pipeline import policies |
| 15 | +from azure.core.rest import HttpRequest, HttpResponse |
| 16 | + |
| 17 | +from ._configuration import DataApiClientConfiguration |
| 18 | +from ._utils.serialization import Deserializer, Serializer |
| 19 | +from .operations import ( |
| 20 | + ApiDefinitionsOperations, |
| 21 | + ApiDeploymentsOperations, |
| 22 | + ApiVersionsOperations, |
| 23 | + ApisOperations, |
| 24 | + EnvironmentsOperations, |
| 25 | +) |
| 26 | + |
| 27 | +if TYPE_CHECKING: |
| 28 | + from azure.core.credentials import TokenCredential |
| 29 | + |
| 30 | + |
| 31 | +class DataApiClient: |
| 32 | + """Data API introduces endpoints to manage your API Center resources. |
| 33 | +
|
| 34 | + :ivar apis: ApisOperations operations |
| 35 | + :vartype apis: azure.apicenter.operations.ApisOperations |
| 36 | + :ivar api_definitions: ApiDefinitionsOperations operations |
| 37 | + :vartype api_definitions: azure.apicenter.operations.ApiDefinitionsOperations |
| 38 | + :ivar api_deployments: ApiDeploymentsOperations operations |
| 39 | + :vartype api_deployments: azure.apicenter.operations.ApiDeploymentsOperations |
| 40 | + :ivar environments: EnvironmentsOperations operations |
| 41 | + :vartype environments: azure.apicenter.operations.EnvironmentsOperations |
| 42 | + :ivar api_versions: ApiVersionsOperations operations |
| 43 | + :vartype api_versions: azure.apicenter.operations.ApiVersionsOperations |
| 44 | + :param service_name: Region-unique API Center service name. Required. |
| 45 | + :type service_name: str |
| 46 | + :param region: Region name. Required. |
| 47 | + :type region: str |
| 48 | + :param credential: Credential used to authenticate requests to the service. Required. |
| 49 | + :type credential: ~azure.core.credentials.TokenCredential |
| 50 | + :keyword api_version: The API version to use for this operation. Default value is |
| 51 | + "2024-02-01-preview". Note that overriding this default value may result in unsupported |
| 52 | + behavior. |
| 53 | + :paramtype api_version: str |
| 54 | + :keyword int polling_interval: Default waiting time between two polls for LRO operations if no |
| 55 | + Retry-After header is present. |
| 56 | + """ |
| 57 | + |
| 58 | + def __init__(self, service_name: str, region: str, credential: "TokenCredential", **kwargs: Any) -> None: |
| 59 | + _endpoint = "https://{serviceName}.data.{region}.azure-apicenter.ms" |
| 60 | + self._config = DataApiClientConfiguration( |
| 61 | + service_name=service_name, region=region, credential=credential, **kwargs |
| 62 | + ) |
| 63 | + |
| 64 | + _policies = kwargs.pop("policies", None) |
| 65 | + if _policies is None: |
| 66 | + _policies = [ |
| 67 | + policies.RequestIdPolicy(**kwargs), |
| 68 | + self._config.headers_policy, |
| 69 | + self._config.user_agent_policy, |
| 70 | + self._config.proxy_policy, |
| 71 | + policies.ContentDecodePolicy(**kwargs), |
| 72 | + self._config.redirect_policy, |
| 73 | + self._config.retry_policy, |
| 74 | + self._config.authentication_policy, |
| 75 | + self._config.custom_hook_policy, |
| 76 | + self._config.logging_policy, |
| 77 | + policies.DistributedTracingPolicy(**kwargs), |
| 78 | + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, |
| 79 | + self._config.http_logging_policy, |
| 80 | + ] |
| 81 | + self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) |
| 82 | + |
| 83 | + self._serialize = Serializer() |
| 84 | + self._deserialize = Deserializer() |
| 85 | + self._serialize.client_side_validation = False |
| 86 | + self.apis = ApisOperations(self._client, self._config, self._serialize, self._deserialize) |
| 87 | + self.api_definitions = ApiDefinitionsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 88 | + self.api_deployments = ApiDeploymentsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 89 | + self.environments = EnvironmentsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 90 | + self.api_versions = ApiVersionsOperations(self._client, self._config, self._serialize, self._deserialize) |
| 91 | + |
| 92 | + def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: |
| 93 | + """Runs the network request through the client's chained policies. |
| 94 | +
|
| 95 | + >>> from azure.core.rest import HttpRequest |
| 96 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 97 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 98 | + >>> response = client.send_request(request) |
| 99 | + <HttpResponse: 200 OK> |
| 100 | +
|
| 101 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 102 | +
|
| 103 | + :param request: The network request you want to make. Required. |
| 104 | + :type request: ~azure.core.rest.HttpRequest |
| 105 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 106 | + :return: The response of your network call. Does not do error handling on your response. |
| 107 | + :rtype: ~azure.core.rest.HttpResponse |
| 108 | + """ |
| 109 | + |
| 110 | + request_copy = deepcopy(request) |
| 111 | + path_format_arguments = { |
| 112 | + "serviceName": self._serialize.url("self._config.service_name", self._config.service_name, "str"), |
| 113 | + "region": self._serialize.url("self._config.region", self._config.region, "str"), |
| 114 | + } |
| 115 | + |
| 116 | + request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) |
| 117 | + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore |
| 118 | + |
| 119 | + def close(self) -> None: |
| 120 | + self._client.close() |
| 121 | + |
| 122 | + def __enter__(self) -> Self: |
| 123 | + self._client.__enter__() |
| 124 | + return self |
| 125 | + |
| 126 | + def __exit__(self, *exc_details: Any) -> None: |
| 127 | + self._client.__exit__(*exc_details) |
0 commit comments