-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Description
Is your feature request related to a problem? Please describe.
I am trying to work around #8313 by adding a new custom policy called ExternalBearerTokenCredentialPolicy, but I find it difficult.
The only way to change the default policy list is to override the whole list by passing policies in ARMPipelineClient's kwargs:
azure-sdk-for-python/sdk/network/azure-mgmt-network/azure/mgmt/network/_network_management_client.py
Lines 72 to 73 in ad5308d
| self._config = NetworkManagementClientConfiguration(credential, subscription_id, **kwargs) | |
| self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs) |
When ARMPipelineClient is created without policies argument, it builds the default policy list from config=self._config:
azure-sdk-for-python/sdk/core/azure-mgmt-core/azure/mgmt/core/_pipeline_client.py
Lines 54 to 69 in de7168a
| def _default_policies(config, **kwargs): | |
| return [ | |
| RequestIdPolicy(**kwargs), | |
| ARMAutoResourceProviderRegistrationPolicy(), | |
| 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 ARMHttpLoggingPolicy(**kwargs), | |
| ] |
In order to add a custom policy to the default policy list, I must also manually create all policies created by NetworkManagementClientConfiguration:
azure-sdk-for-python/sdk/network/azure-mgmt-network/azure/mgmt/network/_configuration.py
Lines 51 to 66 in 3bf5688
| def _configure( | |
| self, | |
| **kwargs # type: Any | |
| ): | |
| # type: (...) -> None | |
| self.user_agent_policy = kwargs.get('user_agent_policy') or policies.UserAgentPolicy(**kwargs) | |
| self.headers_policy = kwargs.get('headers_policy') or policies.HeadersPolicy(**kwargs) | |
| self.proxy_policy = kwargs.get('proxy_policy') or policies.ProxyPolicy(**kwargs) | |
| self.logging_policy = kwargs.get('logging_policy') or policies.NetworkTraceLoggingPolicy(**kwargs) | |
| self.http_logging_policy = kwargs.get('http_logging_policy') or ARMHttpLoggingPolicy(**kwargs) | |
| self.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**kwargs) | |
| self.custom_hook_policy = kwargs.get('custom_hook_policy') or policies.CustomHookPolicy(**kwargs) | |
| self.redirect_policy = kwargs.get('redirect_policy') or policies.RedirectPolicy(**kwargs) | |
| self.authentication_policy = kwargs.get('authentication_policy') | |
| if self.credential and not self.authentication_policy: | |
| self.authentication_policy = policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs) |
This apparently seems too complicated.
Describe the solution you'd like
SDKs should expose the ability to add custom policies to the default policy list.