-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
add custom policy #17340
Merged
Merged
add custom policy #17340
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c2ca12e
add custom policy
xiangyan99 4753c30
updates
xiangyan99 ee4677e
rename arguments
xiangyan99 bcf286f
udpates
xiangyan99 7fb21c0
update
xiangyan99 2ca0585
update
xiangyan99 a30224a
update
xiangyan99 1cba725
update tests
xiangyan99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,18 @@ | |
# -------------------------------------------------------------------------- | ||
|
||
import logging | ||
try: | ||
from collections.abc import Iterable | ||
except ImportError: | ||
from collections import Iterable | ||
from .configuration import Configuration | ||
from .pipeline import Pipeline | ||
from .pipeline.transport._base import PipelineClientBase | ||
from .pipeline.policies import ( | ||
ContentDecodePolicy, DistributedTracingPolicy, HttpLoggingPolicy, RequestIdPolicy | ||
ContentDecodePolicy, | ||
DistributedTracingPolicy, | ||
HttpLoggingPolicy, | ||
RequestIdPolicy, | ||
) | ||
from .pipeline.transport import RequestsTransport | ||
|
||
|
@@ -64,6 +71,10 @@ class PipelineClient(PipelineClientBase): | |
:keyword ~azure.core.configuration.Configuration config: If omitted, the standard configuration is used. | ||
:keyword Pipeline pipeline: If omitted, a Pipeline object is created and returned. | ||
:keyword list[HTTPPolicy] policies: If omitted, the standard policies of the configuration object is used. | ||
:keyword per_call_policies: If specified, the policies will be added into the policy list before RetryPolicy | ||
:paramtype per_call_policies: Union[HTTPPolicy, SansIOHTTPPolicy, list[HTTPPolicy], list[SansIOHTTPPolicy]] | ||
:keyword per_retry_policies: If specified, the policies will be added into the policy list after RetryPolicy | ||
:paramtype per_retry_policies: Union[HTTPPolicy, SansIOHTTPPolicy, list[HTTPPolicy], list[SansIOHTTPPolicy]] | ||
:keyword HttpTransport transport: If omitted, RequestsTransport is used for synchronous transport. | ||
:return: A pipeline object. | ||
:rtype: ~azure.core.pipeline.Pipeline | ||
|
@@ -102,20 +113,34 @@ def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use | |
policies = kwargs.get('policies') | ||
|
||
if policies is None: # [] is a valid policy list | ||
per_call_policies = kwargs.get('per_call_policies', []) | ||
per_retry_policies = kwargs.get('per_retry_policies', []) | ||
policies = [ | ||
RequestIdPolicy(**kwargs), | ||
config.headers_policy, | ||
config.user_agent_policy, | ||
config.proxy_policy, | ||
ContentDecodePolicy(**kwargs), | ||
config.redirect_policy, | ||
config.retry_policy, | ||
config.authentication_policy, | ||
config.custom_hook_policy, | ||
config.logging_policy, | ||
DistributedTracingPolicy(**kwargs), | ||
config.http_logging_policy or HttpLoggingPolicy(**kwargs) | ||
ContentDecodePolicy(**kwargs) | ||
] | ||
if isinstance(per_call_policies, Iterable): | ||
for policy in per_call_policies: | ||
policies.append(policy) | ||
else: | ||
policies.append(per_call_policies) | ||
|
||
policies = policies + [config.redirect_policy, | ||
config.retry_policy, | ||
config.authentication_policy, | ||
config.custom_hook_policy] | ||
Comment on lines
+131
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This causes a new |
||
if isinstance(per_retry_policies, Iterable): | ||
for policy in per_retry_policies: | ||
policies.append(policy) | ||
else: | ||
policies.append(per_retry_policies) | ||
|
||
policies = policies + [config.logging_policy, | ||
DistributedTracingPolicy(**kwargs), | ||
config.http_logging_policy or HttpLoggingPolicy(**kwargs)] | ||
|
||
if not transport: | ||
transport = RequestsTransport(**kwargs) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to explicitly iterate over
per_call_policies
.list.extend(iterable)
does the same thing.