Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[recoveryservicesbackup] fix multiple pages paging #23089

Merged
merged 9 commits into from
Feb 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,42 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import copy
from typing import List
import importlib
import urllib.parse
from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated
from azure.core.pipeline.policies import SansIOHTTPPolicy

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)
updated_query_params = copy.copy(query_params)
for query in query_params:
if query in self.duplicate_param_names and (isinstance(query_params[query], list) and len(query_params[query]) > 1):
updated_query_params[query] = [query_params[query][-1]]
iscai-msft marked this conversation as resolved.
Show resolved Hide resolved
# service returned will be later in the url because of how we format
request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(updated_query_params, doseq=True)
return super().on_request(request)

DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"])

class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated):
def __init__(self, *args, **kwargs):
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__(*args, 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 @@ -24,8 +24,21 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import importlib
from .._patch import DUPLICATE_PARAMS_POLICY
from ._recovery_services_backup_client import RecoveryServicesBackupClient as RecoveryServicesBackupClientGenerated

class RecoveryServicesBackupClient(RecoveryServicesBackupClientGenerated):
def __init__(self, *args, **kwargs):
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__(*args, 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,42 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import copy
from typing import List
import importlib
import urllib.parse
from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated
from azure.core.pipeline.policies import SansIOHTTPPolicy

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)
updated_query_params = copy.copy(query_params)
for query in query_params:
if query in self.duplicate_param_names and (isinstance(query_params[query], list) and len(query_params[query]) > 1):
updated_query_params[query] = [query_params[query][-1]]
# service returned will be later in the url because of how we format
request.http_request.url = request.http_request.url.replace(parsed_url.query, "") + urllib.parse.urlencode(updated_query_params, doseq=True)
return super().on_request(request)

DUPLICATE_PARAMS_POLICY = RemoveDuplicateParamsPolicy(duplicate_param_names=["$filter", "$skiptoken", "api-version"])

class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated):
def __init__(self, *args, **kwargs):
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__(*args, 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 @@ -24,8 +24,21 @@
# IN THE SOFTWARE.
#
# --------------------------------------------------------------------------
import importlib
from .._patch import DUPLICATE_PARAMS_POLICY
from ._recovery_services_backup_passive_client import RecoveryServicesBackupPassiveClient as RecoveryServicesBackupPassiveClientGenerated

class RecoveryServicesBackupPassiveClient(RecoveryServicesBackupPassiveClientGenerated):
def __init__(self, *args, **kwargs):
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__(*args, 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