Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asking as I don't know how this works on Python... if the service introduces new headers/query parameters, this needs to be updated? or will the user be able to add more logging policies if they desire? -> it might not be needed if the list is always updated though

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a list of allowed headers in the policy, but it's general and doesn't include service-specific headers or query params. It can always be updated if the service starts sending anything new.

**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