|
| 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, Union |
| 11 | + |
| 12 | +from azure.core import PipelineClient |
| 13 | +from azure.core.credentials import AzureKeyCredential |
| 14 | +from azure.core.pipeline import policies |
| 15 | +from azure.core.rest import HttpRequest, HttpResponse |
| 16 | + |
| 17 | +from ._configuration import EventGridConsumerClientConfiguration, EventGridPublisherClientConfiguration |
| 18 | +from ._operations import EventGridConsumerClientOperationsMixin, EventGridPublisherClientOperationsMixin |
| 19 | +from ._serialization import Deserializer, Serializer |
| 20 | + |
| 21 | +if TYPE_CHECKING: |
| 22 | + # pylint: disable=unused-import,ungrouped-imports |
| 23 | + from azure.core.credentials import TokenCredential |
| 24 | + |
| 25 | + |
| 26 | +class EventGridPublisherClient( |
| 27 | + EventGridPublisherClientOperationsMixin |
| 28 | +): # pylint: disable=client-accepts-api-version-keyword |
| 29 | + """EventGridPublisherClient. |
| 30 | +
|
| 31 | + :param endpoint: The host name of the namespace, e.g. |
| 32 | + namespaceName1.westus-1.eventgrid.azure.net. Required. |
| 33 | + :type endpoint: str |
| 34 | + :param credential: Credential used to authenticate requests to the service. Is either a |
| 35 | + AzureKeyCredential type or a TokenCredential type. Required. |
| 36 | + :type credential: ~azure.core.credentials.AzureKeyCredential or |
| 37 | + ~azure.core.credentials.TokenCredential |
| 38 | + :keyword api_version: The API version to use for this operation. Default value is "2024-06-01". |
| 39 | + Note that overriding this default value may result in unsupported behavior. |
| 40 | + :paramtype api_version: str |
| 41 | + """ |
| 42 | + |
| 43 | + def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: |
| 44 | + _endpoint = "{endpoint}" |
| 45 | + self._config = EventGridPublisherClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) |
| 46 | + _policies = kwargs.pop("policies", None) |
| 47 | + if _policies is None: |
| 48 | + _policies = [ |
| 49 | + policies.RequestIdPolicy(**kwargs), |
| 50 | + self._config.headers_policy, |
| 51 | + self._config.user_agent_policy, |
| 52 | + self._config.proxy_policy, |
| 53 | + policies.ContentDecodePolicy(**kwargs), |
| 54 | + self._config.redirect_policy, |
| 55 | + self._config.retry_policy, |
| 56 | + self._config.authentication_policy, |
| 57 | + self._config.custom_hook_policy, |
| 58 | + self._config.logging_policy, |
| 59 | + policies.DistributedTracingPolicy(**kwargs), |
| 60 | + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, |
| 61 | + self._config.http_logging_policy, |
| 62 | + ] |
| 63 | + self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) |
| 64 | + |
| 65 | + self._serialize = Serializer() |
| 66 | + self._deserialize = Deserializer() |
| 67 | + self._serialize.client_side_validation = False |
| 68 | + |
| 69 | + def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: |
| 70 | + """Runs the network request through the client's chained policies. |
| 71 | +
|
| 72 | + >>> from azure.core.rest import HttpRequest |
| 73 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 74 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 75 | + >>> response = client.send_request(request) |
| 76 | + <HttpResponse: 200 OK> |
| 77 | +
|
| 78 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 79 | +
|
| 80 | + :param request: The network request you want to make. Required. |
| 81 | + :type request: ~azure.core.rest.HttpRequest |
| 82 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 83 | + :return: The response of your network call. Does not do error handling on your response. |
| 84 | + :rtype: ~azure.core.rest.HttpResponse |
| 85 | + """ |
| 86 | + |
| 87 | + request_copy = deepcopy(request) |
| 88 | + path_format_arguments = { |
| 89 | + "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), |
| 90 | + } |
| 91 | + |
| 92 | + request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) |
| 93 | + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore |
| 94 | + |
| 95 | + def close(self) -> None: |
| 96 | + self._client.close() |
| 97 | + |
| 98 | + def __enter__(self) -> "EventGridPublisherClient": |
| 99 | + self._client.__enter__() |
| 100 | + return self |
| 101 | + |
| 102 | + def __exit__(self, *exc_details: Any) -> None: |
| 103 | + self._client.__exit__(*exc_details) |
| 104 | + |
| 105 | + |
| 106 | +class EventGridConsumerClient( |
| 107 | + EventGridConsumerClientOperationsMixin |
| 108 | +): # pylint: disable=client-accepts-api-version-keyword |
| 109 | + """EventGridConsumerClient. |
| 110 | +
|
| 111 | + :param endpoint: The host name of the namespace, e.g. |
| 112 | + namespaceName1.westus-1.eventgrid.azure.net. Required. |
| 113 | + :type endpoint: str |
| 114 | + :param credential: Credential used to authenticate requests to the service. Is either a |
| 115 | + AzureKeyCredential type or a TokenCredential type. Required. |
| 116 | + :type credential: ~azure.core.credentials.AzureKeyCredential or |
| 117 | + ~azure.core.credentials.TokenCredential |
| 118 | + :keyword api_version: The API version to use for this operation. Default value is "2024-06-01". |
| 119 | + Note that overriding this default value may result in unsupported behavior. |
| 120 | + :paramtype api_version: str |
| 121 | + """ |
| 122 | + |
| 123 | + def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None: |
| 124 | + _endpoint = "{endpoint}" |
| 125 | + self._config = EventGridConsumerClientConfiguration(endpoint=endpoint, credential=credential, **kwargs) |
| 126 | + _policies = kwargs.pop("policies", None) |
| 127 | + if _policies is None: |
| 128 | + _policies = [ |
| 129 | + policies.RequestIdPolicy(**kwargs), |
| 130 | + self._config.headers_policy, |
| 131 | + self._config.user_agent_policy, |
| 132 | + self._config.proxy_policy, |
| 133 | + policies.ContentDecodePolicy(**kwargs), |
| 134 | + self._config.redirect_policy, |
| 135 | + self._config.retry_policy, |
| 136 | + self._config.authentication_policy, |
| 137 | + self._config.custom_hook_policy, |
| 138 | + self._config.logging_policy, |
| 139 | + policies.DistributedTracingPolicy(**kwargs), |
| 140 | + policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None, |
| 141 | + self._config.http_logging_policy, |
| 142 | + ] |
| 143 | + self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs) |
| 144 | + |
| 145 | + self._serialize = Serializer() |
| 146 | + self._deserialize = Deserializer() |
| 147 | + self._serialize.client_side_validation = False |
| 148 | + |
| 149 | + def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse: |
| 150 | + """Runs the network request through the client's chained policies. |
| 151 | +
|
| 152 | + >>> from azure.core.rest import HttpRequest |
| 153 | + >>> request = HttpRequest("GET", "https://www.example.org/") |
| 154 | + <HttpRequest [GET], url: 'https://www.example.org/'> |
| 155 | + >>> response = client.send_request(request) |
| 156 | + <HttpResponse: 200 OK> |
| 157 | +
|
| 158 | + For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request |
| 159 | +
|
| 160 | + :param request: The network request you want to make. Required. |
| 161 | + :type request: ~azure.core.rest.HttpRequest |
| 162 | + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. |
| 163 | + :return: The response of your network call. Does not do error handling on your response. |
| 164 | + :rtype: ~azure.core.rest.HttpResponse |
| 165 | + """ |
| 166 | + |
| 167 | + request_copy = deepcopy(request) |
| 168 | + path_format_arguments = { |
| 169 | + "endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True), |
| 170 | + } |
| 171 | + |
| 172 | + request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments) |
| 173 | + return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore |
| 174 | + |
| 175 | + def close(self) -> None: |
| 176 | + self._client.close() |
| 177 | + |
| 178 | + def __enter__(self) -> "EventGridConsumerClient": |
| 179 | + self._client.__enter__() |
| 180 | + return self |
| 181 | + |
| 182 | + def __exit__(self, *exc_details: Any) -> None: |
| 183 | + self._client.__exit__(*exc_details) |
0 commit comments