Skip to content

Commit

Permalink
[recoveryservicesbackup] fix multiple pages paging (Azure#23089)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
2 people authored and rakshith91 committed Apr 10, 2022
1 parent 765661d commit dce5c64
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp")
curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp.aio")
curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient
Original file line number Diff line number Diff line change
Expand Up @@ -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
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp")
curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp.aio")
curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient

0 comments on commit dce5c64

Please sign in to comment.