Skip to content

Commit de7168a

Browse files
authored
Set http_logging_policy in Configuration (#12218)
* allow user to set http_logging_policy in azure core * add tests for setting http logging policy in azure core * allow user to set http_logging_policy in azure mgmt core * fix default allowed headers for ARMHttpLoggingPolicy * add tests for setting http logging policy in azure mgmt core * deprecate WHITELIST, switch to ALLOWLIST in HttpLoggingPolicy * deprecate WHITELIST, switch to ALLOWLIST in ARMHttpLoggingPolicy * udpate changelog * change fix for ARMHttpLoggingPolicy default allowed headers * update version * Revert "deprecate WHITELIST, switch to ALLOWLIST in ARMHttpLoggingPolicy" This reverts commit 4175acd. * Revert "deprecate WHITELIST, switch to ALLOWLIST in HttpLoggingPolicy" This reverts commit 64b3246. * switch keyword docstring to ivar for most config policies * removed __init__ in azure-mgmt-core async tests * use the current class attribute to get the default allowed headers
1 parent 72d461c commit de7168a

14 files changed

Lines changed: 155 additions & 18 deletions

File tree

sdk/core/azure-core/CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11

22
# Release History
33

4-
## 1.6.1 (Unreleased)
4+
## 1.7.0 (Unreleased)
55

66
### Bug fixes
77

88
- `AzureKeyCredentialPolicy` will now accept (and ignore) passed in kwargs #11963
99
- Better error messages if passed endpoint is incorrect #12106
1010
- Do not JSON encore a string if content type is "text" #12137
1111

12+
### Features
13+
14+
- Added `http_logging_policy` property on the `Configuration` object, allowing users to individually
15+
set the http logging policy of the config #12218
16+
1217
## 1.6.0 (2020-06-03)
1318

1419
### Bug fixes

sdk/core/azure-core/azure/core/_pipeline_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use
114114
config.custom_hook_policy,
115115
config.logging_policy,
116116
DistributedTracingPolicy(**kwargs),
117-
HttpLoggingPolicy(**kwargs)
117+
config.http_logging_policy or HttpLoggingPolicy(**kwargs)
118118
]
119119

120120
if not transport:

sdk/core/azure-core/azure/core/_pipeline_client_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def _build_pipeline(self, config, **kwargs): # pylint: disable=no-self-use
113113
config.custom_hook_policy,
114114
config.logging_policy,
115115
DistributedTracingPolicy(**kwargs),
116-
HttpLoggingPolicy(**kwargs),
116+
config.http_logging_policy or HttpLoggingPolicy(**kwargs)
117117
]
118118

119119
if not transport:

sdk/core/azure-core/azure/core/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
# regenerated.
1010
# --------------------------------------------------------------------------
1111

12-
VERSION = "1.6.1"
12+
VERSION = "1.7.0"

sdk/core/azure-core/azure/core/configuration.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ class Configuration(object):
3434
Configuration to construct the pipeline correctly, as well as inserting any
3535
unexposed/non-configurable policies.
3636
37-
:keyword headers_policy: Provides parameters for custom or additional headers to be sent with the request.
38-
:keyword proxy_policy: Provides configuration parameters for proxy.
39-
:keyword redirect_policy: Provides configuration parameters for redirects.
40-
:keyword retry_policy: Provides configuration parameters for retries in the pipeline.
41-
:keyword custom_hook_policy: Provides configuration parameters for a custom hook.
42-
:keyword logging_policy: Provides configuration parameters for logging.
43-
:keyword user_agent_policy: Provides configuration parameters to append custom values to the
37+
:ivar headers_policy: Provides parameters for custom or additional headers to be sent with the request.
38+
:ivar proxy_policy: Provides configuration parameters for proxy.
39+
:ivar redirect_policy: Provides configuration parameters for redirects.
40+
:ivar retry_policy: Provides configuration parameters for retries in the pipeline.
41+
:ivar custom_hook_policy: Provides configuration parameters for a custom hook.
42+
:ivar logging_policy: Provides configuration parameters for logging.
43+
:ivar http_logging_policy: Provides configuration parameters for HTTP specific logging.
44+
:ivar user_agent_policy: Provides configuration parameters to append custom values to the
4445
User-Agent header.
45-
:keyword authentication_policy: Provides configuration parameters for adding a bearer token Authorization
46+
:ivar authentication_policy: Provides configuration parameters for adding a bearer token Authorization
4647
header to requests.
4748
:keyword polling_interval: Polling interval while doing LRO operations, if Retry-After is not set.
4849
@@ -74,6 +75,9 @@ def __init__(self, **kwargs):
7475
# Logger configuration
7576
self.logging_policy = None
7677

78+
# Http logger configuration
79+
self.http_logging_policy = None
80+
7781
# User Agent configuration
7882
self.user_agent_policy = None
7983

sdk/core/azure-core/azure/core/pipeline/policies/_universal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ def __init__(self, logger=None, **kwargs): # pylint: disable=unused-argument
371371
"azure.core.pipeline.policies.http_logging_policy"
372372
)
373373
self.allowed_query_params = set()
374-
self.allowed_header_names = set(HttpLoggingPolicy.DEFAULT_HEADERS_WHITELIST)
374+
self.allowed_header_names = set(self.__class__.DEFAULT_HEADERS_WHITELIST)
375375

