Skip to content

Commit 42da414

Browse files
iscai-msftmsyyc
andauthored
[recoveryservicesbackup] fix multiple pages paging (Azure#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 <[email protected]>
1 parent 3e03206 commit 42da414

File tree

8 files changed

+169
-7
lines changed

8 files changed

+169
-7
lines changed

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Release History
22

3+
## 4.1.1 (2022-02-18)
4+
5+
**Bug Fixes**
6+
7+
- Fix multi-page paging #23089
8+
39
## 4.1.0 (2022-02-15)
410

511
**Features**

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
VERSION = "4.1.0"
9+
VERSION = "4.1.1"

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_patch.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,56 @@
2424
# IN THE SOFTWARE.
2525
#
2626
# --------------------------------------------------------------------------
27+
from typing import Any, List, TYPE_CHECKING
28+
import importlib
29+
import urllib.parse
30+
from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated
31+
from azure.core.pipeline.policies import SansIOHTTPPolicy
32+
33+
if TYPE_CHECKING:
34+
from azure.core.credentials import TokenCredential
35+
36+
class RemoveDuplicateParamsPolicy(SansIOHTTPPolicy):
37+
def __init__(self, duplicate_param_names):
38+
# type: (List[str]) -> None
39+
self.duplicate_param_names = duplicate_param_names
40+
41+
def on_request(self, request):
42+
parsed_url = urllib.parse.urlparse(request.http_request.url)
43+
query_params = urllib.parse.parse_qs(parsed_url.query)
44+
filtered_query_params = {
45+
k: v[-1:] if k in self.duplicate_param_names else v
46+
for k, v in query_params.items()
47+
}
48+
request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(filtered_query_params, doseq=True)
49+
return super().on_request(request)
50+
51+
DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"])
52+
53+
class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated):
54+
__doc__ = RecoveryServicesBackupClientGenerated.__doc__
55+
def __init__(
56+
self,
57+
credential: "TokenCredential",
58+
subscription_id: str,
59+
base_url: str = "https://management.azure.com",
60+
**kwargs: Any
61+
) -> None:
62+
per_call_policies = kwargs.pop("per_call_policies", [])
63+
try:
64+
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
65+
except AttributeError:
66+
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
67+
super().__init__(
68+
credential=credential,
69+
subscription_id=subscription_id,
70+
base_url=base_url,
71+
per_call_policies=per_call_policies,
72+
**kwargs
73+
)
2774

2875
# This file is used for handwritten extensions to the generated code. Example:
2976
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
3077
def patch_sdk():
31-
pass
78+
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp")
79+
curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
VERSION = "4.1.0"
9+
VERSION = "4.1.1"

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/activestamp/aio/_patch.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,38 @@
2424
# IN THE SOFTWARE.
2525
#
2626
# --------------------------------------------------------------------------
27+
from typing import Any, TYPE_CHECKING
28+
import importlib
29+
from .._patch import DUPLICATE_PARAMS_POLICY
30+
from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated
31+
32+
if TYPE_CHECKING:
33+
from azure.core.credentials_async import AsyncTokenCredential
34+
35+
class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated):
36+
__doc__ = RecoveryServicesBackupClientGenerated.__doc__
37+
def __init__(
38+
self,
39+
credential: "AsyncTokenCredential",
40+
subscription_id: str,
41+
base_url: str = "https://management.azure.com",
42+
**kwargs: Any
43+
) -> None:
44+
per_call_policies = kwargs.pop("per_call_policies", [])
45+
try:
46+
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
47+
except AttributeError:
48+
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
49+
super().__init__(
50+
credential=credential,
51+
subscription_id=subscription_id,
52+
base_url=base_url,
53+
per_call_policies=per_call_policies,
54+
**kwargs
55+
)
2756

