Skip to content

Commit

Permalink
CodeGen from PR 31023 in Azure/azure-rest-api-specs
Browse files Browse the repository at this point in the history
Merge 65531c62d15d5ba0d984db64a28ce474f0b93669 into cfe318beba82c1e5bda6a600f91de32cba814364
  • Loading branch information
SDKAuto committed Oct 19, 2024
1 parent 5aa70de commit 32d60b4
Show file tree
Hide file tree
Showing 96 changed files with 17,698 additions and 10,206 deletions.
5 changes: 2 additions & 3 deletions sdk/face/azure-ai-vision-face/_meta.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"commit": "37acfe2967e5e1be1169146ac461eb1875c9476e",
"commit": "aab95d1ee6f8012dfdba71cc771a313203c23ca7",
"repository_url": "https://github.com/Azure/azure-rest-api-specs",
"typespec_src": "specification/ai/Face",
"@azure-tools/typespec-python": "0.23.8",
"@autorest/python": "6.13.15"
"@azure-tools/typespec-python": "0.36.0"
}
14 changes: 10 additions & 4 deletions sdk/face/azure-ai-vision-face/azure/ai/vision/face/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,25 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._patch import FaceClient
from ._patch import FaceSessionClient
from ._client import FaceAdministrationClient
from ._client import FaceClient
from ._client import FaceSessionClient
from ._version import VERSION

__version__ = VERSION


try:
from ._patch import __all__ as _patch_all
from ._patch import * # pylint: disable=unused-wildcard-import
except ImportError:
_patch_all = []
from ._patch import patch_sdk as _patch_sdk

__all__ = [
"FaceAdministrationClient",
"FaceClient",
"FaceSessionClient",
]

__all__.extend([p for p in _patch_all if p not in __all__]) # pyright: ignore

_patch_sdk()
120 changes: 109 additions & 11 deletions sdk/face/azure-ai-vision-face/azure/ai/vision/face/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,120 @@

from copy import deepcopy
from typing import Any, TYPE_CHECKING, Union
from typing_extensions import Self

from azure.core import PipelineClient
from azure.core.credentials import AzureKeyCredential
from azure.core.pipeline import policies
from azure.core.rest import HttpRequest, HttpResponse

from ._configuration import FaceClientConfiguration, FaceSessionClientConfiguration
from ._operations import FaceClientOperationsMixin, FaceSessionClientOperationsMixin
from ._configuration import (
FaceAdministrationClientConfiguration,
FaceClientConfiguration,
FaceSessionClientConfiguration,
)
from ._serialization import Deserializer, Serializer
from .operations import (
FaceClientOperationsMixin,
FaceSessionClientOperationsMixin,
LargeFaceListOperations,
LargePersonGroupOperations,
)

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential


class FaceClient(FaceClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
class FaceAdministrationClient:
"""FaceAdministrationClient.
:ivar large_face_list: LargeFaceListOperations operations
:vartype large_face_list: azure.ai.vision.face.operations.LargeFaceListOperations
:ivar large_person_group: LargePersonGroupOperations operations
:vartype large_person_group: azure.ai.vision.face.operations.LargePersonGroupOperations
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
https://{resource-name}.cognitiveservices.azure.com). Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: API Version. Known values are "v1.2" and None. Default value is "v1.2".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str or ~azure.ai.vision.face.models.Versions
:keyword int polling_interval: Default waiting time between two polls for LRO operations if no
Retry-After header is present.
"""

def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
_endpoint = "{endpoint}/face/{apiVersion}"
self._config = FaceAdministrationClientConfiguration(endpoint=endpoint, credential=credential, **kwargs)
_policies = kwargs.pop("policies", None)
if _policies is None:
_policies = [
policies.RequestIdPolicy(**kwargs),
self._config.headers_policy,
self._config.user_agent_policy,
self._config.proxy_policy,
policies.ContentDecodePolicy(**kwargs),
self._config.redirect_policy,
self._config.retry_policy,
self._config.authentication_policy,
self._config.custom_hook_policy,
self._config.logging_policy,
policies.DistributedTracingPolicy(**kwargs),
policies.SensitiveHeaderCleanupPolicy(**kwargs) if self._config.redirect_policy else None,
self._config.http_logging_policy,
]
self._client: PipelineClient = PipelineClient(base_url=_endpoint, policies=_policies, **kwargs)

self._serialize = Serializer()
self._deserialize = Deserializer()
self._serialize.client_side_validation = False
self.large_face_list = LargeFaceListOperations(self._client, self._config, self._serialize, self._deserialize)
self.large_person_group = LargePersonGroupOperations(
self._client, self._config, self._serialize, self._deserialize
)

def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs: Any) -> HttpResponse:
"""Runs the network request through the client's chained policies.
>>> from azure.core.rest import HttpRequest
>>> request = HttpRequest("GET", "https://www.example.org/")
<HttpRequest [GET], url: 'https://www.example.org/'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>
For more information on this code flow, see https://aka.ms/azsdk/dpcodegen/python/send_request
:param request: The network request you want to make. Required.
:type request: ~azure.core.rest.HttpRequest
:keyword bool stream: Whether the response payload will be streamed. Defaults to False.
:return: The response of your network call. Does not do error handling on your response.
:rtype: ~azure.core.rest.HttpResponse
"""

