forked from Azure/azure-sdk-for-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from beltr0n/bertong-extract-identity
Bertong extract identity
- Loading branch information
Showing
28 changed files
with
1,899 additions
and
2 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
sdk/communication/azure-communication-identity/azure/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__path__ = __import__('pkgutil').extend_path(__path__, __name__) |
1 change: 1 addition & 0 deletions
1
sdk/communication/azure-communication-identity/azure/communication/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__path__ = __import__('pkgutil').extend_path(__path__, __name__) |
20 changes: 20 additions & 0 deletions
20
sdk/communication/azure-communication-identity/azure/communication/identity/__init__ .py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# ------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for | ||
# license information. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._communication_identity_client import CommunicationIdentityClient | ||
|
||
from ._generated.models import ( | ||
CommunicationTokenRequest, | ||
CommunicationIdentityToken | ||
) | ||
|
||
__all__ = [ | ||
'CommunicationIdentityClient', | ||
|
||
# from _identity | ||
'CommunicationTokenRequest', | ||
'CommunicationIdentityToken', | ||
] |
153 changes: 153 additions & 0 deletions
153
...ure-communication-identity/azure/communication/identity/_communication_identity_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
# coding=utf-8 | ||
# ------------------------------------ | ||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT License. | ||
# ------------------------------------ | ||
|
||
from azure.core.tracing.decorator import distributed_trace | ||
|
||
from ._generated._communication_identity_client\ | ||
import CommunicationIdentityClient as CommunicationIdentityClientGen | ||
from ._generated.models import CommunicationIdentityToken | ||
from ._shared.utils import parse_connection_str, get_authentication_policy | ||
from ._shared.models import CommunicationUserIdentifier | ||
from ._version import SDK_MONIKER | ||
|
||
class CommunicationIdentityClient(object): | ||
"""Azure Communication Services Identity client. | ||
:param str endpoint: | ||
The endpoint url for Azure Communication Service resource. | ||
:param credential: | ||
The credentials with which to authenticate. The value is an account | ||
shared access key | ||
.. admonition:: Example: | ||
.. literalinclude:: ../samples/identity_samples.py | ||
:language: python | ||
:dedent: 8 | ||
""" | ||
def __init__( | ||
self, | ||
endpoint, # type: str | ||
credential, # type: str | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
try: | ||
if not endpoint.lower().startswith('http'): | ||
endpoint = "https://" + endpoint | ||
except AttributeError: | ||
raise ValueError("Account URL must be a string.") | ||
|
||
if not credential: | ||
raise ValueError( | ||
"You need to provide account shared key to authenticate.") | ||
|
||
self._endpoint = endpoint | ||
self._identity_service_client = CommunicationIdentityClientGen( | ||
self._endpoint, | ||
authentication_policy=get_authentication_policy(endpoint, credential), | ||
sdk_moniker=SDK_MONIKER, | ||
**kwargs) | ||
|
||
@classmethod | ||
def from_connection_string( | ||
cls, conn_str, # type: str | ||
**kwargs # type: Any | ||
): # type: (...) -> CommunicationIdentityClient | ||
"""Create CommunicationIdentityClient from a Connection String. | ||
:param str conn_str: | ||
A connection string to an Azure Communication Service resource. | ||
:returns: Instance of CommunicationIdentityClient. | ||
:rtype: ~azure.communication.CommunicationIdentityClient | ||
.. admonition:: Example: | ||
.. literalinclude:: ../samples/identity_samples.py | ||
:start-after: [START auth_from_connection_string] | ||
:end-before: [END auth_from_connection_string] | ||
:language: python | ||
:dedent: 8 | ||
:caption: Creating the CommunicationIdentityClient from a connection string. | ||
""" | ||
endpoint, access_key = parse_connection_str(conn_str) | ||
|
||
return cls(endpoint, access_key, **kwargs) | ||
|
||
@distributed_trace | ||
def create_user(self, **kwargs): | ||
# type: (...) -> CommunicationUserIdentifier | ||
"""create a single Communication user | ||
return: CommunicationUserIdentifier | ||
rtype: ~azure.communication.administration.CommunicationUserIdentifier | ||
""" | ||
return self._identity_service_client.communication_identity.create( | ||
cls=lambda pr, u, e: CommunicationUserIdentifier(u.id), | ||
**kwargs) | ||
|
||
@distributed_trace | ||
def delete_user( | ||
self, | ||
communication_user, # type: CommunicationUserIdentifier | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
"""Triggers revocation event for user and deletes all its data. | ||
:param communication_user: | ||
Azure Communication User to delete | ||
:type communication_user: ~azure.communication.administration.CommunicationUserIdentifier | ||
:return: None | ||
:rtype: None | ||
""" | ||
self._identity_service_client.communication_identity.delete( | ||
communication_user.identifier, **kwargs) | ||
|
||
@distributed_trace | ||
def issue_token( | ||
self, | ||
user, # type: CommunicationUserIdentifier | ||
scopes, # type: List[str] | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> CommunicationIdentityToken | ||
"""Generates a new token for an identity. | ||
:param user: Azure Communication User | ||
:type user: ~azure.communication.administration.CommunicationUserIdentifier | ||
:param scopes: | ||
List of scopes to be added to the token. | ||
:type scopes: list[str] | ||
:return: CommunicationIdentityToken | ||
:rtype: ~azure.communication.administration.CommunicationIdentityToken | ||
""" | ||
return self._identity_service_client.communication_identity.issue_token( | ||
user.identifier, | ||
scopes, | ||
**kwargs) | ||
|
||
@distributed_trace | ||
def revoke_tokens( | ||
self, | ||
user, # type: CommunicationUserIdentifier | ||
issued_before=None, # type: Optional[datetime.datetime] | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
"""Schedule revocation of all tokens of an identity. | ||
:param user: Azure Communication User. | ||
:type user: ~azure.communication.administration.CommunicationUserIdentifier. | ||
:param issued_before: All tokens that are issued prior to this time should get revoked. | ||
:type issued_before: ~datetime.datetime. | ||
:return: None | ||
:rtype: None | ||
""" | ||
return self._identity_service_client.communication_identity.update( | ||
user.identifier if user else None, | ||
tokens_valid_from=issued_before, | ||
**kwargs) |
16 changes: 16 additions & 0 deletions
16
...nication/azure-communication-identity/azure/communication/identity/_generated/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._communication_identity_client import CommunicationIdentityClient | ||
__all__ = ['CommunicationIdentityClient'] | ||
|
||
try: | ||
from ._patch import patch_sdk # type: ignore | ||
patch_sdk() | ||
except ImportError: | ||
pass |
60 changes: 60 additions & 0 deletions
60
...cation-identity/azure/communication/identity/_generated/_communication_identity_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from azure.core import PipelineClient | ||
from msrest import Deserializer, Serializer | ||
|
||
if TYPE_CHECKING: | ||
# pylint: disable=unused-import,ungrouped-imports | ||
from typing import Any | ||
|
||
from ._configuration import CommunicationIdentityClientConfiguration | ||
from .operations import CommunicationIdentityOperations | ||
from . import models | ||
|
||
|
||
class CommunicationIdentityClient(object): | ||
"""Azure Communication Identity Service. | ||
:ivar communication_identity: CommunicationIdentityOperations operations | ||
:vartype communication_identity: azure.communication.identity.operations.CommunicationIdentityOperations | ||
:param endpoint: Auth and Identity endpoint. | ||
:type endpoint: str | ||
""" | ||
|
||
def __init__( | ||
self, | ||
endpoint, # type: str | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
base_url = '{endpoint}' | ||
self._config = CommunicationIdentityClientConfiguration(endpoint, **kwargs) | ||
self._client = PipelineClient(base_url=base_url, config=self._config, **kwargs) | ||
|
||
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} | ||
self._serialize = Serializer(client_models) | ||
self._deserialize = Deserializer(client_models) | ||
|
||
self.communication_identity = CommunicationIdentityOperations( | ||
self._client, self._config, self._serialize, self._deserialize) | ||
|
||
def close(self): | ||
# type: () -> None | ||
self._client.close() | ||
|
||
def __enter__(self): | ||
# type: () -> CommunicationIdentityClient | ||
self._client.__enter__() | ||
return self | ||
|
||
def __exit__(self, *exc_details): | ||
# type: (Any) -> None | ||
self._client.__exit__(*exc_details) |
58 changes: 58 additions & 0 deletions
58
...on/azure-communication-identity/azure/communication/identity/_generated/_configuration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from azure.core.configuration import Configuration | ||
from azure.core.pipeline import policies | ||
|
||
if TYPE_CHECKING: | ||
# pylint: disable=unused-import,ungrouped-imports | ||
from typing import Any | ||
|
||
VERSION = "unknown" | ||
|
||
class CommunicationIdentityClientConfiguration(Configuration): | ||
"""Configuration for CommunicationIdentityClient. | ||
Note that all parameters used to create this instance are saved as instance | ||
attributes. | ||
:param endpoint: Auth and Identity endpoint. | ||
:type endpoint: str | ||
""" | ||
|
||
def __init__( | ||
self, | ||
endpoint, # type: str | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> None | ||
if endpoint is None: | ||
raise ValueError("Parameter 'endpoint' must not be None.") | ||
super(CommunicationIdentityClientConfiguration, self).__init__(**kwargs) | ||
|
||
self.endpoint = endpoint | ||
self.api_version = "2020-07-20-preview2" | ||
kwargs.setdefault('sdk_moniker', 'communicationidentityclient/{}'.format(VERSION)) | ||
self._configure(**kwargs) | ||
|
||
def _configure( | ||
self, | ||
**kwargs # type: Any | ||
): | ||
# type: (...) -> 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.retry_policy = kwargs.get('retry_policy') or policies.RetryPolicy(**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.authentication_policy = kwargs.get('authentication_policy') |
10 changes: 10 additions & 0 deletions
10
...tion/azure-communication-identity/azure/communication/identity/_generated/aio/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from ._communication_identity_client import CommunicationIdentityClient | ||
__all__ = ['CommunicationIdentityClient'] |
52 changes: 52 additions & 0 deletions
52
...on-identity/azure/communication/identity/_generated/aio/_communication_identity_client.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# coding=utf-8 | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# Code generated by Microsoft (R) AutoRest Code Generator. | ||
# Changes may cause incorrect behavior and will be lost if the code is regenerated. | ||
# -------------------------------------------------------------------------- | ||
|
||
from typing import Any | ||
|
||
from azure.core import AsyncPipelineClient | ||
from msrest import Deserializer, Serializer | ||
|
||
from ._configuration import CommunicationIdentityClientConfiguration | ||
from .operations import CommunicationIdentityOperations | ||
from .. import models | ||
|
||
|
||
class CommunicationIdentityClient(object): | ||
"""Azure Communication Identity Service. | ||
:ivar communication_identity: CommunicationIdentityOperations operations | ||
:vartype communication_identity: azure.communication.identity.aio.operations.CommunicationIdentityOperations | ||
:param endpoint: Auth and Identity endpoint. | ||
:type endpoint: str | ||
""" | ||
|
||
def __init__( | ||
self, | ||
endpoint: str, | ||
**kwargs: Any | ||
) -> None: | ||
base_url = '{endpoint}' | ||
self._config = CommunicationIdentityClientConfiguration(endpoint, **kwargs) | ||
self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs) | ||
|
||
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)} | ||
self._serialize = Serializer(client_models) | ||
self._deserialize = Deserializer(client_models) | ||
|
||
self.communication_identity = CommunicationIdentityOperations( | ||
self._client, self._config, self._serialize, self._deserialize) | ||
|
||
async def close(self) -> None: | ||
await self._client.close() | ||
|
||
async def __aenter__(self) -> "CommunicationIdentityClient": | ||
await self._client.__aenter__() | ||
return self | ||
|
||
async def __aexit__(self, *exc_details) -> None: | ||
await self._client.__aexit__(*exc_details) |
Oops, something went wrong.