From dce5c643da2d43f19fb02105b54933de9081a47a Mon Sep 17 00:00:00 2001 From: iscai-msft <43154838+iscai-msft@users.noreply.github.com> Date: Thu, 17 Feb 2022 21:10:25 -0500 Subject: [PATCH] [recoveryservicesbackup] fix multiple pages paging (#23089) * patch activestamp code * patch passivestamp code * use dict comprehension * fix for azure-cli * update passivestamp clients to explicitly state credential * update method signatures for patched clients * udpate docs for patched clients * update changelog * update version file Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com> --- .../CHANGELOG.md | 6 +++ .../mgmt/recoveryservicesbackup/_version.py | 2 +- .../activestamp/_patch.py | 50 ++++++++++++++++++- .../activestamp/_version.py | 2 +- .../activestamp/aio/_patch.py | 32 +++++++++++- .../passivestamp/_patch.py | 50 ++++++++++++++++++- .../passivestamp/_version.py | 2 +- .../passivestamp/aio/_patch.py | 32 +++++++++++- 8 files changed, 169 insertions(+), 7 deletions(-) diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/CHANGELOG.md b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/CHANGELOG.md index 7be3ad076b84..a5c466bcf370 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/CHANGELOG.md +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/CHANGELOG.md @@ -1,5 +1,11 @@ # Release History +## 4.1.1 (2022-02-18) + +**Bug Fixes** + + - Fix multi-page paging #23089 + ## 4.1.0 (2022-02-15) **Features** diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/_version.py b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/_version.py index 73d8f69961be..83801515a450 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/_version.py +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "4.1.0" +VERSION = "4.1.1" diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_patch.py b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_patch.py index 74e48ecd07cf..56184987595f 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_patch.py +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_patch.py @@ -24,8 +24,56 @@ # IN THE SOFTWARE. # # -------------------------------------------------------------------------- +from typing import Any, List, TYPE_CHECKING +import importlib +import urllib.parse +from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated +from azure.core.pipeline.policies import SansIOHTTPPolicy + +if TYPE_CHECKING: + from azure.core.credentials import TokenCredential + +class RemoveDuplicateParamsPolicy(SansIOHTTPPolicy): + def __init__(self, duplicate_param_names): + # type: (List[str]) -> None + self.duplicate_param_names = duplicate_param_names + + def on_request(self, request): + parsed_url = urllib.parse.urlparse(request.http_request.url) + query_params = urllib.parse.parse_qs(parsed_url.query) + filtered_query_params = { + k: v[-1:] if k in self.duplicate_param_names else v + for k, v in query_params.items() + } + request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(filtered_query_params, doseq=True) + return super().on_request(request) + +DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"]) + +class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated): + __doc__ = RecoveryServicesBackupClientGenerated.__doc__ + def __init__( + self, + credential: "TokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + per_call_policies = kwargs.pop("per_call_policies", []) + try: + per_call_policies.append(DUPLICATE_PARAMS_POLICY) + except AttributeError: + per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY] + super().__init__( + credential=credential, + subscription_id=subscription_id, + base_url=base_url, + per_call_policies=per_call_policies, + **kwargs + ) # 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 \ No newline at end of file + curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp") + curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_version.py b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_version.py index 73d8f69961be..83801515a450 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_version.py +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "4.1.0" +VERSION = "4.1.1" diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/aio/_patch.py b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/aio/_patch.py index 74e48ecd07cf..eea0326b9de6 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/aio/_patch.py +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/aio/_patch.py @@ -24,8 +24,38 @@ # IN THE SOFTWARE. # # -------------------------------------------------------------------------- +from typing import Any, TYPE_CHECKING +import importlib +from .._patch import DUPLICATE_PARAMS_POLICY +from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated + +if TYPE_CHECKING: + from azure.core.credentials_async import AsyncTokenCredential + +class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated): + __doc__ = RecoveryServicesBackupClientGenerated.__doc__ + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + per_call_policies = kwargs.pop("per_call_policies", []) + try: + per_call_policies.append(DUPLICATE_PARAMS_POLICY) + except AttributeError: + per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY] + super().__init__( + credential=credential, + subscription_id=subscription_id, + base_url=base_url, + per_call_policies=per_call_policies, + **kwargs + ) # 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 \ No newline at end of file + curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp.aio") + curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_patch.py b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_patch.py index 74e48ecd07cf..026ba53859a1 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_patch.py +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_patch.py @@ -24,8 +24,56 @@ # IN THE SOFTWARE. # # -------------------------------------------------------------------------- +from typing import TYPE_CHECKING, Any, List, TYPE_CHECKING +import importlib +import urllib.parse +from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated +from azure.core.pipeline.policies import SansIOHTTPPolicy + +if TYPE_CHECKING: + from azure.core.credentials import TokenCredential + +class RemoveDuplicateParamsPolicy(SansIOHTTPPolicy): + def __init__(self, duplicate_param_names): + # type: (List[str]) -> None + self.duplicate_param_names = duplicate_param_names + + def on_request(self, request): + parsed_url = urllib.parse.urlparse(request.http_request.url) + query_params = urllib.parse.parse_qs(parsed_url.query) + filtered_query_params = { + k: v[-1:] if k in self.duplicate_param_names else v + for k, v in query_params.items() + } + request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(filtered_query_params, doseq=True) + return super().on_request(request) + +DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"]) + +class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated): + __doc__ = RecoveryServicesBackupPassiveClientGenerated.__doc__ + def __init__( + self, + credential: "TokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + per_call_policies = kwargs.pop("per_call_policies", []) + try: + per_call_policies.append(DUPLICATE_PARAMS_POLICY) + except AttributeError: + per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY] + super().__init__( + credential=credential, + subscription_id=subscription_id, + base_url=base_url, + per_call_policies=per_call_policies, + **kwargs + ) # 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 \ No newline at end of file + curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp") + curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_version.py b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_version.py index 73d8f69961be..83801515a450 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_version.py +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_version.py @@ -6,4 +6,4 @@ # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -VERSION = "4.1.0" +VERSION = "4.1.1" diff --git a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/aio/_patch.py b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/aio/_patch.py index 74e48ecd07cf..0de9ec463126 100644 --- a/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/aio/_patch.py +++ b/sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/aio/_patch.py @@ -24,8 +24,38 @@ # IN THE SOFTWARE. # # -------------------------------------------------------------------------- +from typing import Any, TYPE_CHECKING +import importlib +from .._patch import DUPLICATE_PARAMS_POLICY +from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated + +if TYPE_CHECKING: + from azure.core.credentials_async import AsyncTokenCredential + +class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated): + __doc__ = RecoveryServicesBackupPassiveClientGenerated.__doc__ + def __init__( + self, + credential: "AsyncTokenCredential", + subscription_id: str, + base_url: str = "https://management.azure.com", + **kwargs: Any + ) -> None: + per_call_policies = kwargs.pop("per_call_policies", []) + try: + per_call_policies.append(DUPLICATE_PARAMS_POLICY) + except AttributeError: + per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY] + super().__init__( + credential=credential, + subscription_id=subscription_id, + base_url=base_url, + per_call_policies=per_call_policies, + **kwargs + ) # 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 \ No newline at end of file + curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp.aio") + curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient