Skip to content

Commit

Permalink
unredact some headers/query params at the debug info level (Azure#21571)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristapratico authored Nov 4, 2021
1 parent 6935640 commit 86582bf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Licensed under the MIT License.
# ------------------------------------
from enum import Enum
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from azure.core.pipeline.policies import AzureKeyCredentialPolicy, HttpLoggingPolicy
from azure.core.credentials import AzureKeyCredential
from ._generated import TextAnalyticsClient as _TextAnalyticsClient
from ._policies import TextAnalyticsResponseHookPolicy
Expand Down Expand Up @@ -39,13 +39,38 @@ def _authentication_policy(credential):

class TextAnalyticsClientBase(object):
def __init__(self, endpoint, credential, **kwargs):
http_logging_policy = HttpLoggingPolicy(**kwargs)
http_logging_policy.allowed_header_names.update(
{
"Operation-Location",
"apim-request-id",
"x-envoy-upstream-service-time",
"Strict-Transport-Security",
"x-content-type-options",
}
)
http_logging_policy.allowed_query_params.update(
{
"model-version",
"showStats",
"loggingOptOut",
"domain",
"stringIndexType",
"piiCategories",
"$top",
"$skip",
"opinionMining",
}
)

self._client = _TextAnalyticsClient(
endpoint=endpoint,
credential=credential,
api_version=kwargs.pop("api_version", DEFAULT_API_VERSION),
sdk_moniker=USER_AGENT,
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
custom_hook_policy=kwargs.pop("custom_hook_policy", TextAnalyticsResponseHookPolicy(**kwargs)),
http_logging_policy=kwargs.pop("http_logging_policy", http_logging_policy),
**kwargs
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# ------------------------------------
from typing import Any
from azure.core.credentials import AzureKeyCredential
from azure.core.pipeline.policies import AzureKeyCredentialPolicy
from azure.core.pipeline.policies import AzureKeyCredentialPolicy, HttpLoggingPolicy
from .._generated.aio import TextAnalyticsClient as _TextAnalyticsClient
from .._policies import TextAnalyticsResponseHookPolicy
from .._user_agent import USER_AGENT
Expand All @@ -30,13 +30,38 @@ def _authentication_policy(credential):

class AsyncTextAnalyticsClientBase(object):
def __init__(self, endpoint, credential, **kwargs):
http_logging_policy = HttpLoggingPolicy(**kwargs)
http_logging_policy.allowed_header_names.update(
{
"Operation-Location",
"apim-request-id",
"x-envoy-upstream-service-time",
"Strict-Transport-Security",
"x-content-type-options",
}
)
http_logging_policy.allowed_query_params.update(
{
"model-version",
"showStats",
"loggingOptOut",
"domain",
"stringIndexType",
"piiCategories",
"$top",
"$skip",
"opinionMining",
}
)

self._client = _TextAnalyticsClient(
endpoint=endpoint,
credential=credential,
api_version=kwargs.pop("api_version", DEFAULT_API_VERSION),
sdk_moniker=USER_AGENT,
authentication_policy=kwargs.pop("authentication_policy", _authentication_policy(credential)),
custom_hook_policy=kwargs.pop("custom_hook_policy", TextAnalyticsResponseHookPolicy(**kwargs)),
http_logging_policy=kwargs.pop("http_logging_policy", http_logging_policy),
**kwargs
)

Expand Down

0 comments on commit 86582bf

Please sign in to comment.