request_copy = deepcopy(request)
path_format_arguments = {
"endpoint": self._serialize.url("self._config.endpoint", self._config.endpoint, "str", skip_quote=True),
"apiVersion": self._serialize.url("self._config.api_version", self._config.api_version, "str"),
}

request_copy.url = self._client.format_url(request_copy.url, **path_format_arguments)
return self._client.send_request(request_copy, stream=stream, **kwargs) # type: ignore

def close(self) -> None:
self._client.close()

def __enter__(self) -> Self:
self._client.__enter__()
return self

def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)


class FaceClient(FaceClientOperationsMixin):
"""FaceClient.
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
Expand All @@ -33,8 +131,8 @@ class FaceClient(FaceClientOperationsMixin): # pylint: disable=client-accepts-a
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: API Version. Default value is "v1.1-preview.1". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: API Version. Known values are "v1.2" and None. Default value is "v1.2".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str or ~azure.ai.vision.face.models.Versions
"""

Expand Down Expand Up @@ -94,15 +192,15 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
def close(self) -> None:
self._client.close()

def __enter__(self) -> "FaceClient":
def __enter__(self) -> Self:
self._client.__enter__()
return self

def __exit__(self, *exc_details: Any) -> None:
self._client.__exit__(*exc_details)


class FaceSessionClient(FaceSessionClientOperationsMixin): # pylint: disable=client-accepts-api-version-keyword
class FaceSessionClient(FaceSessionClientOperationsMixin):
"""FaceSessionClient.
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
Expand All @@ -112,8 +210,8 @@ class FaceSessionClient(FaceSessionClientOperationsMixin): # pylint: disable=cl
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: API Version. Default value is "v1.1-preview.1". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: API Version. Known values are "v1.2" and None. Default value is "v1.2".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str or ~azure.ai.vision.face.models.Versions
"""

