Skip to content

Commit

Permalink
unredact headers and query params for logging (#18117)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico authored Apr 19, 2021
1 parent 064e436 commit 2ada230
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
)
from ._user_agent import USER_AGENT
from ._polling import TranslationPolling
from ._helpers import get_http_logging_policy
if TYPE_CHECKING:
from azure.core.paging import ItemPaged

Expand Down Expand Up @@ -62,12 +63,14 @@ def __init__(self, endpoint, credential, **kwargs):
authentication_policy = AzureKeyCredentialPolicy(
name=COGNITIVE_KEY_HEADER, credential=credential
)

self._client = _BatchDocumentTranslationClient(
endpoint=endpoint,
credential=credential, # type: ignore
api_version=self._api_version,
sdk_moniker=USER_AGENT,
authentication_policy=authentication_policy,
http_logging_policy=get_http_logging_policy(),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# coding=utf-8
# ------------------------------------
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# ------------------------------------

from azure.core.pipeline.policies import HttpLoggingPolicy


def get_http_logging_policy(**kwargs):
http_logging_policy = HttpLoggingPolicy(**kwargs)
http_logging_policy.allowed_header_names.update(
{
"Operation-Location",
"Content-Encoding",
"Vary",
"apim-request-id",
"X-RequestId",
"Set-Cookie",
"X-Powered-By",
"Strict-Transport-Security",
"x-content-type-options"
}
)
http_logging_policy.allowed_query_params.update(
{
"$top",
"$skip",
"$maxpagesize",
"ids",
"statuses",
"createdDateTimeUtcStart",
"createdDateTimeUtcEnd",
"$orderBy"
}
)
return http_logging_policy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
FileFormat,
DocumentStatusResult
)
from .._helpers import get_http_logging_policy
from .._polling import TranslationPolling
COGNITIVE_KEY_HEADER = "Ocp-Apim-Subscription-Key"

Expand Down Expand Up @@ -70,6 +71,7 @@ def __init__(
api_version=self._api_version,
sdk_moniker=USER_AGENT,
authentication_policy=authentication_policy,
http_logging_policy=get_http_logging_policy(),
**kwargs
)

Expand Down

0 comments on commit 2ada230

Please sign in to comment.