376376
def _redact_query_param(self, key, value):
377377
lower_case_allowed_query_params = [

sdk/core/azure-core/tests/azure_core_asynctests/test_pipeline.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,19 @@
3131
UserAgentPolicy,
3232
AsyncRedirectPolicy,
3333
AsyncHTTPPolicy,
34-
AsyncRetryPolicy)
34+
AsyncRetryPolicy,
35+
HttpLoggingPolicy
36+
)
3537
from azure.core.pipeline.transport import (
3638
AsyncHttpTransport,
3739
HttpRequest,
3840
AsyncioRequestsTransport,
3941
TrioRequestsTransport,
4042
AioHttpTransport
4143
)
44+
45+
from azure.core.configuration import Configuration
46+
from azure.core import AsyncPipelineClient
4247
from azure.core.exceptions import AzureError
4348

4449
import aiohttp
@@ -143,6 +148,26 @@ async def do():
143148

144149
response = trio.run(do)
145150

151+
def test_default_http_logging_policy():
152+
config = Configuration()
153+
pipeline_client = AsyncPipelineClient(base_url="test")
154+
pipeline = pipeline_client._build_pipeline(config)
155+
http_logging_policy = pipeline._impl_policies[-1]._policy
156+
assert http_logging_policy.allowed_header_names == HttpLoggingPolicy.DEFAULT_HEADERS_WHITELIST
157+
158+
def test_pass_in_http_logging_policy():
159+
config = Configuration()
160+
http_logging_policy = HttpLoggingPolicy()
161+
http_logging_policy.allowed_header_names.update(
162+
{"x-ms-added-header"}
163+
)
164+
config.http_logging_policy = http_logging_policy
165+
166+
pipeline_client = AsyncPipelineClient(base_url="test")
167+
pipeline = pipeline_client._build_pipeline(config)
168+
http_logging_policy = pipeline._impl_policies[-1]._policy
169+
assert http_logging_policy.allowed_header_names == HttpLoggingPolicy.DEFAULT_HEADERS_WHITELIST.union({"x-ms-added-header"})
170+
146171
@pytest.mark.asyncio
147172
async def test_conf_async_requests():
148173

sdk/core/azure-core/tests/test_pipeline.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@
4646

4747
from azure.core.configuration import Configuration
4848
from azure.core.pipeline import Pipeline
49+
from azure.core import PipelineClient
4950
from azure.core.pipeline.policies import (
5051
SansIOHTTPPolicy,
5152
UserAgentPolicy,
5253
RedirectPolicy,
54+
HttpLoggingPolicy
5355
)
5456
from azure.core.pipeline.transport._base import PipelineClientBase
5557
from azure.core.pipeline.transport import (
@@ -60,6 +62,26 @@
6062

6163
from azure.core.exceptions import AzureError
6264

65+
def test_default_http_logging_policy():
66+
config = Configuration()
67+
pipeline_client = PipelineClient(base_url="test")
68+
pipeline = pipeline_client._build_pipeline(config)
69+
http_logging_policy = pipeline._impl_policies[-1]._policy
70+
assert http_logging_policy.allowed_header_names == HttpLoggingPolicy.DEFAULT_HEADERS_WHITELIST
71+
72+
def test_pass_in_http_logging_policy():
73+
config = Configuration()
74+
http_logging_policy = HttpLoggingPolicy()
75+
http_logging_policy.allowed_header_names.update(
76+
{"x-ms-added-header"}
77+
)
78+
config.http_logging_policy = http_logging_policy
79+
80+
pipeline_client = PipelineClient(base_url="test")
81+
pipeline = pipeline_client._build_pipeline(config)
82+
http_logging_policy = pipeline._impl_policies[-1]._policy
83+
assert http_logging_policy.allowed_header_names == HttpLoggingPolicy.DEFAULT_HEADERS_WHITELIST.union({"x-ms-added-header"})
84+
6385

6486
def test_sans_io_exception():
6587
class BrokenSender(HttpTransport):

sdk/core/azure-mgmt-core/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11

22
# Release History
33

4+
## 1.2.0 (Unreleased)
5+
6+
### Bug Fixes
7+
8+
- The `allowed_header_names` property of ARMHttpLoggingPolicy now includes the management plane specific
9+
allowed headers #12218
10+
11+
### Features
12+
13+
- Added `http_logging_policy` property on the `Configuration` object, allowing users to individually
14+
set the http logging policy of the config #12218
15+
416
## 1.1.0 (2020-05-04)
517

618
### Features

sdk/core/azure-mgmt-core/azure/mgmt/core/_async_pipeline_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ def _default_policies(config, **kwargs):
6565
config.custom_hook_policy,
6666
config.logging_policy,
6767
DistributedTracingPolicy(**kwargs),
68-
ARMHttpLoggingPolicy(**kwargs),
68+
config.http_logging_policy or ARMHttpLoggingPolicy(**kwargs),
6969
]

0 commit comments

Comments
 (0)