Expand Down Expand Up @@ -173,7 +271,7 @@ def send_request(self, request: HttpRequest, *, stream: bool = False, **kwargs:
def close(self) -> None:
self._client.close()

def __enter__(self) -> "FaceSessionClient":
def __enter__(self) -> Self:
self._client.__enter__()
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,64 @@
from ._version import VERSION

if TYPE_CHECKING:
# pylint: disable=unused-import,ungrouped-imports
from azure.core.credentials import TokenCredential


class FaceAdministrationClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for FaceAdministrationClient.
Note that all parameters used to create this instance are saved as instance
attributes.
:param endpoint: Supported Cognitive Services endpoints (protocol and hostname, for example:
https://{resource-name}.cognitiveservices.azure.com). Required.
:type endpoint: str
:param credential: Credential used to authenticate requests to the service. Is either a
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: API Version. Known values are "v1.2" and None. Default value is "v1.2".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str or ~azure.ai.vision.face.models.Versions
"""

def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
api_version: str = kwargs.pop("api_version", "v1.2")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
if credential is None:
raise ValueError("Parameter 'credential' must not be None.")

self.endpoint = endpoint
self.credential = credential
self.api_version = api_version
self.credential_scopes = kwargs.pop("credential_scopes", ["https://cognitiveservices.azure.com/.default"])
kwargs.setdefault("sdk_moniker", "ai-vision-face/{}".format(VERSION))
self.polling_interval = kwargs.get("polling_interval", 30)
self._configure(**kwargs)

def _infer_policy(self, **kwargs):
if isinstance(self.credential, AzureKeyCredential):
return policies.AzureKeyCredentialPolicy(self.credential, "Ocp-Apim-Subscription-Key", **kwargs)
if hasattr(self.credential, "get_token"):
return policies.BearerTokenCredentialPolicy(self.credential, *self.credential_scopes, **kwargs)
raise TypeError(f"Unsupported credential: {self.credential}")

def _configure(self, **kwargs: Any) -> None:
self.user_agent_policy = kwargs.get("user_agent_policy") or policies.UserAgentPolicy(**kwargs)
self.headers_policy = kwargs.get("headers_policy") or policies.HeadersPolicy(**kwargs)
self.proxy_policy = kwargs.get("proxy_policy") or policies.ProxyPolicy(**kwargs)
self.logging_policy = kwargs.get("logging_policy") or policies.NetworkTraceLoggingPolicy(**kwargs)
self.http_logging_policy = kwargs.get("http_logging_policy") or policies.HttpLoggingPolicy(**kwargs)
self.custom_hook_policy = kwargs.get("custom_hook_policy") or policies.CustomHookPolicy(**kwargs)
self.redirect_policy = kwargs.get("redirect_policy") or policies.RedirectPolicy(**kwargs)
self.retry_policy = kwargs.get("retry_policy") or policies.RetryPolicy(**kwargs)
self.authentication_policy = kwargs.get("authentication_policy")
if self.credential and not self.authentication_policy:
self.authentication_policy = self._infer_policy(**kwargs)


class FaceClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for FaceClient.
Expand All @@ -31,13 +85,13 @@ class FaceClientConfiguration: # pylint: disable=too-many-instance-attributes
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: API Version. Default value is "v1.1-preview.1". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: API Version. Known values are "v1.2" and None. Default value is "v1.2".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str or ~azure.ai.vision.face.models.Versions
"""

def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
api_version: str = kwargs.pop("api_version", "v1.1-preview.1")
api_version: str = kwargs.pop("api_version", "v1.2")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand Down Expand Up @@ -73,7 +127,7 @@ def _configure(self, **kwargs: Any) -> None:
self.authentication_policy = self._infer_policy(**kwargs)


class FaceSessionClientConfiguration: # pylint: disable=too-many-instance-attributes,name-too-long
class FaceSessionClientConfiguration: # pylint: disable=too-many-instance-attributes
"""Configuration for FaceSessionClient.
Note that all parameters used to create this instance are saved as instance
Expand All @@ -86,13 +140,13 @@ class FaceSessionClientConfiguration: # pylint: disable=too-many-instance-attri
AzureKeyCredential type or a TokenCredential type. Required.
:type credential: ~azure.core.credentials.AzureKeyCredential or
~azure.core.credentials.TokenCredential
:keyword api_version: API Version. Default value is "v1.1-preview.1". Note that overriding this
default value may result in unsupported behavior.
:keyword api_version: API Version. Known values are "v1.2" and None. Default value is "v1.2".
Note that overriding this default value may result in unsupported behavior.
:paramtype api_version: str or ~azure.ai.vision.face.models.Versions
"""

def __init__(self, endpoint: str, credential: Union[AzureKeyCredential, "TokenCredential"], **kwargs: Any) -> None:
api_version: str = kwargs.pop("api_version", "v1.1-preview.1")
api_version: str = kwargs.pop("api_version", "v1.2")

if endpoint is None:
raise ValueError("Parameter 'endpoint' must not be None.")
Expand Down
Loading

0 comments on commit 32d60b4

Please sign in to comment.