From 30094d631e062ab72d7a8e31127f608489955acb Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 1 Mar 2022 17:23:08 -0500 Subject: [PATCH 1/7] regenerate error with secrets --- tasks.py | 1 + .../errorwithsecrets/__init__.py | 19 ++ .../errorwithsecrets/_configuration.py | 49 ++++ .../errorwithsecrets/_errorwith_secrets.py | 86 +++++++ .../errorwithsecrets/_patch.py | 31 +++ .../errorwithsecrets/_vendor.py | 16 ++ .../errorwithsecrets/_version.py | 9 + .../errorwithsecrets/aio/__init__.py | 17 ++ .../errorwithsecrets/aio/_configuration.py | 39 ++++ .../aio/_errorwith_secrets.py | 68 ++++++ .../errorwithsecrets/aio/_patch.py | 31 +++ .../aio/operations/__init__.py | 13 ++ .../_errorwith_secrets_operations.py | 105 +++++++++ .../errorwithsecrets/models/__init__.py | 32 +++ .../models/_errorwith_secrets_enums.py | 25 ++ .../errorwithsecrets/models/_models.py | 191 ++++++++++++++++ .../errorwithsecrets/models/_models_py3.py | 213 ++++++++++++++++++ .../errorwithsecrets/operations/__init__.py | 13 ++ .../_errorwith_secrets_operations.py | 156 +++++++++++++ .../errorwithsecrets/py.typed | 1 + .../AcceptanceTests/ErrorWithSecrets/setup.py | 37 +++ .../errorwithsecretslowlevel/__init__.py | 19 ++ .../_configuration.py | 42 ++++ .../_errorwith_secrets.py | 76 +++++++ .../errorwithsecretslowlevel/_patch.py | 31 +++ .../errorwithsecretslowlevel/_version.py | 9 + .../errorwithsecretslowlevel/aio/__init__.py | 17 ++ .../aio/_configuration.py | 39 ++++ .../aio/_errorwith_secrets.py | 72 ++++++ .../errorwithsecretslowlevel/aio/_patch.py | 31 +++ .../errorwithsecretslowlevel/py.typed | 1 + .../errorwithsecretslowlevel/rest/__init__.py | 19 ++ .../rest/_request_builders.py | 91 ++++++++ .../rest/_request_builders_py3.py | 70 ++++++ .../ErrorWithSecretsLowLevel/setup.py | 37 +++ .../__init__.py | 19 ++ .../_configuration.py | 42 ++++ .../_errorwith_secrets.py | 74 ++++++ .../_operations/__init__.py | 13 ++ .../_operations/_operations.py | 126 +++++++++++ .../errorwithsecretsversiontolerant/_patch.py | 31 +++ .../_version.py | 9 + .../aio/__init__.py | 17 ++ .../aio/_configuration.py | 39 ++++ .../aio/_errorwith_secrets.py | 70 ++++++ .../aio/_operations/__init__.py | 13 ++ .../aio/_operations/_operations.py | 99 ++++++++ .../aio/_patch.py | 31 +++ .../errorwithsecretsversiontolerant/py.typed | 1 + .../ErrorWithSecretsVersionTolerant/setup.py | 37 +++ 50 files changed, 2327 insertions(+) create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/__init__.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_configuration.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_errorwith_secrets.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_patch.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_vendor.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_version.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/__init__.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_configuration.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_errorwith_secrets.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_patch.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/__init__.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/_errorwith_secrets_operations.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/__init__.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_errorwith_secrets_enums.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models_py3.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/__init__.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/_errorwith_secrets_operations.py create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/py.typed create mode 100644 test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/__init__.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_configuration.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_errorwith_secrets.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_patch.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_version.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/__init__.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_configuration.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_errorwith_secrets.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_patch.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/py.typed create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/__init__.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders_py3.py create mode 100644 test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/setup.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/__init__.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_configuration.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_errorwith_secrets.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/__init__.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/_operations.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_patch.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_version.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/__init__.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_configuration.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_errorwith_secrets.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/__init__.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/_operations.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_patch.py create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/py.typed create mode 100644 test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py diff --git a/tasks.py b/tasks.py index b10b0101bb3..eb603a6ca60 100644 --- a/tasks.py +++ b/tasks.py @@ -42,6 +42,7 @@ class _SwaggerGroup(Enum): 'BodyNumber': 'body-number.json', 'BodyString': 'body-string.json', 'BodyTime': 'body-time.json', + 'ErrorWithSecrets': 'error-with-secrets.json', 'ExtensibleEnums': 'extensible-enums-swagger.json', 'Header': 'header.json', 'Http': 'httpInfrastructure.json', diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/__init__.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/__init__.py new file mode 100644 index 00000000000..bf7f7437fd8 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/__init__.py @@ -0,0 +1,19 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets import ErrorWithSecrets +from ._version import VERSION + +__version__ = VERSION +__all__ = ["ErrorWithSecrets"] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk + +patch_sdk() diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_configuration.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_configuration.py new file mode 100644 index 00000000000..87ca88cf597 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_configuration.py @@ -0,0 +1,49 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import TYPE_CHECKING + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from ._version import VERSION + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any + + +class ErrorWithSecretsConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for ErrorWithSecrets. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__( + self, **kwargs # type: Any + ): + # type: (...) -> None + super(ErrorWithSecretsConfiguration, self).__init__(**kwargs) + + kwargs.setdefault("sdk_moniker", "errorwithsecrets/{}".format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, **kwargs # type: Any + ): + # type: (...) -> None + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get("authentication_policy") diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_errorwith_secrets.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_errorwith_secrets.py new file mode 100644 index 00000000000..e3e61476488 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_errorwith_secrets.py @@ -0,0 +1,86 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import TYPE_CHECKING + +from msrest import Deserializer, Serializer + +from azure.core import PipelineClient + +from . import models +from ._configuration import ErrorWithSecretsConfiguration +from .operations import ErrorWithSecretsOperationsMixin + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any + + from azure.core.rest import HttpRequest, HttpResponse + + +class ErrorWithSecrets(ErrorWithSecretsOperationsMixin): + """Tests whether loggers/tracers redact secrets and PII within error responses. + + :param base_url: Service URL. Default value is "http://localhost:3000". + :type base_url: str + """ + + def __init__( + self, + base_url="http://localhost:3000", # type: str + **kwargs # type: Any + ): + # type: (...) -> None + self._config = ErrorWithSecretsConfiguration(**kwargs) + self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + + def _send_request( + self, + request, # type: HttpRequest + **kwargs # type: Any + ): + # type: (...) -> HttpResponse + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> ErrorWithSecrets + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_patch.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_patch.py new file mode 100644 index 00000000000..f99e77fef98 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_vendor.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_vendor.py new file mode 100644 index 00000000000..0dafe0e287f --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_vendor.py @@ -0,0 +1,16 @@ +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.core.pipeline.transport import HttpRequest + + +def _convert_request(request, files=None): + data = request.content if not files else None + request = HttpRequest(method=request.method, url=request.url, headers=request.headers, data=data) + if files: + request.set_formdata_body(files) + return request diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_version.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_version.py new file mode 100644 index 00000000000..eae7c95b6fb --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "0.1.0" diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/__init__.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/__init__.py new file mode 100644 index 00000000000..57ab186755a --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/__init__.py @@ -0,0 +1,17 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets import ErrorWithSecrets + +__all__ = ["ErrorWithSecrets"] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk + +patch_sdk() diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_configuration.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_configuration.py new file mode 100644 index 00000000000..1994309507d --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_configuration.py @@ -0,0 +1,39 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from .._version import VERSION + + +class ErrorWithSecretsConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for ErrorWithSecrets. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__(self, **kwargs: Any) -> None: + super(ErrorWithSecretsConfiguration, self).__init__(**kwargs) + + kwargs.setdefault("sdk_moniker", "errorwithsecrets/{}".format(VERSION)) + self._configure(**kwargs) + + def _configure(self, **kwargs: Any) -> None: + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get("authentication_policy") diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_errorwith_secrets.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_errorwith_secrets.py new file mode 100644 index 00000000000..6ccb1a7f90d --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_errorwith_secrets.py @@ -0,0 +1,68 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, Awaitable + +from msrest import Deserializer, Serializer + +from azure.core import AsyncPipelineClient +from azure.core.rest import AsyncHttpResponse, HttpRequest + +from .. import models +from ._configuration import ErrorWithSecretsConfiguration +from .operations import ErrorWithSecretsOperationsMixin + + +class ErrorWithSecrets(ErrorWithSecretsOperationsMixin): + """Tests whether loggers/tracers redact secrets and PII within error responses. + + :param base_url: Service URL. Default value is "http://localhost:3000". + :type base_url: str + """ + + def __init__(self, base_url: str = "http://localhost:3000", **kwargs: Any) -> None: + self._config = ErrorWithSecretsConfiguration(**kwargs) + self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs) + + client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} + self._serialize = Serializer(client_models) + self._deserialize = Deserializer(client_models) + self._serialize.client_side_validation = False + + def _send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = await client._send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "ErrorWithSecrets": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details) -> None: + await self._client.__aexit__(*exc_details) diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_patch.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_patch.py new file mode 100644 index 00000000000..f99e77fef98 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/__init__.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/__init__.py new file mode 100644 index 00000000000..9e69b0ddd50 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/__init__.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets_operations import ErrorWithSecretsOperationsMixin + +__all__ = [ + "ErrorWithSecretsOperationsMixin", +] diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/_errorwith_secrets_operations.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/_errorwith_secrets_operations.py new file mode 100644 index 00000000000..4ecce4b24bf --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/aio/operations/_errorwith_secrets_operations.py @@ -0,0 +1,105 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Callable, Dict, Optional, TypeVar + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator_async import distributed_trace_async + +from ... import models as _models +from ..._vendor import _convert_request +from ...operations._errorwith_secrets_operations import ( + build_create_secret_request, + build_get_error_with_secrets_request, +) + +T = TypeVar("T") +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class ErrorWithSecretsOperationsMixin: + @distributed_trace_async + async def create_secret(self, **kwargs: Any) -> "_models.SecretResponse": + """Creates a secret. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SecretResponse, or the result of cls(response) + :rtype: ~errorwithsecrets.models.SecretResponse + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop("cls", None) # type: ClsType["_models.SecretResponse"] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_create_secret_request( + template_url=self.create_secret.metadata["url"], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("SecretResponse", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + create_secret.metadata = {"url": "/secrets/:create"} # type: ignore + + @distributed_trace_async + async def get_error_with_secrets(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements + """Gets an error response containing secrets and PII. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None, or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop("cls", None) # type: ClsType[None] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_get_error_with_secrets_request( + template_url=self.get_error_with_secrets.metadata["url"], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + get_error_with_secrets.metadata = {"url": "/secrets/error"} # type: ignore diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/__init__.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/__init__.py new file mode 100644 index 00000000000..e0c128c22e7 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/__init__.py @@ -0,0 +1,32 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +try: + from ._models_py3 import Error + from ._models_py3 import ErrorResponse + from ._models_py3 import InnerError + from ._models_py3 import SecretResponse +except (SyntaxError, ImportError): + from ._models import Error # type: ignore + from ._models import ErrorResponse # type: ignore + from ._models import InnerError # type: ignore + from ._models import SecretResponse # type: ignore + +from ._errorwith_secrets_enums import ( + ErrorCode, + InnerErrorCode, +) + +__all__ = [ + "Error", + "ErrorResponse", + "InnerError", + "SecretResponse", + "ErrorCode", + "InnerErrorCode", +] diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_errorwith_secrets_enums.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_errorwith_secrets_enums.py new file mode 100644 index 00000000000..f8ea2258b0f --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_errorwith_secrets_enums.py @@ -0,0 +1,25 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from enum import Enum +from six import with_metaclass +from azure.core import CaseInsensitiveEnumMeta + + +class ErrorCode(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """Human-readable error code.""" + + BAD_PARAMETER = "BadParameter" + UNAUTHORIZED = "Unauthorized" + + +class InnerErrorCode(with_metaclass(CaseInsensitiveEnumMeta, str, Enum)): + """Human-readable error code.""" + + MISSING_SHARED_KEY = "MissingSharedKey" + UNAUTHORIZED_SHARED_KEY = "UnauthorizedSharedKey" diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models.py new file mode 100644 index 00000000000..9d49eb7d6ef --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models.py @@ -0,0 +1,191 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from azure.core.exceptions import HttpResponseError +import msrest.serialization + + +class Error(msrest.serialization.Model): + """The error object. + + All required parameters must be populated in order to send to Azure. + + :ivar additional_properties: Unmatched properties from the message are deserialized to this + collection. + :vartype additional_properties: dict[str, any] + :ivar code: Required. One of a server-defined set of error codes. Possible values include: + "BadParameter", "Unauthorized". + :vartype code: str or ~errorwithsecrets.models.ErrorCode + :ivar message: Required. A human-readable representation of the error. + :vartype message: str + :ivar target: The target of the error. + :vartype target: str + :ivar details: An array of details about specific errors that led to this reported error. + :vartype details: list[~errorwithsecrets.models.Error] + :ivar innererror: An object containing more specific information than the current object about + the error. + :vartype innererror: ~errorwithsecrets.models.InnerError + """ + + _validation = { + "code": {"required": True}, + "message": {"required": True}, + } + + _attribute_map = { + "additional_properties": {"key": "", "type": "{object}"}, + "code": {"key": "code", "type": "str"}, + "message": {"key": "message", "type": "str"}, + "target": {"key": "target", "type": "str"}, + "details": {"key": "details", "type": "[Error]"}, + "innererror": {"key": "innererror", "type": "InnerError"}, + } + + def __init__(self, **kwargs): + """ + :keyword additional_properties: Unmatched properties from the message are deserialized to this + collection. + :paramtype additional_properties: dict[str, any] + :keyword code: Required. One of a server-defined set of error codes. Possible values include: + "BadParameter", "Unauthorized". + :paramtype code: str or ~errorwithsecrets.models.ErrorCode + :keyword message: Required. A human-readable representation of the error. + :paramtype message: str + :keyword target: The target of the error. + :paramtype target: str + :keyword details: An array of details about specific errors that led to this reported error. + :paramtype details: list[~errorwithsecrets.models.Error] + :keyword innererror: An object containing more specific information than the current object + about the error. + :paramtype innererror: ~errorwithsecrets.models.InnerError + """ + super(Error, self).__init__(**kwargs) + self.additional_properties = kwargs.get("additional_properties", None) + self.code = kwargs["code"] + self.message = kwargs["message"] + self.target = kwargs.get("target", None) + self.details = kwargs.get("details", None) + self.innererror = kwargs.get("innererror", None) + + +class ErrorResponse(msrest.serialization.Model): + """Error response. + + All required parameters must be populated in order to send to Azure. + + :ivar additional_properties: Unmatched properties from the message are deserialized to this + collection. + :vartype additional_properties: dict[str, any] + :ivar error: Required. The error object. + :vartype error: ~errorwithsecrets.models.Error + """ + + _validation = { + "error": {"required": True}, + } + + _attribute_map = { + "additional_properties": {"key": "", "type": "{object}"}, + "error": {"key": "error", "type": "Error"}, + } + + def __init__(self, **kwargs): + """ + :keyword additional_properties: Unmatched properties from the message are deserialized to this + collection. + :paramtype additional_properties: dict[str, any] + :keyword error: Required. The error object. + :paramtype error: ~errorwithsecrets.models.Error + """ + super(ErrorResponse, self).__init__(**kwargs) + self.additional_properties = kwargs.get("additional_properties", None) + self.error = kwargs["error"] + + +class InnerError(msrest.serialization.Model): + """An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. + + All required parameters must be populated in order to send to Azure. + + :ivar additional_properties: Unmatched properties from the message are deserialized to this + collection. + :vartype additional_properties: dict[str, any] + :ivar code: Required. One of a server-defined set of error codes. Possible values include: + "MissingSharedKey", "UnauthorizedSharedKey". + :vartype code: str or ~errorwithsecrets.models.InnerErrorCode + :ivar message: Required. Error message. + :vartype message: str + :ivar innererror: An object containing more specific information than the current object about + the error. + :vartype innererror: ~errorwithsecrets.models.InnerError + """ + + _validation = { + "code": {"required": True}, + "message": {"required": True}, + } + + _attribute_map = { + "additional_properties": {"key": "", "type": "{object}"}, + "code": {"key": "code", "type": "str"}, + "message": {"key": "message", "type": "str"}, + "innererror": {"key": "innererror", "type": "InnerError"}, + } + + def __init__(self, **kwargs): + """ + :keyword additional_properties: Unmatched properties from the message are deserialized to this + collection. + :paramtype additional_properties: dict[str, any] + :keyword code: Required. One of a server-defined set of error codes. Possible values include: + "MissingSharedKey", "UnauthorizedSharedKey". + :paramtype code: str or ~errorwithsecrets.models.InnerErrorCode + :keyword message: Required. Error message. + :paramtype message: str + :keyword innererror: An object containing more specific information than the current object + about the error. + :paramtype innererror: ~errorwithsecrets.models.InnerError + """ + super(InnerError, self).__init__(**kwargs) + self.additional_properties = kwargs.get("additional_properties", None) + self.code = kwargs["code"] + self.message = kwargs["message"] + self.innererror = kwargs.get("innererror", None) + + +class SecretResponse(msrest.serialization.Model): + """A secret. + + All required parameters must be populated in order to send to Azure. + + :ivar key: Required. The secret key. + :vartype key: str + :ivar value: Required. The secret value. + :vartype value: str + """ + + _validation = { + "key": {"required": True}, + "value": {"required": True}, + } + + _attribute_map = { + "key": {"key": "key", "type": "str"}, + "value": {"key": "value", "type": "str"}, + } + + def __init__(self, **kwargs): + """ + :keyword key: Required. The secret key. + :paramtype key: str + :keyword value: Required. The secret value. + :paramtype value: str + """ + super(SecretResponse, self).__init__(**kwargs) + self.key = kwargs["key"] + self.value = kwargs["value"] diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models_py3.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models_py3.py new file mode 100644 index 00000000000..651b622da87 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/models/_models_py3.py @@ -0,0 +1,213 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any, Dict, List, Optional, Union + +from azure.core.exceptions import HttpResponseError +import msrest.serialization + +from ._errorwith_secrets_enums import * + + +class Error(msrest.serialization.Model): + """The error object. + + All required parameters must be populated in order to send to Azure. + + :ivar additional_properties: Unmatched properties from the message are deserialized to this + collection. + :vartype additional_properties: dict[str, any] + :ivar code: Required. One of a server-defined set of error codes. Possible values include: + "BadParameter", "Unauthorized". + :vartype code: str or ~errorwithsecrets.models.ErrorCode + :ivar message: Required. A human-readable representation of the error. + :vartype message: str + :ivar target: The target of the error. + :vartype target: str + :ivar details: An array of details about specific errors that led to this reported error. + :vartype details: list[~errorwithsecrets.models.Error] + :ivar innererror: An object containing more specific information than the current object about + the error. + :vartype innererror: ~errorwithsecrets.models.InnerError + """ + + _validation = { + "code": {"required": True}, + "message": {"required": True}, + } + + _attribute_map = { + "additional_properties": {"key": "", "type": "{object}"}, + "code": {"key": "code", "type": "str"}, + "message": {"key": "message", "type": "str"}, + "target": {"key": "target", "type": "str"}, + "details": {"key": "details", "type": "[Error]"}, + "innererror": {"key": "innererror", "type": "InnerError"}, + } + + def __init__( + self, + *, + code: Union[str, "ErrorCode"], + message: str, + additional_properties: Optional[Dict[str, Any]] = None, + target: Optional[str] = None, + details: Optional[List["Error"]] = None, + innererror: Optional["InnerError"] = None, + **kwargs + ): + """ + :keyword additional_properties: Unmatched properties from the message are deserialized to this + collection. + :paramtype additional_properties: dict[str, any] + :keyword code: Required. One of a server-defined set of error codes. Possible values include: + "BadParameter", "Unauthorized". + :paramtype code: str or ~errorwithsecrets.models.ErrorCode + :keyword message: Required. A human-readable representation of the error. + :paramtype message: str + :keyword target: The target of the error. + :paramtype target: str + :keyword details: An array of details about specific errors that led to this reported error. + :paramtype details: list[~errorwithsecrets.models.Error] + :keyword innererror: An object containing more specific information than the current object + about the error. + :paramtype innererror: ~errorwithsecrets.models.InnerError + """ + super(Error, self).__init__(**kwargs) + self.additional_properties = additional_properties + self.code = code + self.message = message + self.target = target + self.details = details + self.innererror = innererror + + +class ErrorResponse(msrest.serialization.Model): + """Error response. + + All required parameters must be populated in order to send to Azure. + + :ivar additional_properties: Unmatched properties from the message are deserialized to this + collection. + :vartype additional_properties: dict[str, any] + :ivar error: Required. The error object. + :vartype error: ~errorwithsecrets.models.Error + """ + + _validation = { + "error": {"required": True}, + } + + _attribute_map = { + "additional_properties": {"key": "", "type": "{object}"}, + "error": {"key": "error", "type": "Error"}, + } + + def __init__(self, *, error: "Error", additional_properties: Optional[Dict[str, Any]] = None, **kwargs): + """ + :keyword additional_properties: Unmatched properties from the message are deserialized to this + collection. + :paramtype additional_properties: dict[str, any] + :keyword error: Required. The error object. + :paramtype error: ~errorwithsecrets.models.Error + """ + super(ErrorResponse, self).__init__(**kwargs) + self.additional_properties = additional_properties + self.error = error + + +class InnerError(msrest.serialization.Model): + """An object containing more specific information about the error. As per Microsoft One API guidelines - https://github.com/Microsoft/api-guidelines/blob/vNext/Guidelines.md#7102-error-condition-responses. + + All required parameters must be populated in order to send to Azure. + + :ivar additional_properties: Unmatched properties from the message are deserialized to this + collection. + :vartype additional_properties: dict[str, any] + :ivar code: Required. One of a server-defined set of error codes. Possible values include: + "MissingSharedKey", "UnauthorizedSharedKey". + :vartype code: str or ~errorwithsecrets.models.InnerErrorCode + :ivar message: Required. Error message. + :vartype message: str + :ivar innererror: An object containing more specific information than the current object about + the error. + :vartype innererror: ~errorwithsecrets.models.InnerError + """ + + _validation = { + "code": {"required": True}, + "message": {"required": True}, + } + + _attribute_map = { + "additional_properties": {"key": "", "type": "{object}"}, + "code": {"key": "code", "type": "str"}, + "message": {"key": "message", "type": "str"}, + "innererror": {"key": "innererror", "type": "InnerError"}, + } + + def __init__( + self, + *, + code: Union[str, "InnerErrorCode"], + message: str, + additional_properties: Optional[Dict[str, Any]] = None, + innererror: Optional["InnerError"] = None, + **kwargs + ): + """ + :keyword additional_properties: Unmatched properties from the message are deserialized to this + collection. + :paramtype additional_properties: dict[str, any] + :keyword code: Required. One of a server-defined set of error codes. Possible values include: + "MissingSharedKey", "UnauthorizedSharedKey". + :paramtype code: str or ~errorwithsecrets.models.InnerErrorCode + :keyword message: Required. Error message. + :paramtype message: str + :keyword innererror: An object containing more specific information than the current object + about the error. + :paramtype innererror: ~errorwithsecrets.models.InnerError + """ + super(InnerError, self).__init__(**kwargs) + self.additional_properties = additional_properties + self.code = code + self.message = message + self.innererror = innererror + + +class SecretResponse(msrest.serialization.Model): + """A secret. + + All required parameters must be populated in order to send to Azure. + + :ivar key: Required. The secret key. + :vartype key: str + :ivar value: Required. The secret value. + :vartype value: str + """ + + _validation = { + "key": {"required": True}, + "value": {"required": True}, + } + + _attribute_map = { + "key": {"key": "key", "type": "str"}, + "value": {"key": "value", "type": "str"}, + } + + def __init__(self, *, key: str, value: str, **kwargs): + """ + :keyword key: Required. The secret key. + :paramtype key: str + :keyword value: Required. The secret value. + :paramtype value: str + """ + super(SecretResponse, self).__init__(**kwargs) + self.key = key + self.value = value diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/__init__.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/__init__.py new file mode 100644 index 00000000000..9e69b0ddd50 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/__init__.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets_operations import ErrorWithSecretsOperationsMixin + +__all__ = [ + "ErrorWithSecretsOperationsMixin", +] diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/_errorwith_secrets_operations.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/_errorwith_secrets_operations.py new file mode 100644 index 00000000000..686c455bef3 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/operations/_errorwith_secrets_operations.py @@ -0,0 +1,156 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace + +from .. import models as _models +from .._vendor import _convert_request + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Callable, Dict, Optional, TypeVar + + T = TypeVar("T") + ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False +# fmt: off + +def build_create_secret_request( + **kwargs # type: Any +): + # type: (...) -> HttpRequest + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/secrets/:create") + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + headers=_header_parameters, + **kwargs + ) + + +def build_get_error_with_secrets_request( + **kwargs # type: Any +): + # type: (...) -> HttpRequest + accept = "application/json" + # Construct URL + _url = kwargs.pop("template_url", "/secrets/error") + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + headers=_header_parameters, + **kwargs + ) + +# fmt: on +class ErrorWithSecretsOperationsMixin(object): + @distributed_trace + def create_secret( + self, **kwargs # type: Any + ): + # type: (...) -> "_models.SecretResponse" + """Creates a secret. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: SecretResponse, or the result of cls(response) + :rtype: ~errorwithsecrets.models.SecretResponse + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop("cls", None) # type: ClsType["_models.SecretResponse"] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_create_secret_request( + template_url=self.create_secret.metadata["url"], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error) + + deserialized = self._deserialize("SecretResponse", pipeline_response) + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + create_secret.metadata = {"url": "/secrets/:create"} # type: ignore + + @distributed_trace + def get_error_with_secrets( # pylint: disable=inconsistent-return-statements + self, **kwargs # type: Any + ): + # type: (...) -> None + """Gets an error response containing secrets and PII. + + :keyword callable cls: A custom type or function that will be passed the direct response + :return: None, or the result of cls(response) + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop("cls", None) # type: ClsType[None] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_get_error_with_secrets_request( + template_url=self.get_error_with_secrets.metadata["url"], + ) + request = _convert_request(request) + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + error = self._deserialize.failsafe_deserialize(_models.ErrorResponse, pipeline_response) + raise HttpResponseError(response=response, model=error) + + if cls: + return cls(pipeline_response, None, {}) + + get_error_with_secrets.metadata = {"url": "/secrets/error"} # type: ignore diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/py.typed b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/py.typed new file mode 100644 index 00000000000..e5aff4f83af --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/errorwithsecrets/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py new file mode 100644 index 00000000000..ed786ed0573 --- /dev/null +++ b/test/vanilla/legacy/Expected/AcceptanceTests/ErrorWithSecrets/setup.py @@ -0,0 +1,37 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +# coding: utf-8 + +from setuptools import setup, find_packages + +NAME = "errorwithsecrets" +VERSION = "0.1.0" + +# To install the library, run the following +# +# python setup.py install +# +# prerequisite: setuptools +# http://pypi.python.org/pypi/setuptools + +REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.20.1"] + +setup( + name=NAME, + version=VERSION, + description="ErrorWithSecrets", + author_email="", + url="", + keywords=["Swagger", "ErrorWithSecrets"], + install_requires=REQUIRES, + packages=find_packages(), + include_package_data=True, + long_description="""\ + Tests whether loggers/tracers redact secrets and PII within error responses. + """, +) diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/__init__.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/__init__.py new file mode 100644 index 00000000000..bf7f7437fd8 --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/__init__.py @@ -0,0 +1,19 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets import ErrorWithSecrets +from ._version import VERSION + +__version__ = VERSION +__all__ = ["ErrorWithSecrets"] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk + +patch_sdk() diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_configuration.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_configuration.py new file mode 100644 index 00000000000..224f852878d --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_configuration.py @@ -0,0 +1,42 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from ._version import VERSION + + +class ErrorWithSecretsConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for ErrorWithSecrets. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__(self, **kwargs: Any) -> None: + super(ErrorWithSecretsConfiguration, self).__init__(**kwargs) + + kwargs.setdefault("sdk_moniker", "errorwithsecrets/{}".format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, **kwargs # type: Any + ): + # type: (...) -> None + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get("authentication_policy") diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_errorwith_secrets.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_errorwith_secrets.py new file mode 100644 index 00000000000..8583025d29c --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_errorwith_secrets.py @@ -0,0 +1,76 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, TYPE_CHECKING + +from msrest import Deserializer, Serializer + +from azure.core import PipelineClient +from azure.core.rest import HttpRequest, HttpResponse + +from ._configuration import ErrorWithSecretsConfiguration + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Dict + + +class ErrorWithSecrets: + """Tests whether loggers/tracers redact secrets and PII within error responses. + + :keyword endpoint: Service URL. Default value is "http://localhost:3000". + :paramtype endpoint: str + """ + + def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: + + self._config = ErrorWithSecretsConfiguration(**kwargs) + self._client = PipelineClient(base_url=endpoint, config=self._config, **kwargs) + + self._serialize = Serializer() + self._deserialize = Deserializer() + self._serialize.client_side_validation = False + + def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + """Runs the network request through the client's chained policies. + + We have helper methods to create requests specific to this service in `errorwithsecretslowlevel.rest`. + Use these helper methods to create the request you pass to this method. + + >>> from errorwithsecretslowlevel.rest import build_create_secret_request + >>> request = build_create_secret_request(**kwargs) + + >>> response = client.send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> ErrorWithSecrets + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_patch.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_patch.py new file mode 100644 index 00000000000..f99e77fef98 --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_version.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_version.py new file mode 100644 index 00000000000..eae7c95b6fb --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "0.1.0" diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/__init__.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/__init__.py new file mode 100644 index 00000000000..57ab186755a --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/__init__.py @@ -0,0 +1,17 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets import ErrorWithSecrets + +__all__ = ["ErrorWithSecrets"] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk + +patch_sdk() diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_configuration.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_configuration.py new file mode 100644 index 00000000000..1994309507d --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_configuration.py @@ -0,0 +1,39 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from .._version import VERSION + + +class ErrorWithSecretsConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for ErrorWithSecrets. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__(self, **kwargs: Any) -> None: + super(ErrorWithSecretsConfiguration, self).__init__(**kwargs) + + kwargs.setdefault("sdk_moniker", "errorwithsecrets/{}".format(VERSION)) + self._configure(**kwargs) + + def _configure(self, **kwargs: Any) -> None: + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get("authentication_policy") diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_errorwith_secrets.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_errorwith_secrets.py new file mode 100644 index 00000000000..a1409b817b4 --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_errorwith_secrets.py @@ -0,0 +1,72 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, Awaitable, TYPE_CHECKING + +from msrest import Deserializer, Serializer + +from azure.core import AsyncPipelineClient +from azure.core.rest import AsyncHttpResponse, HttpRequest + +from ._configuration import ErrorWithSecretsConfiguration + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Dict + + +class ErrorWithSecrets: + """Tests whether loggers/tracers redact secrets and PII within error responses. + + :keyword endpoint: Service URL. Default value is "http://localhost:3000". + :paramtype endpoint: str + """ + + def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: + self._config = ErrorWithSecretsConfiguration(**kwargs) + self._client = AsyncPipelineClient(base_url=endpoint, config=self._config, **kwargs) + + self._serialize = Serializer() + self._deserialize = Deserializer() + self._serialize.client_side_validation = False + + def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + We have helper methods to create requests specific to this service in `errorwithsecretslowlevel.rest`. + Use these helper methods to create the request you pass to this method. + + >>> from errorwithsecretslowlevel.rest import build_create_secret_request + >>> request = build_create_secret_request(**kwargs) + + >>> response = await client.send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "ErrorWithSecrets": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details) -> None: + await self._client.__aexit__(*exc_details) diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_patch.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_patch.py new file mode 100644 index 00000000000..f99e77fef98 --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/aio/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/py.typed b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/py.typed new file mode 100644 index 00000000000..e5aff4f83af --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/__init__.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/__init__.py new file mode 100644 index 00000000000..741180de779 --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/__init__.py @@ -0,0 +1,19 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +try: + from ._request_builders_py3 import build_create_secret_request + from ._request_builders_py3 import build_get_error_with_secrets_request +except (SyntaxError, ImportError): + from ._request_builders import build_create_secret_request # type: ignore + from ._request_builders import build_get_error_with_secrets_request # type: ignore + +__all__ = [ + "build_create_secret_request", + "build_get_error_with_secrets_request", +] diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders.py new file mode 100644 index 00000000000..1dc68528ba2 --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders.py @@ -0,0 +1,91 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import TYPE_CHECKING + +from msrest import Serializer + +from azure.core.rest import HttpRequest + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Any, Dict + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + +# fmt: off + +def build_create_secret_request( + **kwargs # type: Any +): + # type: (...) -> HttpRequest + """Creates a secret. + + See https://aka.ms/azsdk/python/protocol/quickstart for how to incorporate this request builder + into your code flow. + + :return: Returns an :class:`~azure.core.rest.HttpRequest` that you will pass to the client's + `send_request` method. See https://aka.ms/azsdk/python/protocol/quickstart for how to + incorporate this response into your code flow. + :rtype: ~azure.core.rest.HttpRequest + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response.json() == { + "key": "str", # Required. The secret key. + "value": "str" # Required. The secret value. + } + """ + + accept = "application/json" + # Construct URL + _url = "/secrets/:create" + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="POST", + url=_url, + headers=_header_parameters, + **kwargs + ) + + +def build_get_error_with_secrets_request( + **kwargs # type: Any +): + # type: (...) -> HttpRequest + """Gets an error response containing secrets and PII. + + See https://aka.ms/azsdk/python/protocol/quickstart for how to incorporate this request builder + into your code flow. + + :return: Returns an :class:`~azure.core.rest.HttpRequest` that you will pass to the client's + `send_request` method. See https://aka.ms/azsdk/python/protocol/quickstart for how to + incorporate this response into your code flow. + :rtype: ~azure.core.rest.HttpRequest + """ + + accept = "application/json" + # Construct URL + _url = "/secrets/error" + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters['Accept'] = _SERIALIZER.header("accept", accept, 'str') + + return HttpRequest( + method="GET", + url=_url, + headers=_header_parameters, + **kwargs + ) diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders_py3.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders_py3.py new file mode 100644 index 00000000000..262f075e83a --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/errorwithsecretslowlevel/rest/_request_builders_py3.py @@ -0,0 +1,70 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Dict + +from msrest import Serializer + +from azure.core.rest import HttpRequest + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_create_secret_request(**kwargs: Any) -> HttpRequest: + """Creates a secret. + + See https://aka.ms/azsdk/python/protocol/quickstart for how to incorporate this request builder + into your code flow. + + :return: Returns an :class:`~azure.core.rest.HttpRequest` that you will pass to the client's + `send_request` method. See https://aka.ms/azsdk/python/protocol/quickstart for how to + incorporate this response into your code flow. + :rtype: ~azure.core.rest.HttpRequest + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response.json() == { + "key": "str", # Required. The secret key. + "value": "str" # Required. The secret value. + } + """ + + accept = "application/json" + # Construct URL + _url = "/secrets/:create" + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, headers=_header_parameters, **kwargs) + + +def build_get_error_with_secrets_request(**kwargs: Any) -> HttpRequest: + """Gets an error response containing secrets and PII. + + See https://aka.ms/azsdk/python/protocol/quickstart for how to incorporate this request builder + into your code flow. + + :return: Returns an :class:`~azure.core.rest.HttpRequest` that you will pass to the client's + `send_request` method. See https://aka.ms/azsdk/python/protocol/quickstart for how to + incorporate this response into your code flow. + :rtype: ~azure.core.rest.HttpRequest + """ + + accept = "application/json" + # Construct URL + _url = "/secrets/error" + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, headers=_header_parameters, **kwargs) diff --git a/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/setup.py b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/setup.py new file mode 100644 index 00000000000..ed786ed0573 --- /dev/null +++ b/test/vanilla/low-level/Expected/AcceptanceTests/ErrorWithSecretsLowLevel/setup.py @@ -0,0 +1,37 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +# coding: utf-8 + +from setuptools import setup, find_packages + +NAME = "errorwithsecrets" +VERSION = "0.1.0" + +# To install the library, run the following +# +# python setup.py install +# +# prerequisite: setuptools +# http://pypi.python.org/pypi/setuptools + +REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.20.1"] + +setup( + name=NAME, + version=VERSION, + description="ErrorWithSecrets", + author_email="", + url="", + keywords=["Swagger", "ErrorWithSecrets"], + install_requires=REQUIRES, + packages=find_packages(), + include_package_data=True, + long_description="""\ + Tests whether loggers/tracers redact secrets and PII within error responses. + """, +) diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/__init__.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/__init__.py new file mode 100644 index 00000000000..bf7f7437fd8 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/__init__.py @@ -0,0 +1,19 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets import ErrorWithSecrets +from ._version import VERSION + +__version__ = VERSION +__all__ = ["ErrorWithSecrets"] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk + +patch_sdk() diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_configuration.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_configuration.py new file mode 100644 index 00000000000..224f852878d --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_configuration.py @@ -0,0 +1,42 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from ._version import VERSION + + +class ErrorWithSecretsConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for ErrorWithSecrets. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__(self, **kwargs: Any) -> None: + super(ErrorWithSecretsConfiguration, self).__init__(**kwargs) + + kwargs.setdefault("sdk_moniker", "errorwithsecrets/{}".format(VERSION)) + self._configure(**kwargs) + + def _configure( + self, **kwargs # type: Any + ): + # type: (...) -> None + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get("authentication_policy") diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_errorwith_secrets.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_errorwith_secrets.py new file mode 100644 index 00000000000..9fa66b6de00 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_errorwith_secrets.py @@ -0,0 +1,74 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, TYPE_CHECKING + +from msrest import Deserializer, Serializer + +from azure.core import PipelineClient +from azure.core.rest import HttpRequest, HttpResponse + +from ._configuration import ErrorWithSecretsConfiguration +from ._operations import ErrorWithSecretsOperationsMixin + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Dict + + +class ErrorWithSecrets(ErrorWithSecretsOperationsMixin): + """Tests whether loggers/tracers redact secrets and PII within error responses. + + :keyword endpoint: Service URL. Default value is "http://localhost:3000". + :paramtype endpoint: str + """ + + def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: + + self._config = ErrorWithSecretsConfiguration(**kwargs) + self._client = PipelineClient(base_url=endpoint, config=self._config, **kwargs) + + self._serialize = Serializer() + self._deserialize = Deserializer() + self._serialize.client_side_validation = False + + def send_request(self, request: HttpRequest, **kwargs: Any) -> HttpResponse: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = client.send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.HttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + def close(self): + # type: () -> None + self._client.close() + + def __enter__(self): + # type: () -> ErrorWithSecrets + self._client.__enter__() + return self + + def __exit__(self, *exc_details): + # type: (Any) -> None + self._client.__exit__(*exc_details) diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/__init__.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/__init__.py new file mode 100644 index 00000000000..5808d8f592b --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/__init__.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import ErrorWithSecretsOperationsMixin + +__all__ = [ + "ErrorWithSecretsOperationsMixin", +] diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/_operations.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/_operations.py new file mode 100644 index 00000000000..e3e26a454c9 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_operations/_operations.py @@ -0,0 +1,126 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Callable, Dict, Optional, TypeVar + +from msrest import Serializer + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import HttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator import distributed_trace + +T = TypeVar("T") +JSONType = Any +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] + +_SERIALIZER = Serializer() +_SERIALIZER.client_side_validation = False + + +def build_create_secret_request(**kwargs: Any) -> HttpRequest: + accept = "application/json" + # Construct URL + _url = "/secrets/:create" + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="POST", url=_url, headers=_header_parameters, **kwargs) + + +def build_get_error_with_secrets_request(**kwargs: Any) -> HttpRequest: + accept = "application/json" + # Construct URL + _url = "/secrets/error" + + # Construct headers + _header_parameters = kwargs.pop("headers", {}) # type: Dict[str, Any] + _header_parameters["Accept"] = _SERIALIZER.header("accept", accept, "str") + + return HttpRequest(method="GET", url=_url, headers=_header_parameters, **kwargs) + + +class ErrorWithSecretsOperationsMixin(object): + @distributed_trace + def create_secret(self, **kwargs: Any) -> JSONType: + """Creates a secret. + + :return: JSON object + :rtype: JSONType + :raises: ~azure.core.exceptions.HttpResponseError + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response.json() == { + "key": "str", # Required. The secret key. + "value": "str" # Required. The secret value. + } + """ + cls = kwargs.pop("cls", None) # type: ClsType[JSONType] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_create_secret_request() + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + @distributed_trace + def get_error_with_secrets(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements + """Gets an error response containing secrets and PII. + + :return: None + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop("cls", None) # type: ClsType[None] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_get_error_with_secrets_request() + request.url = self._client.format_url(request.url) + + pipeline_response = self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_patch.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_patch.py new file mode 100644 index 00000000000..f99e77fef98 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_version.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_version.py new file mode 100644 index 00000000000..eae7c95b6fb --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/_version.py @@ -0,0 +1,9 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +VERSION = "0.1.0" diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/__init__.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/__init__.py new file mode 100644 index 00000000000..57ab186755a --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/__init__.py @@ -0,0 +1,17 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._errorwith_secrets import ErrorWithSecrets + +__all__ = ["ErrorWithSecrets"] + +# `._patch.py` is used for handwritten extensions to the generated code +# Example: https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +from ._patch import patch_sdk + +patch_sdk() diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_configuration.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_configuration.py new file mode 100644 index 00000000000..1994309507d --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_configuration.py @@ -0,0 +1,39 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from typing import Any + +from azure.core.configuration import Configuration +from azure.core.pipeline import policies + +from .._version import VERSION + + +class ErrorWithSecretsConfiguration(Configuration): # pylint: disable=too-many-instance-attributes + """Configuration for ErrorWithSecrets. + + Note that all parameters used to create this instance are saved as instance + attributes. + """ + + def __init__(self, **kwargs: Any) -> None: + super(ErrorWithSecretsConfiguration, self).__init__(**kwargs) + + kwargs.setdefault("sdk_moniker", "errorwithsecrets/{}".format(VERSION)) + self._configure(**kwargs) + + def _configure(self, **kwargs: Any) -> None: + self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs) + self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs) + self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs) + self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs) + self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs) + self.retry_policy = kwargs.get("retry_policy") or policies.AsyncRetryPolicy(**kwargs) + self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs) + self.redirect_policy = kwargs.get("redirect_policy") or policies.AsyncRedirectPolicy(**kwargs) + self.authentication_policy = kwargs.get("authentication_policy") diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_errorwith_secrets.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_errorwith_secrets.py new file mode 100644 index 00000000000..46ab92bd960 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_errorwith_secrets.py @@ -0,0 +1,70 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from copy import deepcopy +from typing import Any, Awaitable, TYPE_CHECKING + +from msrest import Deserializer, Serializer + +from azure.core import AsyncPipelineClient +from azure.core.rest import AsyncHttpResponse, HttpRequest + +from ._configuration import ErrorWithSecretsConfiguration +from ._operations import ErrorWithSecretsOperationsMixin + +if TYPE_CHECKING: + # pylint: disable=unused-import,ungrouped-imports + from typing import Dict + + +class ErrorWithSecrets(ErrorWithSecretsOperationsMixin): + """Tests whether loggers/tracers redact secrets and PII within error responses. + + :keyword endpoint: Service URL. Default value is "http://localhost:3000". + :paramtype endpoint: str + """ + + def __init__(self, *, endpoint: str = "http://localhost:3000", **kwargs: Any) -> None: + self._config = ErrorWithSecretsConfiguration(**kwargs) + self._client = AsyncPipelineClient(base_url=endpoint, config=self._config, **kwargs) + + self._serialize = Serializer() + self._deserialize = Deserializer() + self._serialize.client_side_validation = False + + def send_request(self, request: HttpRequest, **kwargs: Any) -> Awaitable[AsyncHttpResponse]: + """Runs the network request through the client's chained policies. + + >>> from azure.core.rest import HttpRequest + >>> request = HttpRequest("GET", "https://www.example.org/") + + >>> response = await client.send_request(request) + + + For more information on this code flow, see https://aka.ms/azsdk/python/protocol/quickstart + + :param request: The network request you want to make. Required. + :type request: ~azure.core.rest.HttpRequest + :keyword bool stream: Whether the response payload will be streamed. Defaults to False. + :return: The response of your network call. Does not do error handling on your response. + :rtype: ~azure.core.rest.AsyncHttpResponse + """ + + request_copy = deepcopy(request) + request_copy.url = self._client.format_url(request_copy.url) + return self._client.send_request(request_copy, **kwargs) + + async def close(self) -> None: + await self._client.close() + + async def __aenter__(self) -> "ErrorWithSecrets": + await self._client.__aenter__() + return self + + async def __aexit__(self, *exc_details) -> None: + await self._client.__aexit__(*exc_details) diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/__init__.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/__init__.py new file mode 100644 index 00000000000..5808d8f592b --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/__init__.py @@ -0,0 +1,13 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- + +from ._operations import ErrorWithSecretsOperationsMixin + +__all__ = [ + "ErrorWithSecretsOperationsMixin", +] diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/_operations.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/_operations.py new file mode 100644 index 00000000000..e85a3197b98 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_operations/_operations.py @@ -0,0 +1,99 @@ +# pylint: disable=too-many-lines +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +from typing import Any, Callable, Dict, Optional, TypeVar + +from azure.core.exceptions import ( + ClientAuthenticationError, + HttpResponseError, + ResourceExistsError, + ResourceNotFoundError, + map_error, +) +from azure.core.pipeline import PipelineResponse +from azure.core.pipeline.transport import AsyncHttpResponse +from azure.core.rest import HttpRequest +from azure.core.tracing.decorator_async import distributed_trace_async + +from ..._operations._operations import build_create_secret_request, build_get_error_with_secrets_request + +T = TypeVar("T") +JSONType = Any +ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] + + +class ErrorWithSecretsOperationsMixin: + @distributed_trace_async + async def create_secret(self, **kwargs: Any) -> JSONType: + """Creates a secret. + + :return: JSON object + :rtype: JSONType + :raises: ~azure.core.exceptions.HttpResponseError + + Example: + .. code-block:: python + + # response body for status code(s): 200 + response.json() == { + "key": "str", # Required. The secret key. + "value": "str" # Required. The secret value. + } + """ + cls = kwargs.pop("cls", None) # type: ClsType[JSONType] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_create_secret_request() + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [200]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if response.content: + deserialized = response.json() + else: + deserialized = None + + if cls: + return cls(pipeline_response, deserialized, {}) + + return deserialized + + @distributed_trace_async + async def get_error_with_secrets(self, **kwargs: Any) -> None: # pylint: disable=inconsistent-return-statements + """Gets an error response containing secrets and PII. + + :return: None + :rtype: None + :raises: ~azure.core.exceptions.HttpResponseError + """ + cls = kwargs.pop("cls", None) # type: ClsType[None] + error_map = {401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError} + error_map.update(kwargs.pop("error_map", {})) + + request = build_get_error_with_secrets_request() + request.url = self._client.format_url(request.url) + + pipeline_response = await self._client._pipeline.run( # pylint: disable=protected-access + request, stream=False, **kwargs + ) + response = pipeline_response.http_response + + if response.status_code not in [204]: + map_error(status_code=response.status_code, response=response, error_map=error_map) + raise HttpResponseError(response=response) + + if cls: + return cls(pipeline_response, None, {}) diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_patch.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_patch.py new file mode 100644 index 00000000000..f99e77fef98 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/aio/_patch.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- + +# This file is used for handwritten extensions to the generated code. Example: +# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md +def patch_sdk(): + pass diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/py.typed b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/py.typed new file mode 100644 index 00000000000..e5aff4f83af --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/errorwithsecretsversiontolerant/py.typed @@ -0,0 +1 @@ +# Marker file for PEP 561. \ No newline at end of file diff --git a/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py new file mode 100644 index 00000000000..ed786ed0573 --- /dev/null +++ b/test/vanilla/version-tolerant/Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/setup.py @@ -0,0 +1,37 @@ +# coding=utf-8 +# -------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# Code generated by Microsoft (R) AutoRest Code Generator. +# Changes may cause incorrect behavior and will be lost if the code is regenerated. +# -------------------------------------------------------------------------- +# coding: utf-8 + +from setuptools import setup, find_packages + +NAME = "errorwithsecrets" +VERSION = "0.1.0" + +# To install the library, run the following +# +# python setup.py install +# +# prerequisite: setuptools +# http://pypi.python.org/pypi/setuptools + +REQUIRES = ["msrest>=0.6.21", "azure-core<2.0.0,>=1.20.1"] + +setup( + name=NAME, + version=VERSION, + description="ErrorWithSecrets", + author_email="", + url="", + keywords=["Swagger", "ErrorWithSecrets"], + install_requires=REQUIRES, + packages=find_packages(), + include_package_data=True, + long_description="""\ + Tests whether loggers/tracers redact secrets and PII within error responses. + """, +) From bb277df277c67f848ccbefde469d59564bb207f0 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 1 Mar 2022 17:42:10 -0500 Subject: [PATCH 2/7] add secrets test --- .../asynctests/test_error_with_secrets.py | 50 ++++++++++++++++ .../test_error_with_secrets.py | 50 ++++++++++++++++ test/vanilla/legacy/requirements.txt | 1 + .../asynctests/test_error_with_secrets.py | 60 +++++++++++++++++++ .../test_error_with_secrets.py | 57 ++++++++++++++++++ test/vanilla/low-level/requirements.txt | 1 + .../asynctests/test_error_with_secrets.py | 51 ++++++++++++++++ .../test_error_with_secrets.py | 50 ++++++++++++++++ .../vanilla/version-tolerant/requirements.txt | 1 + 9 files changed, 321 insertions(+) create mode 100644 test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py create mode 100644 test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py create mode 100644 test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py create mode 100644 test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py create mode 100644 test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py create mode 100644 test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py diff --git a/test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py b/test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py new file mode 100644 index 00000000000..0ae2d68cad9 --- /dev/null +++ b/test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py @@ -0,0 +1,50 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +import pytest +from errorwithsecrets.aio import ErrorWithSecrets +from azure.core.exceptions import HttpResponseError + +@pytest.fixture +async def client(): + async with ErrorWithSecrets() as client: + yield client + +@pytest.mark.asyncio +async def test_create_secret(client): + with pytest.raises(HttpResponseError) as ex: + await client.create_secret() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) +@pytest.mark.asyncio +async def test_raise_error_with_secrets(client): + with pytest.raises(HttpResponseError) as ex: + await client.get_error_with_secrets() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) diff --git a/test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py b/test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py new file mode 100644 index 00000000000..d0470aa0384 --- /dev/null +++ b/test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py @@ -0,0 +1,50 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +import pytest +from errorwithsecrets import ErrorWithSecrets +from azure.core.exceptions import HttpResponseError + +@pytest.fixture +def client(): + with ErrorWithSecrets() as client: + yield client + + +def test_create_secret(client): + with pytest.raises(HttpResponseError) as ex: + client.create_secret() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + +def test_raise_error_with_secrets(client): + with pytest.raises(HttpResponseError) as ex: + client.get_error_with_secrets() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) diff --git a/test/vanilla/legacy/requirements.txt b/test/vanilla/legacy/requirements.txt index 6ccf726f0cb..836a5bc3056 100644 --- a/test/vanilla/legacy/requirements.txt +++ b/test/vanilla/legacy/requirements.txt @@ -29,6 +29,7 @@ azure-core==1.20.1 -e ./Expected/AcceptanceTests/Constants -e ./Expected/AcceptanceTests/CustomBaseUri -e ./Expected/AcceptanceTests/CustomBaseUriMoreOptions +-e ./Expected/AcceptanceTests/ErrorWithSecrets -e ./Expected/AcceptanceTests/ExtensibleEnums -e ./Expected/AcceptanceTests/Header -e ./Expected/AcceptanceTests/Http diff --git a/test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py b/test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py new file mode 100644 index 00000000000..68517af2c34 --- /dev/null +++ b/test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py @@ -0,0 +1,60 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +import pytest +from errorwithsecretslowlevel.aio import ErrorWithSecrets +from errorwithsecretslowlevel import rest +from azure.core.exceptions import HttpResponseError + +@pytest.fixture +async def client(): + async with ErrorWithSecrets() as client: + yield client + +@pytest.fixture +def send_request(client, base_send_request): + async def _send_request(request): + return await base_send_request(client, request) + return _send_request + +@pytest.mark.asyncio +async def test_create_secret(send_request): + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + request = rest.build_create_secret_request() + with pytest.raises(HttpResponseError) as ex: + await send_request(request) + assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + +@pytest.mark.asyncio +async def test_raise_error_with_secrets(send_request): + request = rest.build_get_error_with_secrets_request() + with pytest.raises(HttpResponseError) as ex: + await send_request(request) + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) diff --git a/test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py b/test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py new file mode 100644 index 00000000000..c50054b02c7 --- /dev/null +++ b/test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py @@ -0,0 +1,57 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +import pytest +from errorwithsecretslowlevel import ErrorWithSecrets, rest +from azure.core.exceptions import HttpResponseError + +@pytest.fixture +def client(): + with ErrorWithSecrets() as client: + yield client + +@pytest.fixture +def send_request(client, base_send_request): + def _send_request(request): + return base_send_request(client, request) + return _send_request + +def test_create_secret(send_request): + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + request = rest.build_create_secret_request() + with pytest.raises(HttpResponseError) as ex: + send_request(request) + assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + +def test_raise_error_with_secrets(send_request): + request = rest.build_get_error_with_secrets_request() + with pytest.raises(HttpResponseError) as ex: + send_request(request) + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) diff --git a/test/vanilla/low-level/requirements.txt b/test/vanilla/low-level/requirements.txt index 2d365d5ba2e..47affacddd8 100644 --- a/test/vanilla/low-level/requirements.txt +++ b/test/vanilla/low-level/requirements.txt @@ -28,6 +28,7 @@ azure-core==1.20.1 -e ./Expected/AcceptanceTests/ConstantsLowLevel/ -e ./Expected/AcceptanceTests/CustomBaseUriLowLevel -e ./Expected/AcceptanceTests/CustomBaseUriMoreOptionsLowLevel +-e ./Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/ -e ./Expected/AcceptanceTests/ExtensibleEnumsLowLevel -e ./Expected/AcceptanceTests/HeaderLowLevel -e ./Expected/AcceptanceTests/HttpLowLevel diff --git a/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py b/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py new file mode 100644 index 00000000000..72bb6659ae8 --- /dev/null +++ b/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py @@ -0,0 +1,51 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +import pytest +from errorwithsecretsversiontolerant.aio import ErrorWithSecrets +from azure.core.exceptions import HttpResponseError + +@pytest.fixture +async def client(): + async with ErrorWithSecrets() as client: + yield client + +@pytest.mark.asyncio +async def test_create_secret(client): + with pytest.raises(HttpResponseError) as ex: + await client.create_secret() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + +@pytest.mark.asyncio +async def test_raise_error_with_secrets(client): + with pytest.raises(HttpResponseError) as ex: + await client.get_error_with_secrets() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) diff --git a/test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py b/test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py new file mode 100644 index 00000000000..309950c1b2b --- /dev/null +++ b/test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py @@ -0,0 +1,50 @@ +# -------------------------------------------------------------------------- +# +# Copyright (c) Microsoft Corporation. All rights reserved. +# +# The MIT License (MIT) +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the ""Software""), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +# +# -------------------------------------------------------------------------- +import pytest +from errorwithsecretsversiontolerant import ErrorWithSecrets +from azure.core.exceptions import HttpResponseError + +@pytest.fixture +def client(): + with ErrorWithSecrets() as client: + yield client + + +def test_create_secret(client): + with pytest.raises(HttpResponseError) as ex: + client.create_secret() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + +def test_raise_error_with_secrets(client): + with pytest.raises(HttpResponseError) as ex: + client.get_error_with_secrets() + # The actual test shouldn't have the secrets in the str output + # Until we figure out what to do for Python, just asserting + # what the string currently is for now. + assert "The user 'user@contoso.com' is unauthorized" in str(ex.value) diff --git a/test/vanilla/version-tolerant/requirements.txt b/test/vanilla/version-tolerant/requirements.txt index b7baab89054..a701d3afabc 100644 --- a/test/vanilla/version-tolerant/requirements.txt +++ b/test/vanilla/version-tolerant/requirements.txt @@ -29,6 +29,7 @@ azure-core==1.20.1 -e ./Expected/AcceptanceTests/ConstantsVersionTolerant/ -e ./Expected/AcceptanceTests/CustomBaseUriVersionTolerant -e ./Expected/AcceptanceTests/CustomBaseUriMoreOptionsVersionTolerant +-e ./Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/ -e ./Expected/AcceptanceTests/ExtensibleEnumsVersionTolerant -e ./Expected/AcceptanceTests/HeaderVersionTolerant -e ./Expected/AcceptanceTests/HttpVersionTolerant From c8c519440aa1b4adf1dd8d29edd7d1443641fcfe Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 1 Mar 2022 18:49:42 -0500 Subject: [PATCH 3/7] fix tests and bump version --- package.json | 2 +- .../asynctests/test_error_with_secrets.py | 15 +++++++++------ .../AcceptanceTests/test_error_with_secrets.py | 14 ++++++++------ .../asynctests/test_error_with_secrets.py | 13 ++++++------- .../AcceptanceTests/test_error_with_secrets.py | 13 ++++++------- .../asynctests/test_error_with_secrets.py | 14 ++++++++------ .../AcceptanceTests/test_error_with_secrets.py | 14 ++++++++------ 7 files changed, 46 insertions(+), 39 deletions(-) diff --git a/package.json b/package.json index 87c74c88d8a..7676c1ff6b7 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@azure-tools/extension": "~3.2.1" }, "devDependencies": { - "@microsoft.azure/autorest.testserver": "^3.3.17" + "@microsoft.azure/autorest.testserver": "^3.3.19" }, "files": [ "autorest/**/*.py", diff --git a/test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py b/test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py index 0ae2d68cad9..3be47017652 100644 --- a/test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py +++ b/test/vanilla/legacy/AcceptanceTests/asynctests/test_error_with_secrets.py @@ -24,6 +24,7 @@ # # -------------------------------------------------------------------------- import pytest +from errorwithsecrets.operations._errorwith_secrets_operations import build_create_secret_request from errorwithsecrets.aio import ErrorWithSecrets from azure.core.exceptions import HttpResponseError @@ -34,12 +35,14 @@ async def client(): @pytest.mark.asyncio async def test_create_secret(client): - with pytest.raises(HttpResponseError) as ex: - await client.create_secret() - # The actual test shouldn't have the secrets in the str output - # Until we figure out what to do for Python, just asserting - # what the string currently is for now. - assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + request = build_create_secret_request( + headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, + params={"key": "1c88a67921784300a462b2cb61da2339"}, + json={ "key": "1c88a67921784300a462b2cb61da2339" }, + ) + response = await client._send_request(request) + response.raise_for_status() + @pytest.mark.asyncio async def test_raise_error_with_secrets(client): with pytest.raises(HttpResponseError) as ex: diff --git a/test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py b/test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py index d0470aa0384..080d56c567a 100644 --- a/test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py +++ b/test/vanilla/legacy/AcceptanceTests/test_error_with_secrets.py @@ -25,6 +25,7 @@ # -------------------------------------------------------------------------- import pytest from errorwithsecrets import ErrorWithSecrets +from errorwithsecrets.operations._errorwith_secrets_operations import build_create_secret_request from azure.core.exceptions import HttpResponseError @pytest.fixture @@ -34,12 +35,13 @@ def client(): def test_create_secret(client): - with pytest.raises(HttpResponseError) as ex: - client.create_secret() - # The actual test shouldn't have the secrets in the str output - # Until we figure out what to do for Python, just asserting - # what the string currently is for now. - assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + request = build_create_secret_request( + headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, + params={"key": "1c88a67921784300a462b2cb61da2339"}, + json={ "key": "1c88a67921784300a462b2cb61da2339" }, + ) + response = client._send_request(request) + response.raise_for_status() def test_raise_error_with_secrets(client): with pytest.raises(HttpResponseError) as ex: diff --git a/test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py b/test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py index 68517af2c34..34fa988c23e 100644 --- a/test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py +++ b/test/vanilla/low-level/AcceptanceTests/asynctests/test_error_with_secrets.py @@ -41,13 +41,12 @@ async def _send_request(request): @pytest.mark.asyncio async def test_create_secret(send_request): - # The actual test shouldn't have the secrets in the str output - # Until we figure out what to do for Python, just asserting - # what the string currently is for now. - request = rest.build_create_secret_request() - with pytest.raises(HttpResponseError) as ex: - await send_request(request) - assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + request = rest.build_create_secret_request( + headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, + params={"key": "1c88a67921784300a462b2cb61da2339"}, + json={ "key": "1c88a67921784300a462b2cb61da2339" }, + ) + await send_request(request) @pytest.mark.asyncio async def test_raise_error_with_secrets(send_request): diff --git a/test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py b/test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py index c50054b02c7..6e45f6fa0ad 100644 --- a/test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py +++ b/test/vanilla/low-level/AcceptanceTests/test_error_with_secrets.py @@ -39,13 +39,12 @@ def _send_request(request): return _send_request def test_create_secret(send_request): - # The actual test shouldn't have the secrets in the str output - # Until we figure out what to do for Python, just asserting - # what the string currently is for now. - request = rest.build_create_secret_request() - with pytest.raises(HttpResponseError) as ex: - send_request(request) - assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + request = rest.build_create_secret_request( + headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, + params={"key": "1c88a67921784300a462b2cb61da2339"}, + json={ "key": "1c88a67921784300a462b2cb61da2339" }, + ) + send_request(request) def test_raise_error_with_secrets(send_request): request = rest.build_get_error_with_secrets_request() diff --git a/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py b/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py index 72bb6659ae8..ade519c2f02 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/asynctests/test_error_with_secrets.py @@ -24,6 +24,7 @@ # # -------------------------------------------------------------------------- import pytest +from errorwithsecretsversiontolerant._operations._operations import build_create_secret_request from errorwithsecretsversiontolerant.aio import ErrorWithSecrets from azure.core.exceptions import HttpResponseError @@ -34,12 +35,13 @@ async def client(): @pytest.mark.asyncio async def test_create_secret(client): - with pytest.raises(HttpResponseError) as ex: - await client.create_secret() - # The actual test shouldn't have the secrets in the str output - # Until we figure out what to do for Python, just asserting - # what the string currently is for now. - assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + request = build_create_secret_request( + headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, + params={"key": "1c88a67921784300a462b2cb61da2339"}, + json={ "key": "1c88a67921784300a462b2cb61da2339" }, + ) + response = await client.send_request(request) + response.raise_for_status() @pytest.mark.asyncio async def test_raise_error_with_secrets(client): diff --git a/test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py b/test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py index 309950c1b2b..639d5efad36 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/test_error_with_secrets.py @@ -25,6 +25,7 @@ # -------------------------------------------------------------------------- import pytest from errorwithsecretsversiontolerant import ErrorWithSecrets +from errorwithsecretsversiontolerant._operations._operations import build_create_secret_request from azure.core.exceptions import HttpResponseError @pytest.fixture @@ -34,12 +35,13 @@ def client(): def test_create_secret(client): - with pytest.raises(HttpResponseError) as ex: - client.create_secret() - # The actual test shouldn't have the secrets in the str output - # Until we figure out what to do for Python, just asserting - # what the string currently is for now. - assert "1c88a67921784300a462b2cb61da2339" in str(ex.value) + request = build_create_secret_request( + headers={"authorization": "SharedKey 1c88a67921784300a462b2cb61da2339"}, + params={"key": "1c88a67921784300a462b2cb61da2339"}, + json={ "key": "1c88a67921784300a462b2cb61da2339" }, + ) + response = client.send_request(request) + response.raise_for_status() def test_raise_error_with_secrets(client): with pytest.raises(HttpResponseError) as ex: From b0f63d9c68bc5641a2112febe8b8c914071007f2 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Tue, 1 Mar 2022 19:46:44 -0500 Subject: [PATCH 4/7] update coverage --- test/vanilla/legacy/AcceptanceTests/test_zzz.py | 1 + test/vanilla/low-level/AcceptanceTests/test_zzz.py | 1 + test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py | 1 + 3 files changed, 3 insertions(+) diff --git a/test/vanilla/legacy/AcceptanceTests/test_zzz.py b/test/vanilla/legacy/AcceptanceTests/test_zzz.py index aaa61ed129d..8c737065c69 100644 --- a/test/vanilla/legacy/AcceptanceTests/test_zzz.py +++ b/test/vanilla/legacy/AcceptanceTests/test_zzz.py @@ -61,6 +61,7 @@ def test_ensure_coverage(self): 'putDateTimeMaxUtc7MS': 1, # Python doesn't support 7 digits ms datetime 'FormdataStreamUploadFile': 1, # Form data not supported yet 'StreamUploadFile': 1, # Form data not supported yet + "ErrorWithSecrets": 1, # skip for now } for name in optional_report: if "Options" in name: diff --git a/test/vanilla/low-level/AcceptanceTests/test_zzz.py b/test/vanilla/low-level/AcceptanceTests/test_zzz.py index 6b158fd804a..0f9723e7794 100644 --- a/test/vanilla/low-level/AcceptanceTests/test_zzz.py +++ b/test/vanilla/low-level/AcceptanceTests/test_zzz.py @@ -65,6 +65,7 @@ def test_ensure_coverage(self): "animalNotFoundError": 1, "linkNotFoundError": 1, "putEnumReferencedConstant": 1, # can't do constants on body + "ErrorWithSecrets": 1, # skip for now } print("Coverage:") diff --git a/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py b/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py index 18f390f43a2..88ca90da58b 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py @@ -57,6 +57,7 @@ def test_ensure_coverage(self): 'putDateTimeMaxUtc7MS': 1, # Python doesn't support 7 digits ms datetime 'FormdataStreamUploadFile': 1, # Form data not supported yet 'StreamUploadFile': 1, # Form data not supported yet + "ErrorWithSecrets": 1, # skip for now } for name in optional_report: if "Options" in name: From c1cb6bd45d32766837a8b73d9caa5b0e8bf622ed Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 2 Mar 2022 11:37:11 -0500 Subject: [PATCH 5/7] remove from coverage skip --- test/vanilla/legacy/AcceptanceTests/test_zzz.py | 1 - test/vanilla/low-level/AcceptanceTests/test_zzz.py | 1 - test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py | 1 - 3 files changed, 3 deletions(-) diff --git a/test/vanilla/legacy/AcceptanceTests/test_zzz.py b/test/vanilla/legacy/AcceptanceTests/test_zzz.py index 8c737065c69..aaa61ed129d 100644 --- a/test/vanilla/legacy/AcceptanceTests/test_zzz.py +++ b/test/vanilla/legacy/AcceptanceTests/test_zzz.py @@ -61,7 +61,6 @@ def test_ensure_coverage(self): 'putDateTimeMaxUtc7MS': 1, # Python doesn't support 7 digits ms datetime 'FormdataStreamUploadFile': 1, # Form data not supported yet 'StreamUploadFile': 1, # Form data not supported yet - "ErrorWithSecrets": 1, # skip for now } for name in optional_report: if "Options" in name: diff --git a/test/vanilla/low-level/AcceptanceTests/test_zzz.py b/test/vanilla/low-level/AcceptanceTests/test_zzz.py index 0f9723e7794..6b158fd804a 100644 --- a/test/vanilla/low-level/AcceptanceTests/test_zzz.py +++ b/test/vanilla/low-level/AcceptanceTests/test_zzz.py @@ -65,7 +65,6 @@ def test_ensure_coverage(self): "animalNotFoundError": 1, "linkNotFoundError": 1, "putEnumReferencedConstant": 1, # can't do constants on body - "ErrorWithSecrets": 1, # skip for now } print("Coverage:") diff --git a/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py b/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py index 88ca90da58b..18f390f43a2 100644 --- a/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py +++ b/test/vanilla/version-tolerant/AcceptanceTests/test_zzz.py @@ -57,7 +57,6 @@ def test_ensure_coverage(self): 'putDateTimeMaxUtc7MS': 1, # Python doesn't support 7 digits ms datetime 'FormdataStreamUploadFile': 1, # Form data not supported yet 'StreamUploadFile': 1, # Form data not supported yet - "ErrorWithSecrets": 1, # skip for now } for name in optional_report: if "Options" in name: From a97b56ea085bcd377671d10944fe7af509ad4928 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 2 Mar 2022 11:48:35 -0500 Subject: [PATCH 6/7] bump testserver version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7676c1ff6b7..22001b32158 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "@azure-tools/extension": "~3.2.1" }, "devDependencies": { - "@microsoft.azure/autorest.testserver": "^3.3.19" + "@microsoft.azure/autorest.testserver": "^3.3.20" }, "files": [ "autorest/**/*.py", From 47cbd5a760c686f8f9efdac184159b5c0c26db04 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Wed, 2 Mar 2022 12:20:34 -0500 Subject: [PATCH 7/7] update llc req --- test/vanilla/low-level/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/vanilla/low-level/requirements.txt b/test/vanilla/low-level/requirements.txt index 47affacddd8..29ed657714e 100644 --- a/test/vanilla/low-level/requirements.txt +++ b/test/vanilla/low-level/requirements.txt @@ -28,7 +28,7 @@ azure-core==1.20.1 -e ./Expected/AcceptanceTests/ConstantsLowLevel/ -e ./Expected/AcceptanceTests/CustomBaseUriLowLevel -e ./Expected/AcceptanceTests/CustomBaseUriMoreOptionsLowLevel --e ./Expected/AcceptanceTests/ErrorWithSecretsVersionTolerant/ +-e ./Expected/AcceptanceTests/ErrorWithSecretsLowLevel/ -e ./Expected/AcceptanceTests/ExtensibleEnumsLowLevel -e ./Expected/AcceptanceTests/HeaderLowLevel -e ./Expected/AcceptanceTests/HttpLowLevel