From 86582bfa4dbbf44223cb77e5a00d004073d9d0f4 Mon Sep 17 00:00:00 2001 From: Krista Pratico Date: Wed, 3 Nov 2021 17:16:01 -0700 Subject: [PATCH] unredact some headers/query params at the debug info level (#21571) --- .../azure/ai/textanalytics/_base_client.py | 27 ++++++++++++++++++- .../textanalytics/aio/_base_client_async.py | 27 ++++++++++++++++++- 2 files changed, 52 insertions(+), 2 deletions(-) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_base_client.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_base_client.py index 9e2e10b79ad8..483a388761ea 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_base_client.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/_base_client.py @@ -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 @@ -39,6 +39,30 @@ 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, @@ -46,6 +70,7 @@ def __init__(self, endpoint, credential, **kwargs): 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 ) diff --git a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_base_client_async.py b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_base_client_async.py index 79b618b77ce8..7593f4c43028 100644 --- a/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_base_client_async.py +++ b/sdk/textanalytics/azure-ai-textanalytics/azure/ai/textanalytics/aio/_base_client_async.py @@ -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 @@ -30,6 +30,30 @@ 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, @@ -37,6 +61,7 @@ def __init__(self, endpoint, credential, **kwargs): 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 )