2857
# This file is used for handwritten extensions to the generated code. Example:
2958
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
3059
def patch_sdk():
31-
pass
60+
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.activestamp.aio")
61+
curr_package.RecoveryServicesBackupClient = RecoveryServicesBackupClient

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_patch.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,56 @@
2424
# IN THE SOFTWARE.
2525
#
2626
# --------------------------------------------------------------------------
27+
from typing import TYPE_CHECKING, Any, List, TYPE_CHECKING
28+
import importlib
29+
import urllib.parse
30+
from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated
31+
from azure.core.pipeline.policies import SansIOHTTPPolicy
32+
33+
if TYPE_CHECKING:
34+
from azure.core.credentials import TokenCredential
35+
36+
class RemoveDuplicateParamsPolicy(SansIOHTTPPolicy):
37+
def __init__(self, duplicate_param_names):
38+
# type: (List[str]) -> None
39+
self.duplicate_param_names = duplicate_param_names
40+
41+
def on_request(self, request):
42+
parsed_url = urllib.parse.urlparse(request.http_request.url)
43+
query_params = urllib.parse.parse_qs(parsed_url.query)
44+
filtered_query_params = {
45+
k: v[-1:] if k in self.duplicate_param_names else v
46+
for k, v in query_params.items()
47+
}
48+
request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(filtered_query_params, doseq=True)
49+
return super().on_request(request)
50+
51+
DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"])
52+
53+
class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated):
54+
__doc__ = RecoveryServicesBackupPassiveClientGenerated.__doc__
55+
def __init__(
56+
self,
57+
credential: "TokenCredential",
58+
subscription_id: str,
59+
base_url: str = "https://management.azure.com",
60+
**kwargs: Any
61+
) -> None:
62+
per_call_policies = kwargs.pop("per_call_policies", [])
63+
try:
64+
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
65+
except AttributeError:
66+
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
67+
super().__init__(
68+
credential=credential,
69+
subscription_id=subscription_id,
70+
base_url=base_url,
71+
per_call_policies=per_call_policies,
72+
**kwargs
73+
)
2774

2875
# This file is used for handwritten extensions to the generated code. Example:
2976
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
3077
def patch_sdk():
31-
pass
78+
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp")
79+
curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
77
# --------------------------------------------------------------------------
88

9-
VERSION = "4.1.0"
9+
VERSION = "4.1.1"

sdk/recoveryservices/azure-mgmt-recoveryservicesbackup/azure/mgmt/recoveryservicesbackup/passivestamp/aio/_patch.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,38 @@
2424
# IN THE SOFTWARE.
2525
#
2626
# --------------------------------------------------------------------------
27+
from typing import Any, TYPE_CHECKING
28+
import importlib
29+
from .._patch import DUPLICATE_PARAMS_POLICY
30+
from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated
31+
32+
if TYPE_CHECKING:
33+
from azure.core.credentials_async import AsyncTokenCredential
34+
35+
class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated):
36+
__doc__ = RecoveryServicesBackupPassiveClientGenerated.__doc__
37+
def __init__(
38+
self,
39+
credential: "AsyncTokenCredential",
40+
subscription_id: str,
41+
base_url: str = "https://management.azure.com",
42+
**kwargs: Any
43+
) -> None:
44+
per_call_policies = kwargs.pop("per_call_policies", [])
45+
try:
46+
per_call_policies.append(DUPLICATE_PARAMS_POLICY)
47+
except AttributeError:
48+
per_call_policies = [per_call_policies, DUPLICATE_PARAMS_POLICY]
49+
super().__init__(
50+
credential=credential,
51+
subscription_id=subscription_id,
52+
base_url=base_url,
53+
per_call_policies=per_call_policies,
54+
**kwargs
55+
)
2756

2857
# This file is used for handwritten extensions to the generated code. Example:
2958
# https://github.com/Azure/azure-sdk-for-python/blob/main/doc/dev/customize_code/how-to-patch-sdk-code.md
3059
def patch_sdk():
31-
pass
60+
curr_package = importlib.import_module("azure.mgmt.recoveryservicesbackup.passivestamp.aio")
61+
curr_package.RecoveryServicesBackupPassiveClient = RecoveryServicesBackupPassiveClient

0 commit comments

Comments
 (0)