diff --git a/sdk/communication/azure-communication-administration/CHANGELOG.md b/sdk/communication/azure-communication-administration/CHANGELOG.md index 5ea9e283325d..3f3f0f55287a 100644 --- a/sdk/communication/azure-communication-administration/CHANGELOG.md +++ b/sdk/communication/azure-communication-administration/CHANGELOG.md @@ -3,6 +3,7 @@ ## 1.0.0b4 (Unreleased) ### Breaking Changes +- CommunicationIdentityClient is moved to a new package: "azure.communication.identity" ##### `PhoneNumberAdministrationClient` - `begin_reserve_phone_numbers` now takes `display_name`, `description`, `phone_plan_ids`, diff --git a/sdk/communication/azure-communication-administration/README.md b/sdk/communication/azure-communication-administration/README.md index 9e926e7c2382..4e22a0500161 100644 --- a/sdk/communication/azure-communication-administration/README.md +++ b/sdk/communication/azure-communication-administration/README.md @@ -2,7 +2,7 @@ # Azure Communication Administration Package client library for Python -Azure Communication Administration client package is intended to be used to setup the basics for opening a way to use Azure Communication Service offerings. This package helps to create identities user tokens to be used by other client packages such as chat, calling, sms. +Azure Communication Administration client package is used to administer Phone Numbers. # Getting started ### Prerequisites @@ -17,31 +17,6 @@ pip install azure-communication-administration ``` # Key concepts -## CommunicationIdentityClient -`CommunicationIdentityClient` provides operations for: - -- Create/delete identities to be used in Azure Communication Services. Those identities can be used to make use of Azure Communication offerings and can be scoped to have limited abilities through token scopes. - -- Create/revoke scoped user access tokens to access services such as chat, calling, sms. Tokens are issued for a valid Azure Communication identity and can be revoked at any time. - -### Initializing Identity Client -```python -# You can find your endpoint and access token from your resource in the Azure Portal -import os -from azure.communication.administration import CommunicationIdentityClient -from azure.identity import DefaultAzureCredential - -connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') -endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT') - -# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have -# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables. -identity_client_managed_identity = CommunicationIdentityClient.(endpoint, DefaultAzureCredential()) - -#You can also authenticate using your connection string -identity_client = CommunicationIdentityClient.from_connection_string(connection_str) - -``` ## CommunicationPhoneNumberClient ### Initializing Phone Number Client @@ -70,10 +45,6 @@ Phone numbers can be assigned to a callback URL via the configure number API. As # Examples The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including: -[Create/delete Azure Communication Service identities][identitysamples] - -[Create/revoke scoped user access tokens][identitysamples] - ## Communication Phone number ### Get Countries @@ -179,12 +150,12 @@ poller = phone_number_administration_client.begin_purchase_reservation( ``` # Troubleshooting -The Azure Communication Service Identity client will raise exceptions defined in [Azure Core][azure_core]. +The Phone Number Administration client will raise exceptions defined in [Azure Core][azure_core]. # Next steps ## More sample code -Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/communication/azure-communication-administration/samples) directory for detailed examples of how to use this library to manage identities and tokens. +Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/communication/azure-communication-administration/samples) directory for detailed examples of how to use this library. ## Provide Feedback @@ -201,5 +172,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. -[identitysamples]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/communication/azure-communication-administration/samples/identity_samples.py [azure_core]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/__init__.py b/sdk/communication/azure-communication-administration/azure/communication/administration/__init__.py index 2ed40e51d71c..e10059fad1cc 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/__init__.py +++ b/sdk/communication/azure-communication-administration/azure/communication/administration/__init__.py @@ -4,15 +4,9 @@ # license information. # -------------------------------------------------------------------------- -from ._communication_identity_client import CommunicationIdentityClient from ._phone_number_administration_client import PhoneNumberAdministrationClient from ._polling import ReservePhoneNumberPolling, PurchaseReservationPolling, ReleasePhoneNumberPolling -from ._identity._generated.models import ( - CommunicationTokenRequest, - CommunicationIdentityToken -) - from ._phonenumber._generated.models import ( AcquiredPhoneNumber, AcquiredPhoneNumbers, @@ -42,16 +36,11 @@ ) __all__ = [ - 'CommunicationIdentityClient', 'PhoneNumberAdministrationClient', 'ReservePhoneNumberPolling', 'PurchaseReservationPolling', 'ReleasePhoneNumberPolling', - # from _identity - 'CommunicationTokenRequest', - 'CommunicationIdentityToken', - # from _phonenumber 'AcquiredPhoneNumber', 'AcquiredPhoneNumbers', diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/__init__.py b/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/__init__.py deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/__init__.py b/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/__init__.py deleted file mode 100644 index 05dd3d4b6aab..000000000000 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -# 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. -# -------------------------------------------------------------------------- - -try: - from ._models_py3 import CommunicationIdentity - from ._models_py3 import CommunicationIdentityToken - from ._models_py3 import CommunicationIdentityUpdateRequest - from ._models_py3 import CommunicationTokenRequest -except (SyntaxError, ImportError): - from ._models import CommunicationIdentity # type: ignore - from ._models import CommunicationIdentityToken # type: ignore - from ._models import CommunicationIdentityUpdateRequest # type: ignore - from ._models import CommunicationTokenRequest # type: ignore - -__all__ = [ - 'CommunicationIdentity', - 'CommunicationIdentityToken', - 'CommunicationIdentityUpdateRequest', - 'CommunicationTokenRequest', -] diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/_models.py b/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/_models.py deleted file mode 100644 index ce2106c91807..000000000000 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/_models.py +++ /dev/null @@ -1,113 +0,0 @@ -# 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. -# -------------------------------------------------------------------------- - -import msrest.serialization - - -class CommunicationIdentity(msrest.serialization.Model): - """A communication identity. - - All required parameters must be populated in order to send to Azure. - - :param id: Required. Identifier of the identity. - :type id: str - """ - - _validation = { - 'id': {'required': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - } - - def __init__( - self, - **kwargs - ): - super(CommunicationIdentity, self).__init__(**kwargs) - self.id = kwargs['id'] - - -class CommunicationIdentityToken(msrest.serialization.Model): - """CommunicationIdentityToken. - - All required parameters must be populated in order to send to Azure. - - :param id: Required. Identifier of the identity owning the token. - :type id: str - :param token: Required. The token issued for the identity. - :type token: str - :param expires_on: Required. The expiry time of the token. - :type expires_on: ~datetime.datetime - """ - - _validation = { - 'id': {'required': True}, - 'token': {'required': True}, - 'expires_on': {'required': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'token': {'key': 'token', 'type': 'str'}, - 'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'}, - } - - def __init__( - self, - **kwargs - ): - super(CommunicationIdentityToken, self).__init__(**kwargs) - self.id = kwargs['id'] - self.token = kwargs['token'] - self.expires_on = kwargs['expires_on'] - - -class CommunicationIdentityUpdateRequest(msrest.serialization.Model): - """CommunicationIdentityUpdateRequest. - - :param tokens_valid_from: All tokens that are issued prior to this time will be revoked. - :type tokens_valid_from: ~datetime.datetime - """ - - _attribute_map = { - 'tokens_valid_from': {'key': 'tokensValidFrom', 'type': 'iso-8601'}, - } - - def __init__( - self, - **kwargs - ): - super(CommunicationIdentityUpdateRequest, self).__init__(**kwargs) - self.tokens_valid_from = kwargs.get('tokens_valid_from', None) - - -class CommunicationTokenRequest(msrest.serialization.Model): - """CommunicationTokenRequest. - - All required parameters must be populated in order to send to Azure. - - :param scopes: Required. List of scopes attached to the token. - :type scopes: list[str] - """ - - _validation = { - 'scopes': {'required': True}, - } - - _attribute_map = { - 'scopes': {'key': 'scopes', 'type': '[str]'}, - } - - def __init__( - self, - **kwargs - ): - super(CommunicationTokenRequest, self).__init__(**kwargs) - self.scopes = kwargs['scopes'] diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/_models_py3.py b/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/_models_py3.py deleted file mode 100644 index ba3988b1589a..000000000000 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/models/_models_py3.py +++ /dev/null @@ -1,126 +0,0 @@ -# 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. -# -------------------------------------------------------------------------- - -import datetime -from typing import List, Optional - -import msrest.serialization - - -class CommunicationIdentity(msrest.serialization.Model): - """A communication identity. - - All required parameters must be populated in order to send to Azure. - - :param id: Required. Identifier of the identity. - :type id: str - """ - - _validation = { - 'id': {'required': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - } - - def __init__( - self, - *, - id: str, - **kwargs - ): - super(CommunicationIdentity, self).__init__(**kwargs) - self.id = id - - -class CommunicationIdentityToken(msrest.serialization.Model): - """CommunicationIdentityToken. - - All required parameters must be populated in order to send to Azure. - - :param id: Required. Identifier of the identity owning the token. - :type id: str - :param token: Required. The token issued for the identity. - :type token: str - :param expires_on: Required. The expiry time of the token. - :type expires_on: ~datetime.datetime - """ - - _validation = { - 'id': {'required': True}, - 'token': {'required': True}, - 'expires_on': {'required': True}, - } - - _attribute_map = { - 'id': {'key': 'id', 'type': 'str'}, - 'token': {'key': 'token', 'type': 'str'}, - 'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'}, - } - - def __init__( - self, - *, - id: str, - token: str, - expires_on: datetime.datetime, - **kwargs - ): - super(CommunicationIdentityToken, self).__init__(**kwargs) - self.id = id - self.token = token - self.expires_on = expires_on - - -class CommunicationIdentityUpdateRequest(msrest.serialization.Model): - """CommunicationIdentityUpdateRequest. - - :param tokens_valid_from: All tokens that are issued prior to this time will be revoked. - :type tokens_valid_from: ~datetime.datetime - """ - - _attribute_map = { - 'tokens_valid_from': {'key': 'tokensValidFrom', 'type': 'iso-8601'}, - } - - def __init__( - self, - *, - tokens_valid_from: Optional[datetime.datetime] = None, - **kwargs - ): - super(CommunicationIdentityUpdateRequest, self).__init__(**kwargs) - self.tokens_valid_from = tokens_valid_from - - -class CommunicationTokenRequest(msrest.serialization.Model): - """CommunicationTokenRequest. - - All required parameters must be populated in order to send to Azure. - - :param scopes: Required. List of scopes attached to the token. - :type scopes: list[str] - """ - - _validation = { - 'scopes': {'required': True}, - } - - _attribute_map = { - 'scopes': {'key': 'scopes', 'type': '[str]'}, - } - - def __init__( - self, - *, - scopes: List[str], - **kwargs - ): - super(CommunicationTokenRequest, self).__init__(**kwargs) - self.scopes = scopes diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/aio/__init__.py b/sdk/communication/azure-communication-administration/azure/communication/administration/aio/__init__.py index ffe7feed48fa..a35d7f5eba44 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/aio/__init__.py +++ b/sdk/communication/azure-communication-administration/azure/communication/administration/aio/__init__.py @@ -1,11 +1,9 @@ -from ._communication_identity_client_async import CommunicationIdentityClient from ._phone_number_administration_client_async import PhoneNumberAdministrationClient from ._polling_async import ReservePhoneNumberPollingAsync, \ PurchaseReservationPollingAsync, \ ReleasePhoneNumberPollingAsync __all__ = [ - 'CommunicationIdentityClient', 'PhoneNumberAdministrationClient', 'ReservePhoneNumberPollingAsync', 'PurchaseReservationPollingAsync', diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/aio/_phone_number_administration_client_async.py b/sdk/communication/azure-communication-administration/azure/communication/administration/aio/_phone_number_administration_client_async.py index 28428b4f8e1c..dd18ec52f302 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/aio/_phone_number_administration_client_async.py +++ b/sdk/communication/azure-communication-administration/azure/communication/administration/aio/_phone_number_administration_client_async.py @@ -4,7 +4,7 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. # ------------------------------------ -from typing import Dict, List +from typing import Dict from azure.communication.administration._phonenumber._generated.models import ReleaseStatus, CreateSearchOptions from azure.core.async_paging import AsyncItemPaged diff --git a/sdk/communication/azure-communication-administration/swagger/COMMUNICATION_IDENTITY.md b/sdk/communication/azure-communication-administration/swagger/COMMUNICATION_IDENTITY.md deleted file mode 100644 index 0a5477c97638..000000000000 --- a/sdk/communication/azure-communication-administration/swagger/COMMUNICATION_IDENTITY.md +++ /dev/null @@ -1,27 +0,0 @@ -# Azure Communication Administration for Python - -> see https://aka.ms/autorest - -### Setup -```ps -npm install -g autorest -``` - -### Generation -```ps -cd -autorest ./COMMUNICATION_IDENTITY.md -``` - -### Settings -``` yaml -input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/8818a603b78a1355ba1647ab9cd4e3354cdc4b69/specification/communication/data-plane/Microsoft.CommunicationServicesIdentity/preview/2020-07-20-preview2/CommunicationIdentity.json -output-folder: ../azure/communication/administration/_identity/_generated/ -namespace: azure.communication.administration -license-header: MICROSOFT_MIT_NO_VERSION -payload-flattening-threshold: 3 -no-namespace-folders: true -clear-output-folder: true -v3: true -python: true -``` \ No newline at end of file diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_create_user.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_create_user.yaml deleted file mode 100644 index 744fbd017292..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_create_user.yaml +++ /dev/null @@ -1,30 +0,0 @@ -interactions: -- request: - body: '' - headers: - Accept: - - application/json - Date: - - Tue, 22 Dec 2020 18:48:56 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:48:54 GMT - ms-cv: vfIkgQk+J0OWSV4P3J1i0w.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 22ms - status: - code: 200 - message: OK - url: https://communicationtrnhzmurqrr.communication.azure.com/identities?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_create_user_from_managed_identity.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_create_user_from_managed_identity.yaml deleted file mode 100644 index 883eb09da417..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_create_user_from_managed_identity.yaml +++ /dev/null @@ -1,26 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/json - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:50:04 GMT - ms-cv: fj3guox5CUSvTCDG5gI0YA.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 534ms - status: - code: 200 - message: OK - url: https://communicationr7rdwwqs74n.communication.azure.com/identities?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_delete_user.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_delete_user.yaml deleted file mode 100644 index 46f6bc7da32e..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_delete_user.yaml +++ /dev/null @@ -1,54 +0,0 @@ -interactions: -- request: - body: '' - headers: - Accept: - - application/json - Date: - - Tue, 22 Dec 2020 18:51:13 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:51:12 GMT - ms-cv: dHk7/E5BhUSf+g3Bkg94YQ.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 22ms - status: - code: 200 - message: OK - url: https://communication42hz4pfbosr.communication.azure.com/identities?api-version=2020-07-20-preview2 -- request: - body: '' - headers: - Date: - - Tue, 22 Dec 2020 18:51:14 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: DELETE - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 - response: - body: - string: '' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - date: Tue, 22 Dec 2020 18:51:12 GMT - ms-cv: 3DnY9x3jNUGrGnsi3LP0SA.0 - strict-transport-security: max-age=2592000 - x-processing-time: 440ms - status: - code: 204 - message: No Content - url: https://communication42hz4pfbosr.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_delete_user_from_managed_identity.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_delete_user_from_managed_identity.yaml deleted file mode 100644 index 3d5253742e18..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_delete_user_from_managed_identity.yaml +++ /dev/null @@ -1,46 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/json - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:52:27 GMT - ms-cv: ww9tz7CpG0SXqqYPyV70Cw.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 192ms - status: - code: 200 - message: OK - url: https://communicationrscjfarclwr.communication.azure.com/identities?api-version=2020-07-20-preview2 -- request: - body: null - headers: - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: DELETE - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 - response: - body: - string: '' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - date: Tue, 22 Dec 2020 18:52:28 GMT - ms-cv: baDrTbu3H0qpWj2TJSno0A.0 - strict-transport-security: max-age=2592000 - x-processing-time: 864ms - status: - code: 204 - message: No Content - url: https://communicationrscjfarclwr.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_issue_token.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_issue_token.yaml deleted file mode 100644 index fce3ec17e7e1..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_issue_token.yaml +++ /dev/null @@ -1,62 +0,0 @@ -interactions: -- request: - body: '' - headers: - Accept: - - application/json - Date: - - Tue, 22 Dec 2020 18:53:37 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:53:36 GMT - ms-cv: Agl32miSq0CTEladXG7lbw.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 20ms - status: - code: 200 - message: OK - url: https://communicatione77tfh7y2ht.communication.azure.com/identities?api-version=2020-07-20-preview2 -- request: - body: '{"scopes": ["chat"]}' - headers: - Accept: - - application/json - Content-Length: - - '20' - Content-Type: - - application/json - Date: - - Tue, 22 Dec 2020 18:53:38 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:53:35.7585148+00:00"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:53:36 GMT - ms-cv: P3rSrWhwykmJcOW+Yb8Q2w.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 26ms - status: - code: 200 - message: OK - url: https://communicatione77tfh7y2ht.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_issue_token_from_managed_identity.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_issue_token_from_managed_identity.yaml deleted file mode 100644 index 44a889e13df3..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_issue_token_from_managed_identity.yaml +++ /dev/null @@ -1,54 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/json - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:54:45 GMT - ms-cv: UywF8dbxrkyYXGTozRnuIw.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 773ms - status: - code: 200 - message: OK - url: https://communicationztg2acjbipc.communication.azure.com/identities?api-version=2020-07-20-preview2 -- request: - body: '{"scopes": ["chat"]}' - headers: - Accept: - - application/json - Content-Length: - - '20' - Content-Type: - - application/json - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:54:45.1115885+00:00"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:54:45 GMT - ms-cv: ywaIOOtf9EiQs6pibQmCwg.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 25ms - status: - code: 200 - message: OK - url: https://communicationztg2acjbipc.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_revoke_tokens.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_revoke_tokens.yaml deleted file mode 100644 index cefb985a000f..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_revoke_tokens.yaml +++ /dev/null @@ -1,90 +0,0 @@ -interactions: -- request: - body: '' - headers: - Accept: - - application/json - Date: - - Tue, 22 Dec 2020 18:55:56 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:55:55 GMT - ms-cv: M9b8kGAz8UGwsoZe2mFLCA.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 29ms - status: - code: 200 - message: OK - url: https://communicationngn6p2kywhg.communication.azure.com/identities?api-version=2020-07-20-preview2 -- request: - body: '{"scopes": ["chat"]}' - headers: - Accept: - - application/json - Content-Length: - - '20' - Content-Type: - - application/json - Date: - - Tue, 22 Dec 2020 18:55:57 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:55:54.788117+00:00"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:55:55 GMT - ms-cv: MBCUlMoRBECvCLmV00eWXw.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 27ms - status: - code: 200 - message: OK - url: https://communicationngn6p2kywhg.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 -- request: - body: '{}' - headers: - Content-Length: - - '2' - Content-Type: - - application/merge-patch+json - Date: - - Tue, 22 Dec 2020 18:55:57 GMT - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - x-ms-return-client-request-id: - - 'true' - method: PATCH - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 - response: - body: - string: '' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - date: Tue, 22 Dec 2020 18:55:55 GMT - ms-cv: MVgoSrOVSkiU0c+teqMDZQ.0 - strict-transport-security: max-age=2592000 - x-processing-time: 10ms - status: - code: 204 - message: No Content - url: https://communicationngn6p2kywhg.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_revoke_tokens_from_managed_identity.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_revoke_tokens_from_managed_identity.yaml deleted file mode 100644 index 23b4c57c9632..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client_async.test_revoke_tokens_from_managed_identity.yaml +++ /dev/null @@ -1,78 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/json - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:57:03 GMT - ms-cv: a9v8/cRgN0uyuQQUguwkGA.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 195ms - status: - code: 200 - message: OK - url: https://communicationxheui257vce.communication.azure.com/identities?api-version=2020-07-20-preview2 -- request: - body: '{"scopes": ["chat"]}' - headers: - Accept: - - application/json - Content-Length: - - '20' - Content-Type: - - application/json - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 - response: - body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:57:03.4428768+00:00"}' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - content-type: application/json; charset=utf-8 - date: Tue, 22 Dec 2020 18:57:03 GMT - ms-cv: Oc9n/N0oA0mLVBlk8UaTpw.0 - strict-transport-security: max-age=2592000 - transfer-encoding: chunked - x-processing-time: 24ms - status: - code: 200 - message: OK - url: https://communicationxheui257vce.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 -- request: - body: '{}' - headers: - Content-Length: - - '2' - Content-Type: - - application/merge-patch+json - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: PATCH - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 - response: - body: - string: '' - headers: - api-supported-versions: 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 - date: Tue, 22 Dec 2020 18:57:03 GMT - ms-cv: lBOoIDU5lUe2vbpjz5+Gkg.0 - strict-transport-security: max-age=2592000 - x-processing-time: 11ms - status: - code: 204 - message: No Content - url: https://communicationxheui257vce.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 -version: 1 diff --git a/sdk/communication/azure-communication-chat/README.md b/sdk/communication/azure-communication-chat/README.md index 9f825335ffaa..b178c8bd0e48 100644 --- a/sdk/communication/azure-communication-chat/README.md +++ b/sdk/communication/azure-communication-chat/README.md @@ -22,14 +22,14 @@ pip install --pre azure-communication-chat ## User Access Tokens -User access tokens enable you to build client applications that directly authenticate to Azure Communication Services. You can generate these tokens with azure.communication.administration module, and then use them to initialize the Communication Services SDKs. Example of using azure.communication.administration: +User access tokens enable you to build client applications that directly authenticate to Azure Communication Services. You can generate these tokens with azure.communication.identity module, and then use them to initialize the Communication Services SDKs. Example of using azure.communication.identity: ```bash -pip install --pre azure-communication-administration +pip install --pre azure-communication-identity ``` ```python -from azure.communication.administration import CommunicationIdentityClient +from azure.communication.identity import CommunicationIdentityClient identity_client = CommunicationIdentityClient.from_connection_string("") user = identity_client.create_user() tokenresponse = identity_client.issue_token(user, scopes=["chat"]) @@ -374,7 +374,7 @@ to create a resource, then set some Environment Variables set AZURE_COMMUNICATION_SERVICE_ENDPOINT="https://.communcationservices.azure.com" set AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING="" -pip install azure-communication-administration +pip install azure-communication-identity python samples\chat_client_sample.py python samples\chat_client_sample_async.py diff --git a/sdk/communication/azure-communication-chat/dev_requirements.txt b/sdk/communication/azure-communication-chat/dev_requirements.txt index 1281667d25f3..b88483d99721 100644 --- a/sdk/communication/azure-communication-chat/dev_requirements.txt +++ b/sdk/communication/azure-communication-chat/dev_requirements.txt @@ -1,5 +1,5 @@ -e ../../../tools/azure-devtools -e ../../../tools/azure-sdk-tools ../azure-communication-nspkg --e ../azure-communication-administration +-e ../azure-communication-identity aiohttp>=3.0; python_version >= '3.5' \ No newline at end of file diff --git a/sdk/communication/azure-communication-chat/samples/chat_client_sample.py b/sdk/communication/azure-communication-chat/samples/chat_client_sample.py index ec6746fb2120..25963095f8fd 100644 --- a/sdk/communication/azure-communication-chat/samples/chat_client_sample.py +++ b/sdk/communication/azure-communication-chat/samples/chat_client_sample.py @@ -27,7 +27,7 @@ class ChatClientSamples(object): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient connection_string = os.environ.get("AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING", None) if not connection_string: raise ValueError("Set AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING env before run this sample.") diff --git a/sdk/communication/azure-communication-chat/samples/chat_client_sample_async.py b/sdk/communication/azure-communication-chat/samples/chat_client_sample_async.py index 7c22b5d8acb2..fc8874226f8b 100644 --- a/sdk/communication/azure-communication-chat/samples/chat_client_sample_async.py +++ b/sdk/communication/azure-communication-chat/samples/chat_client_sample_async.py @@ -27,7 +27,7 @@ class ChatClientSamplesAsync(object): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient connection_string = os.environ.get("AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING", None) if not connection_string: raise ValueError("Set AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING env before run this sample.") diff --git a/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample.py b/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample.py index c20ba6be0977..8ba955777a08 100644 --- a/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample.py +++ b/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample.py @@ -27,7 +27,7 @@ class ChatThreadClientSamples(object): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient connection_string = os.environ.get("AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING", None) if not connection_string: raise ValueError("Set AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING env before run this sample.") diff --git a/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample_async.py b/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample_async.py index 129c2c057e44..135fd274970c 100644 --- a/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample_async.py +++ b/sdk/communication/azure-communication-chat/samples/chat_thread_client_sample_async.py @@ -28,7 +28,7 @@ class ChatThreadClientSamplesAsync(object): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient connection_string = os.environ.get("AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING", None) if not connection_string: raise ValueError("Set AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING env before run this sample.") diff --git a/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e.py b/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e.py index f0b4a5189d80..0036d0b263f4 100644 --- a/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e.py +++ b/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e.py @@ -10,7 +10,7 @@ from devtools_testutils import AzureTestCase from msrest.serialization import TZ_UTC -from azure.communication.administration import CommunicationIdentityClient +from azure.communication.identity import CommunicationIdentityClient from azure.communication.chat import ( ChatClient, CommunicationTokenCredential, diff --git a/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e_async.py b/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e_async.py index a3fe1a3750d4..72f727dcaeec 100644 --- a/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e_async.py +++ b/sdk/communication/azure-communication-chat/tests/test_chat_client_e2e_async.py @@ -9,7 +9,7 @@ from datetime import datetime from msrest.serialization import TZ_UTC -from azure.communication.administration import CommunicationIdentityClient +from azure.communication.identity import CommunicationIdentityClient from azure.communication.chat.aio import ( ChatClient, CommunicationTokenCredential, @@ -18,7 +18,7 @@ from azure.communication.chat import ( ChatThreadMember ) -from azure.communication.administration._shared.utils import parse_connection_str +from azure.communication.identity._shared.utils import parse_connection_str from azure_devtools.scenario_tests import RecordingProcessor from helper import URIIdentityReplacer from chat_e2e_helper import ChatURIReplacer diff --git a/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e.py b/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e.py index 9a90b1a79662..eadf9f8114ab 100644 --- a/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e.py +++ b/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e.py @@ -10,7 +10,7 @@ from devtools_testutils import AzureTestCase from msrest.serialization import TZ_UTC -from azure.communication.administration import CommunicationIdentityClient +from azure.communication.identity import CommunicationIdentityClient from azure.communication.chat import ( ChatClient, CommunicationTokenCredential, diff --git a/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e_async.py b/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e_async.py index 7c0c6c7b80cc..e3deffa02236 100644 --- a/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e_async.py +++ b/sdk/communication/azure-communication-chat/tests/test_chat_thread_client_e2e_async.py @@ -9,7 +9,7 @@ from datetime import datetime from msrest.serialization import TZ_UTC -from azure.communication.administration import CommunicationIdentityClient +from azure.communication.identity import CommunicationIdentityClient from azure.communication.chat.aio import ( ChatClient, CommunicationTokenCredential, @@ -19,7 +19,7 @@ ChatThreadMember, ChatMessagePriority ) -from azure.communication.administration._shared.utils import parse_connection_str +from azure.communication.identity._shared.utils import parse_connection_str from azure_devtools.scenario_tests import RecordingProcessor from helper import URIIdentityReplacer from chat_e2e_helper import ChatURIReplacer diff --git a/sdk/communication/azure-communication-identity/CHANGELOG.md b/sdk/communication/azure-communication-identity/CHANGELOG.md new file mode 100644 index 000000000000..cafa147a25ac --- /dev/null +++ b/sdk/communication/azure-communication-identity/CHANGELOG.md @@ -0,0 +1,10 @@ +# Release History + +## 1.0.0-beta.4 (Unreleased) + +### Added +- Added CommunicationIdentityClient (originally was part of the azure.communication.administration package). + + +[read_me]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/communication/azure-communication-identity/README.md +[documentation]: https://docs.microsoft.com/azure/communication-services/quickstarts/access-tokens?pivots=programming-language-python \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/LICENSE.txt b/sdk/communication/azure-communication-identity/LICENSE.txt new file mode 100644 index 000000000000..0313a903d76c --- /dev/null +++ b/sdk/communication/azure-communication-identity/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Microsoft + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/MANIFEST.in b/sdk/communication/azure-communication-identity/MANIFEST.in new file mode 100644 index 000000000000..a743efd0162b --- /dev/null +++ b/sdk/communication/azure-communication-identity/MANIFEST.in @@ -0,0 +1,6 @@ +include *.md +include azure/__init__.py +include azure/communication/__init__.py +include LICENSE.txt +recursive-include tests *.py +recursive-include samples *.py *.md \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/README.md b/sdk/communication/azure-communication-identity/README.md new file mode 100644 index 000000000000..bce44c94e482 --- /dev/null +++ b/sdk/communication/azure-communication-identity/README.md @@ -0,0 +1,77 @@ +[![Build Status](https://dev.azure.com/azure-sdk/public/_apis/build/status/azure-sdk-for-python.client?branchName=master)](https://dev.azure.com/azure-sdk/public/_build/latest?definitionId=46?branchName=master) + +# Azure Communication Identity Package client library for Python + +Azure Communication Identity client package is intended to be used to setup the basics for opening a way to use Azure Communication Service offerings. This package helps to create identities user tokens to be used by other client packages such as chat, calling, sms. + +# Getting started +### Prerequisites +- Python 2.7, or 3.5 or later is required to use this package. +- You must have an [Azure subscription](https://azure.microsoft.com/free/) +- A deployed Communication Services resource. You can use the [Azure Portal](https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource?tabs=windows&pivots=platform-azp) or the [Azure PowerShell](https://docs.microsoft.com/powershell/module/az.communication/new-azcommunicationservice) to set it up. +### Install the package +Install the Azure Communication Identity client library for Python with [pip](https://pypi.org/project/pip/): + +```bash +pip install azure-communication-identity +``` + +# Key concepts +## CommunicationIdentityClient +`CommunicationIdentityClient` provides operations for: + +- Create/delete identities to be used in Azure Communication Services. Those identities can be used to make use of Azure Communication offerings and can be scoped to have limited abilities through token scopes. + +- Create/revoke scoped user access tokens to access services such as chat, calling, sms. Tokens are issued for a valid Azure Communication identity and can be revoked at any time. + +### Initializing Identity Client +```python +# You can find your endpoint and access token from your resource in the Azure Portal +import os +from azure.communication.identity import CommunicationIdentityClient +from azure.identity import DefaultAzureCredential + +connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') +endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT') + +# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have +# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables. +identity_client_managed_identity = CommunicationIdentityClient.(endpoint, DefaultAzureCredential()) + +#You can also authenticate using your connection string +identity_client = CommunicationIdentityClient.from_connection_string(connection_str) + +``` + +# Examples +The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including: + +[Create/delete Azure Communication Service identities][identitysamples] + +[Create/revoke scoped user access tokens][identitysamples] + +# Troubleshooting +The Azure Communication Service Identity client will raise exceptions defined in [Azure Core][azure_core]. + +# Next steps +## More sample code + +Please take a look at the [samples](https://github.com/Azure/azure-sdk-for-python/tree/master/sdk/communication/azure-communication-identity/samples) directory for detailed examples of how to use this library to manage identities and tokens. + +## Provide Feedback + +If you encounter any bugs or have suggestions, please file an issue in the [Issues](https://github.com/Azure/azure-sdk-for-python/issues) section of the project + +# Contributing +This project welcomes contributions and suggestions. Most contributions require you to agree to a +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the +PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + + +[identitysamples]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/communication/azure-communication-identity/samples/identity_samples.py +[azure_core]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/core/azure-core/README.md diff --git a/sdk/communication/azure-communication-identity/azure/__init__.py b/sdk/communication/azure-communication-identity/azure/__init__.py new file mode 100644 index 000000000000..69e3be50dac4 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/__init__.py @@ -0,0 +1 @@ +__path__ = __import__('pkgutil').extend_path(__path__, __name__) diff --git a/sdk/communication/azure-communication-identity/azure/communication/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/__init__.py new file mode 100644 index 000000000000..69e3be50dac4 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/__init__.py @@ -0,0 +1 @@ +__path__ = __import__('pkgutil').extend_path(__path__, __name__) diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/__init__.py new file mode 100644 index 000000000000..8cf68fa76838 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/__init__.py @@ -0,0 +1,26 @@ +# ------------------------------------------------------------------------- +# 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 ( + CommunicationIdentityAccessTokenRequest, + CommunicationUserToken +) + +from ._shared.models import CommunicationUserIdentifier + + +__all__ = [ + 'CommunicationIdentityClient', + + # from _identity + 'CommunicationIdentityAccessTokenRequest', + 'CommunicationUserToken', + + # from _shared + 'CommunicationUserIdentifier' +] diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_communication_identity_client.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_communication_identity_client.py similarity index 70% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_communication_identity_client.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_communication_identity_client.py index a97fd4407779..43444467aa2c 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_communication_identity_client.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_communication_identity_client.py @@ -6,9 +6,9 @@ from azure.core.tracing.decorator import distributed_trace -from ._identity._generated._communication_identity_client\ +from ._generated._communication_identity_client\ import CommunicationIdentityClient as CommunicationIdentityClientGen -from ._identity._generated.models import CommunicationIdentityToken +from ._generated.models import CommunicationUserToken from ._shared.utils import parse_connection_str, get_authentication_policy from ._shared.models import CommunicationUserIdentifier from ._version import SDK_MONIKER @@ -62,7 +62,7 @@ def from_connection_string( :param str conn_str: A connection string to an Azure Communication Service resource. :returns: Instance of CommunicationIdentityClient. - :rtype: ~azure.communication.CommunicationIdentityClient + :rtype: ~azure.communication.identity.CommunicationIdentityClient .. admonition:: Example: @@ -82,11 +82,31 @@ def create_user(self, **kwargs): # type: (...) -> CommunicationUserIdentifier """create a single Communication user - return: CommunicationUserIdentifier - rtype: ~azure.communication.administration.CommunicationUserIdentifier + :return: CommunicationUserIdentifier + :rtype: ~azure.communication.identity.CommunicationUserIdentifier """ return self._identity_service_client.communication_identity.create( - cls=lambda pr, u, e: CommunicationUserIdentifier(u.id), + cls=lambda pr, u, e: CommunicationUserIdentifier(u.identity.id), + **kwargs) + + @distributed_trace + def create_user_with_token( + self, + scopes, # type: List[Union[str, "_model.CommunicationTokenScope"]] + **kwargs # type: Any + ): + # type: (...) -> Tuple[CommunicationUserIdentifier, CommunicationUserToken] + """create a single Communication user with an identity token. + :param scopes: + List of scopes to be added to the token. + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] + :return: A CommunicationUser and a CommunicationIdentityToken tuple. + :rtype: tuple of (~azure.communication.identity.CommunicationUserIdentifier, \ +~azure.communication.identity.CommunicationUserToken) + """ + return self._identity_service_client.communication_identity.create( + cls=lambda pr, u, e: CommunicationUserIdentifier(u.identity.id), + create_token_with_scopes=scopes, **kwargs) @distributed_trace @@ -100,7 +120,7 @@ def delete_user( :param communication_user: Azure Communication User to delete - :type communication_user: ~azure.communication.administration.CommunicationUserIdentifier + :type communication_user: ~azure.communication.identity.CommunicationUserIdentifier :return: None :rtype: None """ @@ -111,21 +131,21 @@ def delete_user( def issue_token( self, user, # type: CommunicationUserIdentifier - scopes, # type: List[str] + scopes, # List[Union[str, "_model.CommunicationTokenScope"]] **kwargs # type: Any ): - # type: (...) -> CommunicationIdentityToken + # type: (...) -> CommunicationUserToken """Generates a new token for an identity. :param user: Azure Communication User - :type user: ~azure.communication.administration.CommunicationUserIdentifier + :type user: ~azure.communication.identity.CommunicationUserIdentifier :param scopes: List of scopes to be added to the token. - :type scopes: list[str] - :return: CommunicationIdentityToken - :rtype: ~azure.communication.administration.CommunicationIdentityToken + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] + :return: CommunicationUserToken + :rtype: ~azure.communication.identity.CommunicationUserToken """ - return self._identity_service_client.communication_identity.issue_token( + return self._identity_service_client.communication_identity.issue_access_token( user.identifier, scopes, **kwargs) @@ -134,20 +154,16 @@ def issue_token( 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. + :type user: ~azure.communication.identity.CommunicationUserIdentifier. :return: None :rtype: None """ - return self._identity_service_client.communication_identity.update( + return self._identity_service_client.communication_identity.revoke_access_tokens( user.identifier if user else None, - tokens_valid_from=issued_before, **kwargs) diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/__init__.py similarity index 100% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/__init__.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/__init__.py diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/_communication_identity_client.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/_communication_identity_client.py similarity index 90% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/_communication_identity_client.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/_communication_identity_client.py index c7a76a0d444d..c8e80845ea47 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/_communication_identity_client.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/_communication_identity_client.py @@ -24,8 +24,8 @@ class CommunicationIdentityClient(object): """Azure Communication Identity Service. :ivar communication_identity: CommunicationIdentityOperations operations - :vartype communication_identity: azure.communication.administration.operations.CommunicationIdentityOperations - :param endpoint: Auth and Identity endpoint. + :vartype communication_identity: azure.communication.identity.operations.CommunicationIdentityOperations + :param endpoint: The communication resource, for example https://my-resource.communication.azure.com. :type endpoint: str """ diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/_configuration.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/_configuration.py similarity index 94% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/_configuration.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/_configuration.py index 079f98f2ffd0..68363ff6515f 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/_configuration.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/_configuration.py @@ -23,7 +23,7 @@ class CommunicationIdentityClientConfiguration(Configuration): Note that all parameters used to create this instance are saved as instance attributes. - :param endpoint: Auth and Identity endpoint. + :param endpoint: The communication resource, for example https://my-resource.communication.azure.com. :type endpoint: str """ @@ -38,7 +38,7 @@ def __init__( super(CommunicationIdentityClientConfiguration, self).__init__(**kwargs) self.endpoint = endpoint - self.api_version = "2020-07-20-preview2" + self.api_version = "2021-03-07" kwargs.setdefault('sdk_moniker', 'communicationidentityclient/{}'.format(VERSION)) self._configure(**kwargs) diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/__init__.py similarity index 100% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/__init__.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/__init__.py diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/_communication_identity_client.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/_communication_identity_client.py similarity index 89% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/_communication_identity_client.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/_communication_identity_client.py index 06c5aa66ddff..a9e14baadd75 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/_communication_identity_client.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/_communication_identity_client.py @@ -20,8 +20,8 @@ class CommunicationIdentityClient(object): """Azure Communication Identity Service. :ivar communication_identity: CommunicationIdentityOperations operations - :vartype communication_identity: azure.communication.administration.aio.operations.CommunicationIdentityOperations - :param endpoint: Auth and Identity endpoint. + :vartype communication_identity: azure.communication.identity.aio.operations.CommunicationIdentityOperations + :param endpoint: The communication resource, for example https://my-resource.communication.azure.com. :type endpoint: str """ diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/_configuration.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/_configuration.py similarity index 93% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/_configuration.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/_configuration.py index 4b91da974fe0..ffd8616506db 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/_configuration.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/_configuration.py @@ -19,7 +19,7 @@ class CommunicationIdentityClientConfiguration(Configuration): Note that all parameters used to create this instance are saved as instance attributes. - :param endpoint: Auth and Identity endpoint. + :param endpoint: The communication resource, for example https://my-resource.communication.azure.com. :type endpoint: str """ @@ -33,7 +33,7 @@ def __init__( super(CommunicationIdentityClientConfiguration, self).__init__(**kwargs) self.endpoint = endpoint - self.api_version = "2020-07-20-preview2" + self.api_version = "2021-03-07" kwargs.setdefault('sdk_moniker', 'communicationidentityclient/{}'.format(VERSION)) self._configure(**kwargs) diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/operations/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/operations/__init__.py similarity index 100% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/operations/__init__.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/operations/__init__.py diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/operations/_communication_identity_operations.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/operations/_communication_identity_operations.py similarity index 70% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/operations/_communication_identity_operations.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/operations/_communication_identity_operations.py index 9ff3934e2458..bf5d9fa4246b 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/aio/operations/_communication_identity_operations.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/aio/operations/_communication_identity_operations.py @@ -5,15 +5,14 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import datetime -from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar +from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union import warnings from azure.core.exceptions import ClientAuthenticationError, HttpResponseError, ResourceExistsError, ResourceNotFoundError, map_error from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import AsyncHttpResponse, HttpRequest -from ... import models +from ... import models as _models T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, AsyncHttpResponse], T, Dict[str, Any]], Any]] @@ -25,14 +24,14 @@ class CommunicationIdentityOperations: instantiates it for you and attaches it as an attribute. :ivar models: Alias to model classes used in this operation group. - :type models: ~azure.communication.administration.models + :type models: ~azure.communication.identity.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. """ - models = models + models = _models def __init__(self, client, config, serializer, deserializer) -> None: self._client = client @@ -42,23 +41,29 @@ def __init__(self, client, config, serializer, deserializer) -> None: async def create( self, + create_token_with_scopes: Optional[List[Union[str, "_models.CommunicationTokenScope"]]] = None, **kwargs - ) -> "models.CommunicationIdentity": + ) -> "_models.CommunicationIdentityAccessTokenResult": """Create a new identity. Create a new identity. + :param create_token_with_scopes: Also create access token for the created identity. + :type create_token_with_scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] :keyword callable cls: A custom type or function that will be passed the direct response - :return: CommunicationIdentity, or the result of cls(response) - :rtype: ~azure.communication.administration.models.CommunicationIdentity + :return: CommunicationIdentityAccessTokenResult, or the result of cls(response) + :rtype: ~azure.communication.identity.models.CommunicationIdentityAccessTokenResult :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.CommunicationIdentity"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationIdentityAccessTokenResult"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-07-20-preview2" + + _body = _models.CommunicationIdentityCreateRequest(create_token_with_scopes=create_token_with_scopes) + api_version = "2021-03-07" + content_type = kwargs.pop("content_type", "application/json") accept = "application/json" # Construct URL @@ -74,17 +79,25 @@ async def create( # Construct headers header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - request = self._client.post(url, query_parameters, header_parameters) + body_content_kwargs = {} # type: Dict[str, Any] + if _body is not None: + body_content = self._serialize.body(_body, 'CommunicationIdentityCreateRequest') + else: + body_content = None + body_content_kwargs['content'] = body_content + request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response - if response.status_code not in [200]: + if response.status_code not in [201]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) - deserialized = self._deserialize('CommunicationIdentity', pipeline_response) + deserialized = self._deserialize('CommunicationIdentityAccessTokenResult', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) @@ -97,9 +110,9 @@ async def delete( id: str, **kwargs ) -> None: - """Delete the identity, revoke all tokens of the identity and delete all associated data. + """Delete the identity, revoke all tokens for the identity and delete all associated data. - Delete the identity, revoke all tokens of the identity and delete all associated data. + Delete the identity, revoke all tokens for the identity and delete all associated data. :param id: Identifier of the identity to be deleted. :type id: str @@ -113,7 +126,8 @@ async def delete( 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-07-20-preview2" + api_version = "2021-03-07" + accept = "application/json" # Construct URL url = self.delete.metadata['url'] # type: ignore @@ -129,6 +143,7 @@ async def delete( # Construct headers header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') request = self._client.delete(url, query_parameters, header_parameters) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) @@ -136,27 +151,25 @@ async def delete( if response.status_code not in [204]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) if cls: return cls(pipeline_response, None, {}) delete.metadata = {'url': '/identities/{id}'} # type: ignore - async def update( + async def revoke_access_tokens( self, id: str, - tokens_valid_from: Optional[datetime.datetime] = None, **kwargs ) -> None: - """Update an Identity. + """Revoke all access tokens for the specific identity. - Update an Identity. + Revoke all access tokens for the specific identity. :param id: Identifier of the identity. :type id: str - :param tokens_valid_from: All tokens that are issued prior to this time will be revoked. - :type tokens_valid_from: ~datetime.datetime :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None @@ -167,13 +180,11 @@ async def update( 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - - _body = models.CommunicationIdentityUpdateRequest(tokens_valid_from=tokens_valid_from) - api_version = "2020-07-20-preview2" - content_type = kwargs.pop("content_type", "application/merge-patch+json") + api_version = "2021-03-07" + accept = "application/json" # Construct URL - url = self.update.metadata['url'] # type: ignore + url = self.revoke_access_tokens.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'id': self._serialize.url("id", id, 'str'), @@ -186,56 +197,54 @@ async def update( # Construct headers header_parameters = {} # type: Dict[str, Any] - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - body_content_kwargs = {} # type: Dict[str, Any] - body_content = self._serialize.body(_body, 'CommunicationIdentityUpdateRequest') - body_content_kwargs['content'] = body_content - request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs) + request = self._client.post(url, query_parameters, header_parameters) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response if response.status_code not in [204]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': '/identities/{id}'} # type: ignore + revoke_access_tokens.metadata = {'url': '/identities/{id}/:revokeAccessTokens'} # type: ignore - async def issue_token( + async def issue_access_token( self, id: str, - scopes: List[str], + scopes: List[Union[str, "_models.CommunicationTokenScope"]], **kwargs - ) -> "models.CommunicationIdentityToken": - """Generate a new token for an identity. + ) -> "_models.CommunicationUserToken": + """Issue a new token for an identity. - Generate a new token for an identity. + Issue a new token for an identity. :param id: Identifier of the identity to issue token for. :type id: str :param scopes: List of scopes attached to the token. - :type scopes: list[str] + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] :keyword callable cls: A custom type or function that will be passed the direct response - :return: CommunicationIdentityToken, or the result of cls(response) - :rtype: ~azure.communication.administration.models.CommunicationIdentityToken + :return: CommunicationUserToken, or the result of cls(response) + :rtype: ~azure.communication.identity.models.CommunicationUserToken :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.CommunicationIdentityToken"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationUserToken"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - _body = models.CommunicationTokenRequest(scopes=scopes) - api_version = "2020-07-20-preview2" + _body = _models.CommunicationIdentityAccessTokenRequest(scopes=scopes) + api_version = "2021-03-07" content_type = kwargs.pop("content_type", "application/json") accept = "application/json" # Construct URL - url = self.issue_token.metadata['url'] # type: ignore + url = self.issue_access_token.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'id': self._serialize.url("id", id, 'str'), @@ -252,7 +261,7 @@ async def issue_token( header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') body_content_kwargs = {} # type: Dict[str, Any] - body_content = self._serialize.body(_body, 'CommunicationTokenRequest') + body_content = self._serialize.body(_body, 'CommunicationIdentityAccessTokenRequest') body_content_kwargs['content'] = body_content request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) pipeline_response = await self._client._pipeline.run(request, stream=False, **kwargs) @@ -260,12 +269,13 @@ async def issue_token( if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) - deserialized = self._deserialize('CommunicationIdentityToken', pipeline_response) + deserialized = self._deserialize('CommunicationUserToken', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - issue_token.metadata = {'url': '/identities/{id}/token'} # type: ignore + issue_access_token.metadata = {'url': '/identities/{id}/:issueAccessToken'} # type: ignore diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/__init__.py new file mode 100644 index 000000000000..4c6b3887ee2d --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/__init__.py @@ -0,0 +1,39 @@ +# 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. +# -------------------------------------------------------------------------- + +try: + from ._models_py3 import CommunicationError + from ._models_py3 import CommunicationErrorResponse + from ._models_py3 import CommunicationIdentity + from ._models_py3 import CommunicationIdentityAccessTokenRequest + from ._models_py3 import CommunicationIdentityAccessTokenResult + from ._models_py3 import CommunicationIdentityCreateRequest + from ._models_py3 import CommunicationUserToken +except (SyntaxError, ImportError): + from ._models import CommunicationError # type: ignore + from ._models import CommunicationErrorResponse # type: ignore + from ._models import CommunicationIdentity # type: ignore + from ._models import CommunicationIdentityAccessTokenRequest # type: ignore + from ._models import CommunicationIdentityAccessTokenResult # type: ignore + from ._models import CommunicationIdentityCreateRequest # type: ignore + from ._models import CommunicationUserToken # type: ignore + +from ._communication_identity_client_enums import ( + CommunicationTokenScope, +) + +__all__ = [ + 'CommunicationError', + 'CommunicationErrorResponse', + 'CommunicationIdentity', + 'CommunicationIdentityAccessTokenRequest', + 'CommunicationIdentityAccessTokenResult', + 'CommunicationIdentityCreateRequest', + 'CommunicationUserToken', + 'CommunicationTokenScope', +] diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_communication_identity_client_enums.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_communication_identity_client_enums.py new file mode 100644 index 000000000000..fb650aac3d10 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_communication_identity_client_enums.py @@ -0,0 +1,34 @@ +# 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 enum import Enum, EnumMeta +from six import with_metaclass + +class _CaseInsensitiveEnumMeta(EnumMeta): + def __getitem__(self, name): + return super().__getitem__(name.upper()) + + def __getattr__(cls, name): + """Return the enum member matching `name` + We use __getattr__ instead of descriptors or inserting into the enum + class' __dict__ in order to support `name` and `value` being both + properties for enum members (which live in the class' __dict__) and + enum members themselves. + """ + try: + return cls._member_map_[name.upper()] + except KeyError: + raise AttributeError(name) + + +class CommunicationTokenScope(with_metaclass(_CaseInsensitiveEnumMeta, str, Enum)): + """List of scopes for an access token. + """ + + CHAT = "chat" + VOIP = "voip" diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_models.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_models.py new file mode 100644 index 000000000000..e788acd2aa32 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_models.py @@ -0,0 +1,210 @@ +# 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 azure.core.exceptions import HttpResponseError +import msrest.serialization + + +class CommunicationError(msrest.serialization.Model): + """The Communication Services error. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :param code: Required. The error code. + :type code: str + :param message: Required. The error message. + :type message: str + :ivar target: The error target. + :vartype target: str + :ivar details: Further details about specific errors that led to this error. + :vartype details: list[~azure.communication.identity.models.CommunicationError] + :param inner_error: The Communication Services error. + :type inner_error: ~azure.communication.identity.models.CommunicationError + """ + + _validation = { + 'code': {'required': True}, + 'message': {'required': True}, + 'target': {'readonly': True}, + 'details': {'readonly': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'target': {'key': 'target', 'type': 'str'}, + 'details': {'key': 'details', 'type': '[CommunicationError]'}, + 'inner_error': {'key': 'innerError', 'type': 'CommunicationError'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationError, self).__init__(**kwargs) + self.code = kwargs['code'] + self.message = kwargs['message'] + self.target = None + self.details = None + self.inner_error = kwargs.get('inner_error', None) + + +class CommunicationErrorResponse(msrest.serialization.Model): + """The Communication Services error. + + All required parameters must be populated in order to send to Azure. + + :param error: Required. The Communication Services error. + :type error: ~azure.communication.identity.models.CommunicationError + """ + + _validation = { + 'error': {'required': True}, + } + + _attribute_map = { + 'error': {'key': 'error', 'type': 'CommunicationError'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationErrorResponse, self).__init__(**kwargs) + self.error = kwargs['error'] + + +class CommunicationIdentity(msrest.serialization.Model): + """A communication identity. + + All required parameters must be populated in order to send to Azure. + + :param id: Required. Identifier of the identity. + :type id: str + """ + + _validation = { + 'id': {'required': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationIdentity, self).__init__(**kwargs) + self.id = kwargs['id'] + + +class CommunicationIdentityAccessTokenRequest(msrest.serialization.Model): + """CommunicationIdentityAccessTokenRequest. + + All required parameters must be populated in order to send to Azure. + + :param scopes: Required. List of scopes attached to the token. + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] + """ + + _validation = { + 'scopes': {'required': True}, + } + + _attribute_map = { + 'scopes': {'key': 'scopes', 'type': '[str]'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationIdentityAccessTokenRequest, self).__init__(**kwargs) + self.scopes = kwargs['scopes'] + + +class CommunicationIdentityAccessTokenResult(msrest.serialization.Model): + """A communication identity with access token. + + All required parameters must be populated in order to send to Azure. + + :param identity: Required. A communication identity. + :type identity: ~azure.communication.identity.models.CommunicationIdentity + :param access_token: An access token. + :type access_token: ~azure.communication.identity.models.CommunicationUserToken + """ + + _validation = { + 'identity': {'required': True}, + } + + _attribute_map = { + 'identity': {'key': 'identity', 'type': 'CommunicationIdentity'}, + 'access_token': {'key': 'accessToken', 'type': 'CommunicationUserToken'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationIdentityAccessTokenResult, self).__init__(**kwargs) + self.identity = kwargs['identity'] + self.access_token = kwargs.get('access_token', None) + + +class CommunicationIdentityCreateRequest(msrest.serialization.Model): + """CommunicationIdentityCreateRequest. + + :param create_token_with_scopes: Also create access token for the created identity. + :type create_token_with_scopes: list[str or + ~azure.communication.identity.models.CommunicationTokenScope] + """ + + _attribute_map = { + 'create_token_with_scopes': {'key': 'createTokenWithScopes', 'type': '[str]'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationIdentityCreateRequest, self).__init__(**kwargs) + self.create_token_with_scopes = kwargs.get('create_token_with_scopes', None) + + +class CommunicationUserToken(msrest.serialization.Model): + """An access token. + + All required parameters must be populated in order to send to Azure. + + :param token: Required. The access token issued for the identity. + :type token: str + :param expires_on: Required. The expiry time of the token. + :type expires_on: ~datetime.datetime + """ + + _validation = { + 'token': {'required': True}, + 'expires_on': {'required': True}, + } + + _attribute_map = { + 'token': {'key': 'token', 'type': 'str'}, + 'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'}, + } + + def __init__( + self, + **kwargs + ): + super(CommunicationUserToken, self).__init__(**kwargs) + self.token = kwargs['token'] + self.expires_on = kwargs['expires_on'] diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_models_py3.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_models_py3.py new file mode 100644 index 000000000000..b459227f23b4 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/models/_models_py3.py @@ -0,0 +1,231 @@ +# 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. +# -------------------------------------------------------------------------- + +import datetime +from typing import List, Optional, Union + +from azure.core.exceptions import HttpResponseError +import msrest.serialization + + +class CommunicationError(msrest.serialization.Model): + """The Communication Services error. + + Variables are only populated by the server, and will be ignored when sending a request. + + All required parameters must be populated in order to send to Azure. + + :param code: Required. The error code. + :type code: str + :param message: Required. The error message. + :type message: str + :ivar target: The error target. + :vartype target: str + :ivar details: Further details about specific errors that led to this error. + :vartype details: list[~azure.communication.identity.models.CommunicationError] + :param inner_error: The Communication Services error. + :type inner_error: ~azure.communication.identity.models.CommunicationError + """ + + _validation = { + 'code': {'required': True}, + 'message': {'required': True}, + 'target': {'readonly': True}, + 'details': {'readonly': True}, + } + + _attribute_map = { + 'code': {'key': 'code', 'type': 'str'}, + 'message': {'key': 'message', 'type': 'str'}, + 'target': {'key': 'target', 'type': 'str'}, + 'details': {'key': 'details', 'type': '[CommunicationError]'}, + 'inner_error': {'key': 'innerError', 'type': 'CommunicationError'}, + } + + def __init__( + self, + *, + code: str, + message: str, + inner_error: Optional["CommunicationError"] = None, + **kwargs + ): + super(CommunicationError, self).__init__(**kwargs) + self.code = code + self.message = message + self.target = None + self.details = None + self.inner_error = inner_error + + +class CommunicationErrorResponse(msrest.serialization.Model): + """The Communication Services error. + + All required parameters must be populated in order to send to Azure. + + :param error: Required. The Communication Services error. + :type error: ~azure.communication.identity.models.CommunicationError + """ + + _validation = { + 'error': {'required': True}, + } + + _attribute_map = { + 'error': {'key': 'error', 'type': 'CommunicationError'}, + } + + def __init__( + self, + *, + error: "CommunicationError", + **kwargs + ): + super(CommunicationErrorResponse, self).__init__(**kwargs) + self.error = error + + +class CommunicationIdentity(msrest.serialization.Model): + """A communication identity. + + All required parameters must be populated in order to send to Azure. + + :param id: Required. Identifier of the identity. + :type id: str + """ + + _validation = { + 'id': {'required': True}, + } + + _attribute_map = { + 'id': {'key': 'id', 'type': 'str'}, + } + + def __init__( + self, + *, + id: str, + **kwargs + ): + super(CommunicationIdentity, self).__init__(**kwargs) + self.id = id + + +class CommunicationIdentityAccessTokenRequest(msrest.serialization.Model): + """CommunicationIdentityAccessTokenRequest. + + All required parameters must be populated in order to send to Azure. + + :param scopes: Required. List of scopes attached to the token. + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] + """ + + _validation = { + 'scopes': {'required': True}, + } + + _attribute_map = { + 'scopes': {'key': 'scopes', 'type': '[str]'}, + } + + def __init__( + self, + *, + scopes: List[Union[str, "CommunicationTokenScope"]], + **kwargs + ): + super(CommunicationIdentityAccessTokenRequest, self).__init__(**kwargs) + self.scopes = scopes + + +class CommunicationIdentityAccessTokenResult(msrest.serialization.Model): + """A communication identity with access token. + + All required parameters must be populated in order to send to Azure. + + :param identity: Required. A communication identity. + :type identity: ~azure.communication.identity.models.CommunicationIdentity + :param access_token: An access token. + :type access_token: ~azure.communication.identity.models.CommunicationUserToken + """ + + _validation = { + 'identity': {'required': True}, + } + + _attribute_map = { + 'identity': {'key': 'identity', 'type': 'CommunicationIdentity'}, + 'access_token': {'key': 'accessToken', 'type': 'CommunicationUserToken'}, + } + + def __init__( + self, + *, + identity: "CommunicationIdentity", + access_token: Optional["CommunicationUserToken"] = None, + **kwargs + ): + super(CommunicationIdentityAccessTokenResult, self).__init__(**kwargs) + self.identity = identity + self.access_token = access_token + + +class CommunicationIdentityCreateRequest(msrest.serialization.Model): + """CommunicationIdentityCreateRequest. + + :param create_token_with_scopes: Also create access token for the created identity. + :type create_token_with_scopes: list[str or + ~azure.communication.identity.models.CommunicationTokenScope] + """ + + _attribute_map = { + 'create_token_with_scopes': {'key': 'createTokenWithScopes', 'type': '[str]'}, + } + + def __init__( + self, + *, + create_token_with_scopes: Optional[List[Union[str, "CommunicationTokenScope"]]] = None, + **kwargs + ): + super(CommunicationIdentityCreateRequest, self).__init__(**kwargs) + self.create_token_with_scopes = create_token_with_scopes + + +class CommunicationUserToken(msrest.serialization.Model): + """An access token. + + All required parameters must be populated in order to send to Azure. + + :param token: Required. The access token issued for the identity. + :type token: str + :param expires_on: Required. The expiry time of the token. + :type expires_on: ~datetime.datetime + """ + + _validation = { + 'token': {'required': True}, + 'expires_on': {'required': True}, + } + + _attribute_map = { + 'token': {'key': 'token', 'type': 'str'}, + 'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'}, + } + + def __init__( + self, + *, + token: str, + expires_on: datetime.datetime, + **kwargs + ): + super(CommunicationUserToken, self).__init__(**kwargs) + self.token = token + self.expires_on = expires_on diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/operations/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/operations/__init__.py similarity index 100% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/operations/__init__.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/operations/__init__.py diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/operations/_communication_identity_operations.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/operations/_communication_identity_operations.py similarity index 70% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/operations/_communication_identity_operations.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/operations/_communication_identity_operations.py index 26d1a86a88d2..0c1d77b6e1cb 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/operations/_communication_identity_operations.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/operations/_communication_identity_operations.py @@ -5,7 +5,6 @@ # Code generated by Microsoft (R) AutoRest Code Generator. # Changes may cause incorrect behavior and will be lost if the code is regenerated. # -------------------------------------------------------------------------- -import datetime from typing import TYPE_CHECKING import warnings @@ -13,11 +12,11 @@ from azure.core.pipeline import PipelineResponse from azure.core.pipeline.transport import HttpRequest, HttpResponse -from .. import models +from .. import models as _models if TYPE_CHECKING: # pylint: disable=unused-import,ungrouped-imports - from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar + from typing import Any, Callable, Dict, Generic, List, Optional, TypeVar, Union T = TypeVar('T') ClsType = Optional[Callable[[PipelineResponse[HttpRequest, HttpResponse], T, Dict[str, Any]], Any]] @@ -29,14 +28,14 @@ class CommunicationIdentityOperations(object): instantiates it for you and attaches it as an attribute. :ivar models: Alias to model classes used in this operation group. - :type models: ~azure.communication.administration.models + :type models: ~azure.communication.identity.models :param client: Client for service requests. :param config: Configuration of service client. :param serializer: An object model serializer. :param deserializer: An object model deserializer. """ - models = models + models = _models def __init__(self, client, config, serializer, deserializer): self._client = client @@ -46,24 +45,30 @@ def __init__(self, client, config, serializer, deserializer): def create( self, + create_token_with_scopes=None, # type: Optional[List[Union[str, "_models.CommunicationTokenScope"]]] **kwargs # type: Any ): - # type: (...) -> "models.CommunicationIdentity" + # type: (...) -> "_models.CommunicationIdentityAccessTokenResult" """Create a new identity. Create a new identity. + :param create_token_with_scopes: Also create access token for the created identity. + :type create_token_with_scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] :keyword callable cls: A custom type or function that will be passed the direct response - :return: CommunicationIdentity, or the result of cls(response) - :rtype: ~azure.communication.administration.models.CommunicationIdentity + :return: CommunicationIdentityAccessTokenResult, or the result of cls(response) + :rtype: ~azure.communication.identity.models.CommunicationIdentityAccessTokenResult :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.CommunicationIdentity"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationIdentityAccessTokenResult"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-07-20-preview2" + + _body = _models.CommunicationIdentityCreateRequest(create_token_with_scopes=create_token_with_scopes) + api_version = "2021-03-07" + content_type = kwargs.pop("content_type", "application/json") accept = "application/json" # Construct URL @@ -79,17 +84,25 @@ def create( # Construct headers header_parameters = {} # type: Dict[str, Any] + header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - request = self._client.post(url, query_parameters, header_parameters) + body_content_kwargs = {} # type: Dict[str, Any] + if _body is not None: + body_content = self._serialize.body(_body, 'CommunicationIdentityCreateRequest') + else: + body_content = None + body_content_kwargs['content'] = body_content + request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response - if response.status_code not in [200]: + if response.status_code not in [201]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) - deserialized = self._deserialize('CommunicationIdentity', pipeline_response) + deserialized = self._deserialize('CommunicationIdentityAccessTokenResult', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) @@ -103,9 +116,9 @@ def delete( **kwargs # type: Any ): # type: (...) -> None - """Delete the identity, revoke all tokens of the identity and delete all associated data. + """Delete the identity, revoke all tokens for the identity and delete all associated data. - Delete the identity, revoke all tokens of the identity and delete all associated data. + Delete the identity, revoke all tokens for the identity and delete all associated data. :param id: Identifier of the identity to be deleted. :type id: str @@ -119,7 +132,8 @@ def delete( 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - api_version = "2020-07-20-preview2" + api_version = "2021-03-07" + accept = "application/json" # Construct URL url = self.delete.metadata['url'] # type: ignore @@ -135,6 +149,7 @@ def delete( # Construct headers header_parameters = {} # type: Dict[str, Any] + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') request = self._client.delete(url, query_parameters, header_parameters) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) @@ -142,28 +157,26 @@ def delete( if response.status_code not in [204]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) if cls: return cls(pipeline_response, None, {}) delete.metadata = {'url': '/identities/{id}'} # type: ignore - def update( + def revoke_access_tokens( self, id, # type: str - tokens_valid_from=None, # type: Optional[datetime.datetime] **kwargs # type: Any ): # type: (...) -> None - """Update an Identity. + """Revoke all access tokens for the specific identity. - Update an Identity. + Revoke all access tokens for the specific identity. :param id: Identifier of the identity. :type id: str - :param tokens_valid_from: All tokens that are issued prior to this time will be revoked. - :type tokens_valid_from: ~datetime.datetime :keyword callable cls: A custom type or function that will be passed the direct response :return: None, or the result of cls(response) :rtype: None @@ -174,13 +187,11 @@ def update( 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - - _body = models.CommunicationIdentityUpdateRequest(tokens_valid_from=tokens_valid_from) - api_version = "2020-07-20-preview2" - content_type = kwargs.pop("content_type", "application/merge-patch+json") + api_version = "2021-03-07" + accept = "application/json" # Construct URL - url = self.update.metadata['url'] # type: ignore + url = self.revoke_access_tokens.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'id': self._serialize.url("id", id, 'str'), @@ -193,57 +204,55 @@ def update( # Construct headers header_parameters = {} # type: Dict[str, Any] - header_parameters['Content-Type'] = self._serialize.header("content_type", content_type, 'str') + header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') - body_content_kwargs = {} # type: Dict[str, Any] - body_content = self._serialize.body(_body, 'CommunicationIdentityUpdateRequest') - body_content_kwargs['content'] = body_content - request = self._client.patch(url, query_parameters, header_parameters, **body_content_kwargs) + request = self._client.post(url, query_parameters, header_parameters) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) response = pipeline_response.http_response if response.status_code not in [204]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) if cls: return cls(pipeline_response, None, {}) - update.metadata = {'url': '/identities/{id}'} # type: ignore + revoke_access_tokens.metadata = {'url': '/identities/{id}/:revokeAccessTokens'} # type: ignore - def issue_token( + def issue_access_token( self, id, # type: str - scopes, # type: List[str] + scopes, # type: List[Union[str, "_models.CommunicationTokenScope"]] **kwargs # type: Any ): - # type: (...) -> "models.CommunicationIdentityToken" - """Generate a new token for an identity. + # type: (...) -> "_models.CommunicationUserToken" + """Issue a new token for an identity. - Generate a new token for an identity. + Issue a new token for an identity. :param id: Identifier of the identity to issue token for. :type id: str :param scopes: List of scopes attached to the token. - :type scopes: list[str] + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] :keyword callable cls: A custom type or function that will be passed the direct response - :return: CommunicationIdentityToken, or the result of cls(response) - :rtype: ~azure.communication.administration.models.CommunicationIdentityToken + :return: CommunicationUserToken, or the result of cls(response) + :rtype: ~azure.communication.identity.models.CommunicationUserToken :raises: ~azure.core.exceptions.HttpResponseError """ - cls = kwargs.pop('cls', None) # type: ClsType["models.CommunicationIdentityToken"] + cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationUserToken"] error_map = { 401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError } error_map.update(kwargs.pop('error_map', {})) - _body = models.CommunicationTokenRequest(scopes=scopes) - api_version = "2020-07-20-preview2" + _body = _models.CommunicationIdentityAccessTokenRequest(scopes=scopes) + api_version = "2021-03-07" content_type = kwargs.pop("content_type", "application/json") accept = "application/json" # Construct URL - url = self.issue_token.metadata['url'] # type: ignore + url = self.issue_access_token.metadata['url'] # type: ignore path_format_arguments = { 'endpoint': self._serialize.url("self._config.endpoint", self._config.endpoint, 'str', skip_quote=True), 'id': self._serialize.url("id", id, 'str'), @@ -260,7 +269,7 @@ def issue_token( header_parameters['Accept'] = self._serialize.header("accept", accept, 'str') body_content_kwargs = {} # type: Dict[str, Any] - body_content = self._serialize.body(_body, 'CommunicationTokenRequest') + body_content = self._serialize.body(_body, 'CommunicationIdentityAccessTokenRequest') body_content_kwargs['content'] = body_content request = self._client.post(url, query_parameters, header_parameters, **body_content_kwargs) pipeline_response = self._client._pipeline.run(request, stream=False, **kwargs) @@ -268,12 +277,13 @@ def issue_token( if response.status_code not in [200]: map_error(status_code=response.status_code, response=response, error_map=error_map) - raise HttpResponseError(response=response) + error = self._deserialize(_models.CommunicationErrorResponse, response) + raise HttpResponseError(response=response, model=error) - deserialized = self._deserialize('CommunicationIdentityToken', pipeline_response) + deserialized = self._deserialize('CommunicationUserToken', pipeline_response) if cls: return cls(pipeline_response, deserialized, {}) return deserialized - issue_token.metadata = {'url': '/identities/{id}/token'} # type: ignore + issue_access_token.metadata = {'url': '/identities/{id}/:issueAccessToken'} # type: ignore diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/py.typed b/sdk/communication/azure-communication-identity/azure/communication/identity/_generated/py.typed similarity index 100% rename from sdk/communication/azure-communication-administration/azure/communication/administration/_identity/_generated/py.typed rename to sdk/communication/azure-communication-identity/azure/communication/identity/_generated/py.typed diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/__init__.py new file mode 100644 index 000000000000..5b396cd202e8 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/__init__.py @@ -0,0 +1,5 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py new file mode 100644 index 000000000000..51260e07d2d9 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/models.py @@ -0,0 +1,55 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +class CommunicationUserIdentifier(object): + """ + Represents a user in Azure Communication Service. + :ivar identifier: Communication user identifier. + :vartype identifier: str + :param identifier: Identifier to initialize CommunicationUserIdentifier. + :type identifier: str + """ + def __init__(self, identifier): + self.identifier = identifier + +class PhoneNumberIdentifier(object): + """ + Represents a phone number. + :ivar value: Value for a phone number. + :vartype value: str + :param value: Value to initialize PhoneNumberIdentifier. + :type value: str + """ + def __init__(self, value): + self.value = value + +class UnknownIdentifier(object): + """ + Represents an identifier of an unknown type. + It will be encountered in communications with endpoints that are not + identifiable by this version of the SDK. + :ivar identifier: Unknown communication identifier. + :vartype identifier: str + :param identifier: Value to initialize UnknownIdentifier. + :type identifier: str + """ + def __init__(self, identifier): + self.identifier = identifier + +class MicrosoftTeamsUserIdentifier(object): + """ + Represents an identifier for a Microsoft Teams user. + :ivar user_id: the string identifier representing the identity + :vartype user_id: str + :param user_id: Value to initialize MicrosoftTeamsUserIdentifier. + :type user_id: str + :ivar is_anonymous: set this to true if the user is anonymous for example when joining a meeting with a share link + :vartype is_anonymous: bool + :param is_anonymous: Value to initialize MicrosoftTeamsUserIdentifier. + :type is_anonymous: bool + """ + def __init__(self, user_id, is_anonymous=False): + self.user_id = user_id + self.is_anonymous = is_anonymous diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/policy.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/policy.py new file mode 100644 index 000000000000..b2a0de8d4238 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/policy.py @@ -0,0 +1,91 @@ +# ------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ------------------------------------------------------------------------- + +import hashlib +import urllib +import base64 +import hmac +from azure.core.pipeline.policies import SansIOHTTPPolicy +from .utils import get_current_utc_time + +class HMACCredentialsPolicy(SansIOHTTPPolicy): + """Implementation of HMAC authentication policy. + """ + + def __init__(self, + host, # type: str + access_key, # type: str + decode_url=False # type: bool + ): + # type: (...) -> None + super(HMACCredentialsPolicy, self).__init__() + + if host.startswith("https://"): + self._host = host.replace("https://", "") + + if host.startswith("http://"): + self._host = host.replace("http://", "") + + self._access_key = access_key + self._decode_url = decode_url + + def _compute_hmac(self, + value # type: str + ): + decoded_secret = base64.b64decode(self._access_key) + digest = hmac.new( + decoded_secret, value.encode("utf-8"), hashlib.sha256 + ).digest() + + return base64.b64encode(digest).decode("utf-8") + + def _sign_request(self, request): + verb = request.http_request.method.upper() + + # Get the path and query from url, which looks like https://host/path/query + query_url = str(request.http_request.url[len(self._host) + 8:]) + + if self._decode_url: + query_url = urllib.parse.unquote(query_url) + + signed_headers = "date;host;x-ms-content-sha256" + + utc_now = get_current_utc_time() + if request.http_request.body is None: + request.http_request.body = "" + content_digest = hashlib.sha256( + (request.http_request.body.encode("utf-8")) + ).digest() + content_hash = base64.b64encode(content_digest).decode("utf-8") + + string_to_sign = ( + verb + + "\n" + + query_url + + "\n" + + utc_now + + ";" + + self._host + + ";" + + content_hash + ) + + signature = self._compute_hmac(string_to_sign) + + signature_header = { + "Date": utc_now, + "x-ms-content-sha256": content_hash, + "x-ms-return-client-request-id": "true", + "Authorization": "HMAC-SHA256 SignedHeaders=" +\ + signed_headers + "&Signature=" + signature, + } + + request.http_request.headers.update(signature_header) + + return request + + def on_request(self, request): + self._sign_request(request) diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_credential.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_credential.py new file mode 100644 index 000000000000..e920d356a518 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_credential.py @@ -0,0 +1,83 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from threading import Lock, Condition +from datetime import datetime, timedelta +from typing import ( # pylint: disable=unused-import + cast, + Tuple, +) + +from msrest.serialization import TZ_UTC + +class CommunicationTokenCredential(object): + """Credential type used for authenticating to an Azure Communication service. + :param communication_token_refresh_options: The token used to authenticate to an Azure Communication service + :type communication_token_refresh_options: ~azure.communication.chat.CommunicationTokenRefreshOptions + """ + + ON_DEMAND_REFRESHING_INTERVAL_MINUTES = 2 + + def __init__(self, + communication_token_refresh_options + ): + self._token = communication_token_refresh_options.get_token() + self._token_refresher = communication_token_refresh_options.get_token_refresher() + self._lock = Condition(Lock()) + self._some_thread_refreshing = False + + def get_token(self): + # type () -> ~azure.core.credentials.AccessToken + """The value of the configured token. + :rtype: ~azure.core.credentials.AccessToken + """ + + if not self._token_refresher or not self._token_expiring(): + return self._token + + should_this_thread_refresh = False + + with self._lock: + while self._token_expiring(): + if self._some_thread_refreshing: + if self._is_currenttoken_valid(): + return self._token + + self._wait_till_inprogress_thread_finish_refreshing() + else: + should_this_thread_refresh = True + self._some_thread_refreshing = True + break + + if should_this_thread_refresh: + try: + newtoken = self._token_refresher() + + with self._lock: + self._token = newtoken + self._some_thread_refreshing = False + self._lock.notify_all() + except: + with self._lock: + self._some_thread_refreshing = False + self._lock.notify_all() + + raise + return self._token + + def _wait_till_inprogress_thread_finish_refreshing(self): + self._lock.release() + self._lock.acquire() + + def _token_expiring(self): + return self._token.expires_on - self._get_utc_now() <\ + timedelta(minutes=self.ON_DEMAND_REFRESHING_INTERVAL_MINUTES) + + def _is_currenttoken_valid(self): + return self._get_utc_now() < self._token.expires_on + + @classmethod + def _get_utc_now(cls): + return datetime.now().replace(tzinfo=TZ_UTC) diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_credential_async.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_credential_async.py new file mode 100644 index 000000000000..0918074eb04a --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_credential_async.py @@ -0,0 +1,87 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from asyncio import Condition, Lock +from datetime import datetime, timedelta +from typing import ( # pylint: disable=unused-import + cast, + Tuple, +) + +from msrest.serialization import TZ_UTC + +class CommunicationTokenCredential(object): + """Credential type used for authenticating to an Azure Communication service. + :param communication_token_refresh_options: The token used to authenticate to an Azure Communication service + :type communication_token_refresh_options: ~azure.communication.chat.aio.CommunicationTokenRefreshOptions + :raises: TypeError + """ + + ON_DEMAND_REFRESHING_INTERVAL_MINUTES = 2 + + def __init__(self, + communication_token_refresh_options + ): + self._token = communication_token_refresh_options.get_token() + self._token_refresher = communication_token_refresh_options.get_token_refresher() + self._lock = Condition(Lock()) + self._some_thread_refreshing = False + + def get_token(self): + # type () -> ~azure.core.credentials.AccessToken + """The value of the configured token. + :rtype: ~azure.core.credentials.AccessToken + """ + + if not self._token_refresher or not self._token_expiring(): + return self._token + + should_this_thread_refresh = False + + with self._lock: + + while self._token_expiring(): + if self._some_thread_refreshing: + if self._is_currenttoken_valid(): + return self._token + + self._wait_till_inprogress_thread_finish_refreshing() + else: + should_this_thread_refresh = True + self._some_thread_refreshing = True + break + + + if should_this_thread_refresh: + try: + newtoken = self._token_refresher() + + with self._lock: + self._token = newtoken + self._some_thread_refreshing = False + self._lock.notify_all() + except: + with self._lock: + self._some_thread_refreshing = False + self._lock.notify_all() + + raise + + return self._token + + def _wait_till_inprogress_thread_finish_refreshing(self): + self._lock.release() + self._lock.acquire() + + def _token_expiring(self): + return self._token.expires_on - self._get_utc_now() <\ + timedelta(minutes=self.ON_DEMAND_REFRESHING_INTERVAL_MINUTES) + + def _is_currenttoken_valid(self): + return self._get_utc_now() < self._token.expires_on + + @classmethod + def _get_utc_now(cls): + return datetime.now().replace(tzinfo=TZ_UTC) diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_token_refresh_options.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_token_refresh_options.py new file mode 100644 index 000000000000..6bdc0d456026 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/user_token_refresh_options.py @@ -0,0 +1,36 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from typing import ( # pylint: disable=unused-import + cast, + Tuple, +) +import six +from .utils import create_access_token + +class CommunicationTokenRefreshOptions(object): + """Options for refreshing CommunicationTokenCredential. + :param str token: The token used to authenticate to an Azure Communication service + :param token_refresher: The token refresher to provide capacity to fetch fresh token + :raises: TypeError + """ + + def __init__(self, + token, # type: str + token_refresher=None + ): + # type: (str) -> None + if not isinstance(token, six.string_types): + raise TypeError("token must be a string.") + self._token = token + self._token_refresher = token_refresher + + def get_token(self): + """Return the the serialized JWT token.""" + return create_access_token(self._token) + + def get_token_refresher(self): + """Return the token refresher to provide capacity to fetch fresh token.""" + return self._token_refresher diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/utils.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/utils.py new file mode 100644 index 000000000000..18da505150ba --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_shared/utils.py @@ -0,0 +1,103 @@ +# ------------------------------------------------------------------------ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ------------------------------------------------------------------------- + +import base64 +import json +from typing import ( # pylint: disable=unused-import + cast, + Tuple, +) +from datetime import datetime +from msrest.serialization import TZ_UTC +from azure.core.credentials import AccessToken + +def parse_connection_str(conn_str): + # type: (str) -> Tuple[str, str, str, str] + endpoint = None + shared_access_key = None + for element in conn_str.split(";"): + key, _, value = element.partition("=") + if key.lower() == "endpoint": + endpoint = value.rstrip("/") + elif key.lower() == "accesskey": + shared_access_key = value + if not all([endpoint, shared_access_key]): + raise ValueError( + "Invalid connection string. Should be in the format: " + "endpoint=sb:///;accesskey=" + ) + left_slash_pos = cast(str, endpoint).find("//") + if left_slash_pos != -1: + host = cast(str, endpoint)[left_slash_pos + 2:] + else: + host = str(endpoint) + + return host, str(shared_access_key) + + +def get_current_utc_time(): + # type: () -> str + return str(datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S ")) + "GMT" + +def create_access_token(token): + # type: (str) -> azure.core.credentials.AccessToken + """Creates an instance of azure.core.credentials.AccessToken from a + string token. The input string is jwt token in the following form: + .. + This method looks into the token_payload which is a json and extracts the expiry time + for that token and creates a tuple of type azure.core.credentials.AccessToken + (, ) + :param token: User token + :type token: str + :return: Instance of azure.core.credentials.AccessToken - token and expiry date of it + :rtype: ~azure.core.credentials.AccessToken + """ + + token_parse_err_msg = "Token is not formatted correctly" + parts = token.split(".") + + if len(parts) < 3: + raise ValueError(token_parse_err_msg) + + try: + padded_base64_payload = base64.b64decode(parts[1] + "==").decode('ascii') + payload = json.loads(padded_base64_payload) + return AccessToken(token, datetime.fromtimestamp(payload['exp']).replace(tzinfo=TZ_UTC)) + except ValueError: + raise ValueError(token_parse_err_msg) + +def get_authentication_policy( + endpoint, # type: str + credential, # type: TokenCredential or str + is_async=False, # type: bool +): + # type: (...) -> BearerTokenCredentialPolicy or HMACCredentialPolicy + """Returns the correct authentication policy based + on which credential is being passed. + + :param endpoint: The endpoint to which we are authenticating to. + :type endpoint: str + :param credential: The credential we use to authenticate to the service + :type credential: TokenCredential or str + :param isAsync: For async clients there is a need to decode the url + :type bool: isAsync or str + + :rtype: ~azure.core.pipeline.policies.BearerTokenCredentialPolicy + ~HMACCredentialsPolicy + """ + + if credential is None: + raise ValueError("Parameter 'credential' must not be None.") + if hasattr(credential, "get_token"): + from azure.core.pipeline.policies import BearerTokenCredentialPolicy + return BearerTokenCredentialPolicy( + credential, "https://communication.azure.com//.default") + if isinstance(credential, str): + from .._shared.policy import HMACCredentialsPolicy + return HMACCredentialsPolicy(endpoint, credential, decode_url=is_async) + + raise TypeError("Unsupported credential: {}. Use an access token string to use HMACCredentialsPolicy" + "or a token credential from azure.identity".format(type(credential))) diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/_version.py b/sdk/communication/azure-communication-identity/azure/communication/identity/_version.py new file mode 100644 index 000000000000..22f6d37839a7 --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/_version.py @@ -0,0 +1,9 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- + +VERSION = "1.0.0b4" + +SDK_MONIKER = "communication-identity/{}".format(VERSION) # type: str diff --git a/sdk/communication/azure-communication-identity/azure/communication/identity/aio/__init__.py b/sdk/communication/azure-communication-identity/azure/communication/identity/aio/__init__.py new file mode 100644 index 000000000000..c2544f786cbf --- /dev/null +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/aio/__init__.py @@ -0,0 +1,5 @@ +from ._communication_identity_client_async import CommunicationIdentityClient + +__all__ = [ + 'CommunicationIdentityClient' +] diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/aio/_communication_identity_client_async.py b/sdk/communication/azure-communication-identity/azure/communication/identity/aio/_communication_identity_client_async.py similarity index 70% rename from sdk/communication/azure-communication-administration/azure/communication/administration/aio/_communication_identity_client_async.py rename to sdk/communication/azure-communication-identity/azure/communication/identity/aio/_communication_identity_client_async.py index 4347edb7e3e8..9db27f05aeb1 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/aio/_communication_identity_client_async.py +++ b/sdk/communication/azure-communication-identity/azure/communication/identity/aio/_communication_identity_client_async.py @@ -6,9 +6,9 @@ from azure.core.tracing.decorator_async import distributed_trace_async -from .._identity._generated.aio._communication_identity_client\ +from .._generated.aio._communication_identity_client\ import CommunicationIdentityClient as CommunicationIdentityClientGen -from .._identity._generated.models import CommunicationIdentityToken +from .._generated.models import CommunicationUserToken from .._shared.utils import parse_connection_str, get_authentication_policy from .._shared.models import CommunicationUserIdentifier @@ -64,7 +64,7 @@ def from_connection_string( :param str conn_str: A connection string to an Azure Communication Service resource. :returns: Instance of CommunicationIdentityClient. - :rtype: ~azure.communication.aio.CommunicationIdentityClient + :rtype: ~azure.communication.identity.aio.CommunicationIdentityClient .. admonition:: Example: @@ -84,11 +84,32 @@ async def create_user(self, **kwargs): # type: (...) -> CommunicationUserIdentifier """create a single Communication user - return: CommunicationUserIdentifier - rtype: ~azure.communication.administration.CommunicationUserIdentifier + :return: CommunicationUserIdentifier + :rtype: ~azure.communication.identity.CommunicationUserIdentifier """ return await self._identity_service_client.communication_identity.create( - cls=lambda pr, u, e: CommunicationUserIdentifier(u.id), + cls=lambda pr, u, e: CommunicationUserIdentifier(u.identity.id), + **kwargs) + + @distributed_trace_async + async def create_user_with_token( + self, + scopes, # type: List[Union[str, "_model.CommunicationTokenScope"]] + **kwargs + ): + # type: (...) -> Tuple[CommunicationUserIdentifier, CommunicationUserToken] + """create a single Communication user along with an Identity Token + + :param scopes: + List of scopes to be added to the token. + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] + :return: A tuple of a CommunicationUserIdentifier and a CommunicationUserToken. + :rtype: tuple of (~azure.communication.identity.CommunicationUserIdentifier, \ +~azure.communication.identity.CommunicationUserToken) + """ + return await self._identity_service_client.communication_identity.create( + create_token_with_scopes=scopes, + cls=lambda pr, u, e: CommunicationUserIdentifier(u.identity.id), **kwargs) @distributed_trace_async @@ -102,7 +123,7 @@ async def delete_user( :param communication_user: Azure Communication User to delete - :type communication_user: ~azure.communication.administration.CommunicationUserIdentifier + :type communication_user: ~azure.communication.identity.CommunicationUserIdentifier :return: None :rtype: None """ @@ -113,21 +134,21 @@ async def delete_user( async def issue_token( self, user, # type: CommunicationUserIdentifier - scopes, # type: List[str] + scopes, # type: List[Union[str, "_model.CommunicationTokenScope"]] **kwargs # type: Any ): - # type: (...) -> CommunicationIdentityToken + # type: (...) -> CommunicationUserToken """Generates a new token for an identity. :param user: Azure Communication User - :type user: ~azure.communication.administration.CommunicationUserIdentifier + :type user: ~azure.communication.identity.CommunicationUserIdentifier :param scopes: List of scopes to be added to the token. - :type scopes: list[str] - :return: CommunicationIdentityToken - :rtype: ~azure.communication.administration.CommunicationIdentityToken + :type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope] + :return: CommunicationUserToken + :rtype: ~azure.communication.identity.CommunicationUserToken """ - return await self._identity_service_client.communication_identity.issue_token( + return await self._identity_service_client.communication_identity.issue_access_token( user.identifier, scopes, **kwargs) @@ -136,22 +157,18 @@ async def issue_token( async 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 + :type user: ~azure.communication.identity.CommunicationUserIdentifier :return: None :rtype: None """ - return await self._identity_service_client.communication_identity.update( + return await self._identity_service_client.communication_identity.revoke_access_tokens( user.identifier if user else None, - tokens_valid_from=issued_before, **kwargs) async def __aenter__(self) -> "CommunicationIdentityClient": @@ -163,6 +180,6 @@ async def __aexit__(self, *args: "Any") -> None: async def close(self) -> None: """Close the :class: - `~azure.communication.administration.aio.CommunicationIdentityClient` session. + `~azure.communication.identity.aio.CommunicationIdentityClient` session. """ await self._identity_service_client.__aexit__() diff --git a/sdk/communication/azure-communication-identity/dev_requirements.txt b/sdk/communication/azure-communication-identity/dev_requirements.txt new file mode 100644 index 000000000000..6feae79262c7 --- /dev/null +++ b/sdk/communication/azure-communication-identity/dev_requirements.txt @@ -0,0 +1,7 @@ +-e ../../../tools/azure-sdk-tools +-e ../../../tools/azure-devtools +-e ../../identity/azure-identity +../../core/azure-core +../azure-communication-nspkg +../azure-mgmt-communication +aiohttp>=3.0; python_version >= '3.5' \ No newline at end of file diff --git a/sdk/communication/azure-communication-administration/samples/identity_samples.py b/sdk/communication/azure-communication-identity/samples/identity_samples.py similarity index 90% rename from sdk/communication/azure-communication-administration/samples/identity_samples.py rename to sdk/communication/azure-communication-identity/samples/identity_samples.py index e20e5cfedfba..cf28e9fe18e8 100644 --- a/sdk/communication/azure-communication-administration/samples/identity_samples.py +++ b/sdk/communication/azure-communication-identity/samples/identity_samples.py @@ -27,7 +27,7 @@ def __init__(self): self.tenant_id = os.getnenv('AZURE_TENANT_ID') def issue_token(self): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential @@ -39,7 +39,7 @@ def issue_token(self): print(tokenresponse) def revoke_tokens(self): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential @@ -52,7 +52,7 @@ def revoke_tokens(self): print(tokenresponse) def create_user(self): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential @@ -63,7 +63,7 @@ def create_user(self): print(user.identifier) def delete_user(self): - from azure.communication.administration import CommunicationIdentityClient + from azure.communication.identity import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential diff --git a/sdk/communication/azure-communication-administration/samples/identity_samples_async.py b/sdk/communication/azure-communication-identity/samples/identity_samples_async.py similarity index 91% rename from sdk/communication/azure-communication-administration/samples/identity_samples_async.py rename to sdk/communication/azure-communication-identity/samples/identity_samples_async.py index 0cbb8c147fb0..2b2b8e17b992 100644 --- a/sdk/communication/azure-communication-administration/samples/identity_samples_async.py +++ b/sdk/communication/azure-communication-identity/samples/identity_samples_async.py @@ -30,7 +30,7 @@ def __init__(self): self.tenant_id = os.getnenv('AZURE_TENANT_ID') async def issue_token(self): - from azure.communication.administration.aio import CommunicationIdentityClient + from azure.communication.identity.aio import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) @@ -44,7 +44,7 @@ async def issue_token(self): print(tokenresponse) async def revoke_tokens(self): - from azure.communication.administration.aio import CommunicationIdentityClient + from azure.communication.identity.aio import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) @@ -58,7 +58,7 @@ async def revoke_tokens(self): print(tokenresponse) async def create_user(self): - from azure.communication.administration.aio import CommunicationIdentityClient + from azure.communication.identity.aio import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) @@ -70,7 +70,7 @@ async def create_user(self): print(user.identifier) async def delete_user(self): - from azure.communication.administration.aio import CommunicationIdentityClient + from azure.communication.identity.aio import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) diff --git a/sdk/communication/azure-communication-identity/sdk_packaging.toml b/sdk/communication/azure-communication-identity/sdk_packaging.toml new file mode 100644 index 000000000000..88dbadd37a99 --- /dev/null +++ b/sdk/communication/azure-communication-identity/sdk_packaging.toml @@ -0,0 +1,7 @@ +[packaging] +auto_update = false +package_name = "azure-communication-identity" +package_pprint_name = "Communication Identity Service" +package_doc_id = "" +is_stable = false +is_arm = false \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/setup.cfg b/sdk/communication/azure-communication-identity/setup.cfg new file mode 100644 index 000000000000..3480374bc2f2 --- /dev/null +++ b/sdk/communication/azure-communication-identity/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal=1 \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/setup.py b/sdk/communication/azure-communication-identity/setup.py new file mode 100644 index 000000000000..9efe558e6239 --- /dev/null +++ b/sdk/communication/azure-communication-identity/setup.py @@ -0,0 +1,76 @@ +from setuptools import setup, find_packages +import os +from io import open +import re + +# example setup.py Feel free to copy the entire "azure-template" folder into a package folder named +# with "azure-". Ensure that the below arguments to setup() are updated to reflect +# your package. + +# this setup.py is set up in a specific way to keep the azure* and azure-mgmt-* namespaces WORKING all the way +# up from python 2.7. Reference here: https://github.com/Azure/azure-sdk-for-python/wiki/Azure-packaging + +PACKAGE_NAME = "azure-communication-identity" +PACKAGE_PPRINT_NAME = "Communication Identity Service" + +# a-b-c => a/b/c +package_folder_path = PACKAGE_NAME.replace('-', '/') +# a-b-c => a.b.c +namespace_name = PACKAGE_NAME.replace('-', '.') + +# Version extraction inspired from 'requests' +with open(os.path.join(package_folder_path, '_version.py'), 'r') as fd: + version = re.search(r'^VERSION\s*=\s*[\'"]([^\'"]*)[\'"]', + fd.read(), re.MULTILINE).group(1) +if not version: + raise RuntimeError('Cannot find version information') + +with open('README.md', encoding='utf-8') as f: + long_description = f.read() + +setup( + name=PACKAGE_NAME, + version=version, + description='Microsoft Azure {} Client Library for Python'.format(PACKAGE_PPRINT_NAME), + long_description_content_type='text/markdown', + + # ensure that these are updated to reflect the package owners' information + long_description=long_description, + url='https://github.com/Azure/azure-sdk-for-python', + author='Microsoft Corporation', + author_email='azuresdkengsysadmins@microsoft.com', + + license='MIT License', + # ensure that the development status reflects the status of your package + classifiers=[ + "Development Status :: 4 - Beta", + + 'Programming Language :: Python', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3.7', + 'Programming Language :: Python :: 3.8', + 'License :: OSI Approved :: MIT License', + ], + packages=find_packages(exclude=[ + 'tests', + # Exclude packages that will be covered by PEP420 or nspkg + 'azure', + 'azure.communication' + ]), + install_requires=[ + 'msrest>=0.5.0', + "azure-core<2.0.0,>=1.2.2" + ], + extras_require={ + ":python_version<'3.0'": ['azure-communication-nspkg'], + }, + project_urls={ + 'Bug Reports': 'https://github.com/Azure/azure-sdk-for-python/issues', + 'Source': 'https://github.com/Azure/azure-sdk-for-python', + } +) \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/swagger/SWAGGER.md b/sdk/communication/azure-communication-identity/swagger/SWAGGER.md new file mode 100644 index 000000000000..1c447dd7884c --- /dev/null +++ b/sdk/communication/azure-communication-identity/swagger/SWAGGER.md @@ -0,0 +1,44 @@ +# Azure Communication Identity for Python + +> see https://aka.ms/autorest + +### Setup +```ps +npm install -g autorest +``` + +### Generation +```ps +cd +autorest ./SWAGGER.md +``` + +### Settings +``` yaml +input-file: https://raw.githubusercontent.com/Azure/azure-rest-api-specs/14bfbf5d0ff8f0dc1358e6e60362e99d0a649ba7/specification/communication/data-plane/Microsoft.CommunicationServicesIdentity/stable/2021-03-07/CommunicationIdentity.json +output-folder: ../azure/communication/identity/_generated/ +namespace: azure.communication.identity +license-header: MICROSOFT_MIT_NO_VERSION +payload-flattening-threshold: 3 +no-namespace-folders: true +clear-output-folder: true +v3: true +python: true +``` + +### Rename CommunicationIdentityAccessToken to CommunicationUserToken + +``` yaml +directive: + - rename-model: + from: CommunicationIdentityAccessToken + to: CommunicationUserToken +``` + +### Rename CommunicationIdentityTokenScope to CommunicationTokenScope +```yaml +directive: + - from: swagger-document + where: $.definitions.CommunicationIdentityTokenScope + transform: > + $["x-ms-enum"].name = "CommunicationTokenScope"; \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/tests/_shared/__init__.py b/sdk/communication/azure-communication-identity/tests/_shared/__init__.py new file mode 100644 index 000000000000..841b812e10ba --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/_shared/__init__.py @@ -0,0 +1,6 @@ +# 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. +# -------------------------------------------------------------------------- \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/tests/_shared/asynctestcase.py b/sdk/communication/azure-communication-identity/tests/_shared/asynctestcase.py new file mode 100644 index 000000000000..197c48e0079b --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/_shared/asynctestcase.py @@ -0,0 +1,27 @@ + +# 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. +# -------------------------------------------------------------------------- +import functools +import asyncio +from azure_devtools.scenario_tests.utilities import trim_kwargs_from_test_function +from .testcase import CommunicationTestCase + +class AsyncCommunicationTestCase(CommunicationTestCase): + + @staticmethod + def await_prepared_test(test_fn): + """Synchronous wrapper for async test methods. Used to avoid making changes + upstream to AbstractPreparer (which doesn't await the functions it wraps) + """ + + @functools.wraps(test_fn) + def run(test_class_instance, *args, **kwargs): + trim_kwargs_from_test_function(test_fn, kwargs) + loop = asyncio.get_event_loop() + return loop.run_until_complete(test_fn(test_class_instance, **kwargs)) + + return run diff --git a/sdk/communication/azure-communication-identity/tests/_shared/communication_service_preparer.py b/sdk/communication/azure-communication-identity/tests/_shared/communication_service_preparer.py new file mode 100644 index 000000000000..e3907ff011e0 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/_shared/communication_service_preparer.py @@ -0,0 +1,89 @@ +# ------------------------------------ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. +# ------------------------------------ + +import datetime + +from azure.mgmt.communication import CommunicationServiceManagementClient +from azure.mgmt.communication.models import CommunicationServiceResource +from devtools_testutils import( + AzureMgmtPreparer, + ResourceGroupPreparer, + FakeResource +) +from devtools_testutils.resource_testcase import RESOURCE_GROUP_PARAM +from azure_devtools.scenario_tests.exceptions import AzureTestError + +class CommunicationServicePreparer(AzureMgmtPreparer): + """Communication Service Preparer. + Creating and destroying test resources on demand + """ + def __init__( + self, + name_prefix="communication", + resource_group_parameter_name=RESOURCE_GROUP_PARAM, + disable_recording=True, + use_cache=False, + playback_fake_resource=None, + client_kwargs=None, + ): + super(CommunicationServicePreparer, self).__init__( + name_prefix, + random_name_length=24, + disable_recording=disable_recording, + playback_fake_resource=playback_fake_resource, + client_kwargs=client_kwargs, + ) + self.resource_group_parameter_name = resource_group_parameter_name + self.random_name_enabled = True + self.service_name = "TEST-SERVICE-NAME" + self.mgmt_client = None + self.set_cache(use_cache) + self.scrubbed_resource_name = "communicationegrcrs" + + def _get_resource_group(self, **kwargs): + try: + return kwargs[self.resource_group_parameter_name] + except KeyError: + template = ( + "To create a communication service a resource group is required. Please add " + "decorator @{} in front of this preparer." + ) + raise AzureTestError(template.format(ResourceGroupPreparer.__name__)) + + def create_resource(self, name, **kwargs): + if not self.is_live: + self.resource = FakeResource(name=self.scrubbed_resource_name, id=name) + + return { + "connection_string": "endpoint=https://{}.communication.azure.com/;accesskey=fake===".format(self.resource.name), + } + + self.test_class_instance.scrubber.register_name_pair(name, self.scrubbed_resource_name) + group_name = self._get_resource_group(**kwargs).name + + self.client = self.create_mgmt_client(CommunicationServiceManagementClient, polling_interval=30) + + self.resource = self.client.communication_service.begin_create_or_update( + group_name, + name, + CommunicationServiceResource(location="global", data_location="UnitedStates") + ).result() + + self.service_name = self.resource.name + + primary_connection_string = self.client.communication_service.list_keys( + group_name, + self.resource.name).primary_connection_string + + return { + "connection_string": primary_connection_string, + } + + def remove_resource(self, name, **kwargs): + if not self.is_live: + return + + group_name = self._get_resource_group(**kwargs).name + self.client.communication_service.begin_delete(group_name, self.service_name).wait() diff --git a/sdk/communication/azure-communication-identity/tests/_shared/helper.py b/sdk/communication/azure-communication-identity/tests/_shared/helper.py new file mode 100644 index 000000000000..7338f10940a0 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/_shared/helper.py @@ -0,0 +1,19 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +from azure_devtools.scenario_tests import RecordingProcessor + +class URIIdentityReplacer(RecordingProcessor): + """Replace the identity in request uri""" + def process_request(self, request): + import re + request.uri = re.sub('/identities/([^/?]+)', '/identities/sanitized', request.uri) + return request + + def process_response(self, response): + import re + if 'url' in response: + response['url'] = re.sub('/identities/([^/?]+)', '/identities/sanitized', response['url']) + return response \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/tests/_shared/testcase.py b/sdk/communication/azure-communication-identity/tests/_shared/testcase.py new file mode 100644 index 000000000000..f56f17e56a46 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/_shared/testcase.py @@ -0,0 +1,69 @@ + +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import re +from devtools_testutils import AzureTestCase +from azure_devtools.scenario_tests import RecordingProcessor, ReplayableTest +from azure_devtools.scenario_tests.utilities import is_text_payload + +class ResponseReplacerProcessor(RecordingProcessor): + def __init__(self, keys=None, replacement="sanitized"): + self._keys = keys if keys else [] + self._replacement = replacement + + def process_response(self, response): + def sanitize_dict(dictionary): + for key in dictionary: + value = dictionary[key] + if isinstance(value, str): + dictionary[key] = re.sub( + r"("+'|'.join(self._keys)+r")", + self._replacement, + dictionary[key]) + elif isinstance(value, dict): + sanitize_dict(value) + + sanitize_dict(response) + + return response + +class BodyReplacerProcessor(RecordingProcessor): + """Sanitize the sensitive info inside request or response bodies""" + + def __init__(self, keys=None, replacement="sanitized"): + self._replacement = replacement + self._keys = keys if keys else [] + + def process_request(self, request): + if is_text_payload(request) and request.body: + request.body = self._replace_keys(request.body.decode()).encode() + + return request + + def process_response(self, response): + if is_text_payload(response) and response['body']['string']: + response['body']['string'] = self._replace_keys(response['body']['string']) + + return response + + def _replace_keys(self, body): + import json + try: + body = json.loads(body) + for key in self._keys: + if key in body: + body[key] = self._replacement + + except (KeyError, ValueError): + return body + + return json.dumps(body) + +class CommunicationTestCase(AzureTestCase): + FILTER_HEADERS = ReplayableTest.FILTER_HEADERS + ['x-azure-ref', 'x-ms-content-sha256', 'location'] + + def __init__(self, method_name, *args, **kwargs): + super(CommunicationTestCase, self).__init__(method_name, *args, **kwargs) \ No newline at end of file diff --git a/sdk/communication/azure-communication-identity/tests/conftest.py b/sdk/communication/azure-communication-identity/tests/conftest.py new file mode 100644 index 000000000000..9f69fcac8bdc --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/conftest.py @@ -0,0 +1,11 @@ +# ------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# -------------------------------------------------------------------------- +import sys + +# Ignore collection of async tests for Python 2 +collect_ignore_glob = [] +if sys.version_info < (3, 5): + collect_ignore_glob.append("*_async.py") diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_create_user.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user.yaml similarity index 55% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_create_user.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user.yaml index c2bc1d2d7dc8..bc64aafcef68 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_create_user.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,34 +9,36 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json Date: - - Tue, 22 Dec 2020 18:26:56 GMT + - Wed, 27 Jan 2021 23:54:39 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:713bd27c-3c73-4c55-a3d2-11c120d32fa8_00000007-e626-e90a-6216-1f3a0d003bb4"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:26:55 GMT + - Wed, 27 Jan 2021 23:54:40 GMT ms-cv: - - 4whAoum970WIzePHLz1Ujg.0 + - V3Rpav/bY0WZnu7vMclLog.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 18ms + - 229ms status: - code: 200 - message: OK + code: 201 + message: Created version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_create_user_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user_from_managed_identity.yaml similarity index 54% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_create_user_from_managed_identity.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user_from_managed_identity.yaml index f159cc5d3c7c..67a09dedbd90 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_create_user_from_managed_identity.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_create_user_from_managed_identity.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,30 +9,32 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:3de2c19f-8f12-45ac-a978-5fe327284a35_00000007-e627-f129-ac00-343a0d00b106"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:28:04 GMT + - Wed, 27 Jan 2021 23:55:48 GMT ms-cv: - - /4JsXqUuEkmQ1v304iaBTw.0 + - iocVB67Og0KRosYwvJnZlg.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 635ms + - 183ms status: - code: 200 - message: OK + code: 201 + message: Created version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_delete_user.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user.yaml similarity index 59% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_delete_user.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user.yaml index 392431b12f89..1feba48bb56c 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_delete_user.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,41 +9,43 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json Date: - - Tue, 22 Dec 2020 18:29:13 GMT + - Wed, 27 Jan 2021 23:56:55 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:b040bbd1-fb13-465b-a547-44c5ff20b980_00000007-e628-f9f8-3ef0-8b3a0d003d3d"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:29:12 GMT + - Wed, 27 Jan 2021 23:56:55 GMT ms-cv: - - UzbbWyNM6Ee4hx1Ym7MwSA.0 + - lv7eyX3+o0SgYHigmvhZNw.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 19ms + - 214ms status: - code: 200 - message: OK + code: 201 + message: Created - request: body: null headers: Accept: - - '*/*' + - application/json Accept-Encoding: - gzip, deflate Connection: @@ -51,27 +53,27 @@ interactions: Content-Length: - '0' Date: - - Tue, 22 Dec 2020 18:29:14 GMT + - Wed, 27 Jan 2021 23:56:55 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' method: DELETE - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07 response: body: string: '' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 date: - - Tue, 22 Dec 2020 18:29:13 GMT + - Wed, 27 Jan 2021 23:56:56 GMT ms-cv: - - bD8oBIuNQEWXEaluFwupbA.0 + - sVJZF/hnPUiFLBDEQt3jnQ.0 strict-transport-security: - max-age=2592000 x-processing-time: - - 764ms + - 777ms status: code: 204 message: No Content diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_delete_user_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user_from_managed_identity.yaml similarity index 58% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_delete_user_from_managed_identity.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user_from_managed_identity.yaml index e1b92837214b..ed23307fa951 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_delete_user_from_managed_identity.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_delete_user_from_managed_identity.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,37 +9,39 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:f050eca7-6baa-4427-966b-21841aa36a78_00000007-e62a-1f3f-8337-3b3a0d009555"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:30:23 GMT + - Wed, 27 Jan 2021 23:58:10 GMT ms-cv: - - eSMH8ZATxUWO5OamG49Wdg.0 + - RivzvSMrYUCxdpIjJOqXeA.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 811ms + - 193ms status: - code: 200 - message: OK + code: 201 + message: Created - request: body: null headers: Accept: - - '*/*' + - application/json Accept-Encoding: - gzip, deflate Connection: @@ -47,23 +49,23 @@ interactions: Content-Length: - '0' User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: DELETE - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07 response: body: string: '' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 date: - - Tue, 22 Dec 2020 18:30:24 GMT + - Wed, 27 Jan 2021 23:58:12 GMT ms-cv: - - 91lJNqPMP0+hZnY0ay0tXA.0 + - akcIQiMeskOt/X1QZdhizg.0 strict-transport-security: - max-age=2592000 x-processing-time: - - 741ms + - 1936ms status: code: 204 message: No Content diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_issue_token.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_issue_token.yaml similarity index 60% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_issue_token.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_issue_token.yaml index 76d30c8ff3e6..dc7bd3bffa92 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_issue_token.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_issue_token.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,36 +9,38 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json Date: - - Tue, 22 Dec 2020 18:31:34 GMT + - Wed, 27 Jan 2021 23:59:18 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:8b7cf66e-98a2-4dc9-b44e-902ad4bd2a83_00000007-e62b-2a03-8d33-3b3a0d00aab4"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:31:32 GMT + - Wed, 27 Jan 2021 23:59:19 GMT ms-cv: - - OXm+S4D9ak+t0Y4jKA3bFA.0 + - svjbdAEx+0CIrvFNZfZTNA.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 24ms + - 20ms status: - code: 200 - message: OK + code: 201 + message: Created - request: body: '{"scopes": ["chat"]}' headers: @@ -53,31 +55,31 @@ interactions: Content-Type: - application/json Date: - - Tue, 22 Dec 2020 18:31:34 GMT + - Wed, 27 Jan 2021 23:59:19 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 response: body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:31:32.3009076+00:00"}' + string: '{"token": "sanitized", "expiresOn": "2021-01-28T23:59:19.164577+00:00"}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:31:32 GMT + - Wed, 27 Jan 2021 23:59:20 GMT ms-cv: - - EArcgkwtPkCU38ZbLjwJEQ.0 + - q/mt/g2JeUiXEsC0OhWXNQ.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 24ms + - 284ms status: code: 200 message: OK diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_issue_token_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_issue_token_from_managed_identity.yaml similarity index 59% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_issue_token_from_managed_identity.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_issue_token_from_managed_identity.yaml index 879ddee12d3c..cbcb125440c8 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_issue_token_from_managed_identity.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_issue_token_from_managed_identity.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,32 +9,34 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:31fd4348-e9dd-4222-ae65-a61c9953759c_00000007-e62c-414b-0e04-343a0d00a745"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:32:41 GMT + - Thu, 28 Jan 2021 00:00:30 GMT ms-cv: - - NcQPodkL5UOzC+AtKJcXvw.0 + - BndpwMRlKkSHkEuCPG7OOw.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 501ms + - 198ms status: - code: 200 - message: OK + code: 201 + message: Created - request: body: '{"scopes": ["chat"]}' headers: @@ -49,27 +51,27 @@ interactions: Content-Type: - application/json User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 response: body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:32:41.3736569+00:00"}' + string: '{"token": "sanitized", "expiresOn": "2021-01-29T00:00:30.7153587+00:00"}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:32:41 GMT + - Thu, 28 Jan 2021 00:00:31 GMT ms-cv: - - W4rjQkxkvUSQqyJk5dUwCA.0 + - Ka0JSro0U0mjBhf0UNLzSg.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 27ms + - 328ms status: code: 200 message: OK diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_revoke_tokens.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_revoke_tokens.yaml similarity index 61% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_revoke_tokens.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_revoke_tokens.yaml index 5e79664fa87f..ecc9db7c4710 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_revoke_tokens.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_revoke_tokens.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,36 +9,38 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json Date: - - Tue, 22 Dec 2020 18:34:17 GMT + - Thu, 28 Jan 2021 00:01:37 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:a83346e4-c8aa-4a33-8993-ef56f44076ba_00000007-e62d-4910-1000-343a0d00b028"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:34:16 GMT + - Thu, 28 Jan 2021 00:01:38 GMT ms-cv: - - ZDSP6Prb6UGYOTBLvb6AdQ.0 + - 3EE+zJXF4kyYK65z0u5AnQ.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 23ms + - 18ms status: - code: 200 - message: OK + code: 201 + message: Created - request: body: '{"scopes": ["chat"]}' headers: @@ -53,69 +55,67 @@ interactions: Content-Type: - application/json Date: - - Tue, 22 Dec 2020 18:34:18 GMT + - Thu, 28 Jan 2021 00:01:38 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 response: body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:34:15.7537392+00:00"}' + string: '{"token": "sanitized", "expiresOn": "2021-01-29T00:01:38.1765422+00:00"}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:34:16 GMT + - Thu, 28 Jan 2021 00:01:39 GMT ms-cv: - - Hmv1R+jifUSsezIU2yJU8Q.0 + - wkhlq8Sb0ES4lAV8LpBBpw.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 31ms + - 277ms status: code: 200 message: OK - request: - body: '{}' + body: null headers: Accept: - - '*/*' + - application/json Accept-Encoding: - gzip, deflate Connection: - keep-alive Content-Length: - - '2' - Content-Type: - - application/merge-patch+json + - '0' Date: - - Tue, 22 Dec 2020 18:34:18 GMT + - Thu, 28 Jan 2021 00:01:38 GMT User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) x-ms-return-client-request-id: - 'true' - method: PATCH - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:revokeAccessTokens?api-version=2021-03-07 response: body: string: '' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 date: - - Tue, 22 Dec 2020 18:34:16 GMT + - Thu, 28 Jan 2021 00:01:39 GMT ms-cv: - - vwznKj2MY0qO9HTJ9YWIRw.0 + - 3+8Tl9kzVUSYp1fxZqKkSA.0 strict-transport-security: - max-age=2592000 x-processing-time: - - 11ms + - 231ms status: code: 204 message: No Content diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_revoke_tokens_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_revoke_tokens_from_managed_identity.yaml similarity index 60% rename from sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_revoke_tokens_from_managed_identity.yaml rename to sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_revoke_tokens_from_managed_identity.yaml index 853de6129c9d..25b2208d7edd 100644 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_communication_identity_client.test_revoke_tokens_from_managed_identity.yaml +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client.test_revoke_tokens_from_managed_identity.yaml @@ -1,6 +1,6 @@ interactions: - request: - body: null + body: '{}' headers: Accept: - application/json @@ -9,32 +9,34 @@ interactions: Connection: - keep-alive Content-Length: - - '0' + - '2' + Content-Type: + - application/json User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: POST - uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 response: body: - string: '{"id": "sanitized"}' + string: '{"identity": {"id": "8:acs:ae743ca9-44ad-417b-9f52-cd0f7714f7f8_00000007-e62e-559c-defd-8b3a0d0026b9"}}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:35:27 GMT + - Thu, 28 Jan 2021 00:02:47 GMT ms-cv: - - QmngflWD+EOVXH7i/FS+iw.0 + - 6bho3IvVN0KiuXQIQuaY4A.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 792ms + - 351ms status: - code: 200 - message: OK + code: 201 + message: Created - request: body: '{"scopes": ["chat"]}' headers: @@ -49,61 +51,59 @@ interactions: Content-Type: - application/json User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) method: POST - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/token?api-version=2020-07-20-preview2 + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 response: body: - string: '{"id": "sanitized", "token": "sanitized", "expiresOn": "2020-12-23T18:35:27.28321+00:00"}' + string: '{"token": "sanitized", "expiresOn": "2021-01-29T00:02:46.9228559+00:00"}' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 content-type: - application/json; charset=utf-8 date: - - Tue, 22 Dec 2020 18:35:27 GMT + - Thu, 28 Jan 2021 00:02:47 GMT ms-cv: - - PRIzOxRVQkycMUEl6WNjHw.0 + - IaJHFvPdF0mpl2c2JVYIzw.0 strict-transport-security: - max-age=2592000 transfer-encoding: - chunked x-processing-time: - - 30ms + - 419ms status: code: 200 message: OK - request: - body: '{}' + body: null headers: Accept: - - '*/*' + - application/json Accept-Encoding: - gzip, deflate Connection: - keep-alive Content-Length: - - '2' - Content-Type: - - application/merge-patch+json + - '0' User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: PATCH - uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2020-07-20-preview2 + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:revokeAccessTokens?api-version=2021-03-07 response: body: string: '' headers: api-supported-versions: - - 2020-01-15-preview3, 2020-07-20-preview1, 2020-07-20-preview2 + - 2020-07-20-preview2, 2021-03-07 date: - - Tue, 22 Dec 2020 18:35:27 GMT + - Thu, 28 Jan 2021 00:02:48 GMT ms-cv: - - mUk2cNSJI0e/Nz7J7yCGYg.0 + - sw69Gh9HzkGQWmbSHeePvQ.0 strict-transport-security: - max-age=2592000 x-processing-time: - - 11ms + - 800ms status: code: 204 message: No Content diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_create_user.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_create_user.yaml new file mode 100644 index 000000000000..f6e055603649 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_create_user.yaml @@ -0,0 +1,34 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + Date: + - Thu, 28 Jan 2021 00:03:54 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:739796df-dcea-4106-b003-57a6e6d2b610_00000007-e62f-6079-defd-8b3a0d0026c2"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:03:55 GMT + ms-cv: PttWnGmR6EmJpoysdPDsDA.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 240ms + status: + code: 201 + message: Created + url: https://communicationx3clgzus2tf.communication.azure.com/identities?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_create_user_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_create_user_from_managed_identity.yaml new file mode 100644 index 000000000000..41b643c8f1d4 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_create_user_from_managed_identity.yaml @@ -0,0 +1,30 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:9c350207-bcd5-45a4-82d3-894441d61f3b_00000007-e630-69b0-a1ab-1d3a0d002d3b"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:05:02 GMT + ms-cv: gGztHo5tZ0S0/LUla6RpUA.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 310ms + status: + code: 201 + message: Created + url: https://communication7ne7szyxrek.communication.azure.com/identities?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_delete_user.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_delete_user.yaml new file mode 100644 index 000000000000..0f3b5ea70644 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_delete_user.yaml @@ -0,0 +1,60 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + Date: + - Thu, 28 Jan 2021 00:06:09 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:0f760253-1d8c-4ac0-b43b-df2d1c43e136_00000007-e631-705c-92fd-8b3a0d004c1d"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:06:10 GMT + ms-cv: CP51xT5ofU2Qf4/8quyvHA.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 207ms + status: + code: 201 + message: Created + url: https://communicationjr4rcjud6dy.communication.azure.com/identities?api-version=2021-03-07 +- request: + body: '' + headers: + Accept: + - application/json + Date: + - Thu, 28 Jan 2021 00:06:10 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: DELETE + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07 + response: + body: + string: '' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + date: Thu, 28 Jan 2021 00:06:11 GMT + ms-cv: PvIFy0Tb7UmwNq2Se6oJhg.0 + strict-transport-security: max-age=2592000 + x-processing-time: 843ms + status: + code: 204 + message: No Content + url: https://communicationjr4rcjud6dy.communication.azure.com/identities/sanitized?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_delete_user_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_delete_user_from_managed_identity.yaml new file mode 100644 index 000000000000..9e48141e976d --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_delete_user_from_managed_identity.yaml @@ -0,0 +1,52 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:a24497f3-efec-4740-a3b5-1fa011bcf80c_00000007-e632-7b36-6032-3b3a0d009e24"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:07:18 GMT + ms-cv: S8lcY4P4/0ufU/ttufqb9A.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 223ms + status: + code: 201 + message: Created + url: https://communicationmp7h7ovhgeo.communication.azure.com/identities?api-version=2021-03-07 +- request: + body: null + headers: + Accept: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: DELETE + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized?api-version=2021-03-07 + response: + body: + string: '' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + date: Thu, 28 Jan 2021 00:07:19 GMT + ms-cv: kATCJqiKOUCRhfHBvexmcA.0 + strict-transport-security: max-age=2592000 + x-processing-time: 432ms + status: + code: 204 + message: No Content + url: https://communicationmp7h7ovhgeo.communication.azure.com/identities/sanitized?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_issue_token.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_issue_token.yaml new file mode 100644 index 000000000000..0c17f57a3b1b --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_issue_token.yaml @@ -0,0 +1,66 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + Date: + - Thu, 28 Jan 2021 00:08:25 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:26a61a0d-7568-4668-b4af-a50d5e31a3c2_00000007-e633-80ba-8337-3b3a0d00957f"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:08:25 GMT + ms-cv: bgD+YH+iyUq2DCmb3A8xpA.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 18ms + status: + code: 201 + message: Created + url: https://communicationc76ebhgedjy.communication.azure.com/identities?api-version=2021-03-07 +- request: + body: '{"scopes": ["chat"]}' + headers: + Accept: + - application/json + Content-Length: + - '20' + Content-Type: + - application/json + Date: + - Thu, 28 Jan 2021 00:08:25 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 + response: + body: + string: '{"token": "sanitized", "expiresOn": "2021-01-29T00:08:25.6307952+00:00"}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:08:25 GMT + ms-cv: zvXlhCo5B0q+t7sBNEliuQ.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 271ms + status: + code: 200 + message: OK + url: https://communicationc76ebhgedjy.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_issue_token_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_issue_token_from_managed_identity.yaml new file mode 100644 index 000000000000..f7ce02fdc730 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_issue_token_from_managed_identity.yaml @@ -0,0 +1,58 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:eb4d4339-97ec-4d4d-838f-3535e5be22fb_00000007-e634-8c53-1000-343a0d00b05d"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:09:33 GMT + ms-cv: aYXgrkUYzkCqrvW6aCFoJg.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 203ms + status: + code: 201 + message: Created + url: https://communicationbro23o5lt3y.communication.azure.com/identities?api-version=2021-03-07 +- request: + body: '{"scopes": ["chat"]}' + headers: + Accept: + - application/json + Content-Length: + - '20' + Content-Type: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 + response: + body: + string: '{"token": "sanitized", "expiresOn": "2021-01-29T00:09:34.3804866+00:00"}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:09:34 GMT + ms-cv: 1xmX6Mokj06NM2PVg6ZuqQ.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 522ms + status: + code: 200 + message: OK + url: https://communicationbro23o5lt3y.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_revoke_tokens.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_revoke_tokens.yaml new file mode 100644 index 000000000000..a75ac24c472c --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_revoke_tokens.yaml @@ -0,0 +1,92 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + Date: + - Thu, 28 Jan 2021 00:10:41 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:dfd067fd-fca6-4b13-ab29-9942ccef42de_00000007-e635-948a-0338-3b3a0d00a0b2"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:10:42 GMT + ms-cv: MQOB7hTyHUWG20LRH6jl4A.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 19ms + status: + code: 201 + message: Created + url: https://communication2rjlrpnsekt.communication.azure.com/identities?api-version=2021-03-07 +- request: + body: '{"scopes": ["chat"]}' + headers: + Accept: + - application/json + Content-Length: + - '20' + Content-Type: + - application/json + Date: + - Thu, 28 Jan 2021 00:10:41 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 + response: + body: + string: '{"token": "sanitized", "expiresOn": "2021-01-29T00:10:41.2727745+00:00"}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:10:42 GMT + ms-cv: ewu+XAda5EKtcLG/IUVAqg.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 34ms + status: + code: 200 + message: OK + url: https://communication2rjlrpnsekt.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 +- request: + body: '' + headers: + Accept: + - application/json + Date: + - Thu, 28 Jan 2021 00:10:41 GMT + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + x-ms-return-client-request-id: + - 'true' + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:revokeAccessTokens?api-version=2021-03-07 + response: + body: + string: '' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + date: Thu, 28 Jan 2021 00:10:42 GMT + ms-cv: 73SrLh8Gu0qRA7HwJHhzPA.0 + strict-transport-security: max-age=2592000 + x-processing-time: 326ms + status: + code: 204 + message: No Content + url: https://communication2rjlrpnsekt.communication.azure.com/identities/sanitized/:revokeAccessTokens?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_revoke_tokens_from_managed_identity.yaml b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_revoke_tokens_from_managed_identity.yaml new file mode 100644 index 000000000000..a2e7c57b3452 --- /dev/null +++ b/sdk/communication/azure-communication-identity/tests/recordings/test_communication_identity_client_async.test_revoke_tokens_from_managed_identity.yaml @@ -0,0 +1,80 @@ +interactions: +- request: + body: '{}' + headers: + Accept: + - application/json + Content-Length: + - '2' + Content-Type: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities?api-version=2021-03-07 + response: + body: + string: '{"identity": {"id": "8:acs:27e29eed-ad97-4eb3-a1ce-754ac5f661e3_00000007-e636-9f5d-a1ab-1d3a0d002d81"}}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:11:49 GMT + ms-cv: ai+7GFVaeEKhVOAHICW3uw.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 498ms + status: + code: 201 + message: Created + url: https://communicationrfbn6jmio5t.communication.azure.com/identities?api-version=2021-03-07 +- request: + body: '{"scopes": ["chat"]}' + headers: + Accept: + - application/json + Content-Length: + - '20' + Content-Type: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 + response: + body: + string: '{"token": "sanitized", "expiresOn": "2021-01-29T00:11:49.9423938+00:00"}' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + content-type: application/json; charset=utf-8 + date: Thu, 28 Jan 2021 00:11:50 GMT + ms-cv: V32cSH7R6k+Js2HFOK2/0g.0 + strict-transport-security: max-age=2592000 + transfer-encoding: chunked + x-processing-time: 277ms + status: + code: 200 + message: OK + url: https://communicationrfbn6jmio5t.communication.azure.com/identities/sanitized/:issueAccessToken?api-version=2021-03-07 +- request: + body: null + headers: + Accept: + - application/json + User-Agent: + - azsdk-python-communication-identity/1.0.0b4 Python/3.9.0 (Windows-10-10.0.19041-SP0) + method: POST + uri: https://communicationegrcrs.communication.azure.com/identities/sanitized/:revokeAccessTokens?api-version=2021-03-07 + response: + body: + string: '' + headers: + api-supported-versions: 2020-07-20-preview2, 2021-03-07 + date: Thu, 28 Jan 2021 00:11:50 GMT + ms-cv: 9cuEcfUT3EG/iFHPRteC3Q.0 + strict-transport-security: max-age=2592000 + x-processing-time: 412ms + status: + code: 204 + message: No Content + url: https://communicationrfbn6jmio5t.communication.azure.com/identities/sanitized/:revokeAccessTokens?api-version=2021-03-07 +version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/test_communication_identity_client.py b/sdk/communication/azure-communication-identity/tests/test_communication_identity_client.py similarity index 97% rename from sdk/communication/azure-communication-administration/tests/test_communication_identity_client.py rename to sdk/communication/azure-communication-identity/tests/test_communication_identity_client.py index 9104aae5f915..9fc58152be3c 100644 --- a/sdk/communication/azure-communication-administration/tests/test_communication_identity_client.py +++ b/sdk/communication/azure-communication-identity/tests/test_communication_identity_client.py @@ -5,7 +5,7 @@ # license information. # -------------------------------------------------------------------------- import pytest -from azure.communication.administration import CommunicationIdentityClient +from azure.communication.identity import CommunicationIdentityClient from azure.core.credentials import AccessToken from _shared.helper import URIIdentityReplacer from _shared.testcase import ( @@ -15,7 +15,7 @@ from devtools_testutils import ResourceGroupPreparer from _shared.communication_service_preparer import CommunicationServicePreparer from azure.identity import DefaultAzureCredential -from azure.communication.administration._shared.utils import parse_connection_str +from azure.communication.identity._shared.utils import parse_connection_str class FakeTokenCredential(object): def __init__(self): diff --git a/sdk/communication/azure-communication-administration/tests/test_communication_identity_client_async.py b/sdk/communication/azure-communication-identity/tests/test_communication_identity_client_async.py similarity index 97% rename from sdk/communication/azure-communication-administration/tests/test_communication_identity_client_async.py rename to sdk/communication/azure-communication-identity/tests/test_communication_identity_client_async.py index a01f92c618ed..0dafc2b5b76c 100644 --- a/sdk/communication/azure-communication-administration/tests/test_communication_identity_client_async.py +++ b/sdk/communication/azure-communication-identity/tests/test_communication_identity_client_async.py @@ -6,8 +6,8 @@ # -------------------------------------------------------------------------- import pytest from azure.core.credentials import AccessToken -from azure.communication.administration.aio import CommunicationIdentityClient -from azure.communication.administration._shared.utils import parse_connection_str +from azure.communication.identity.aio import CommunicationIdentityClient +from azure.communication.identity._shared.utils import parse_connection_str from azure_devtools.scenario_tests import RecordingProcessor from devtools_testutils import ResourceGroupPreparer from _shared.helper import URIIdentityReplacer diff --git a/sdk/communication/azure-communication-administration/tests/user_credential_tests.py b/sdk/communication/azure-communication-identity/tests/user_credential_tests.py similarity index 90% rename from sdk/communication/azure-communication-administration/tests/user_credential_tests.py rename to sdk/communication/azure-communication-identity/tests/user_credential_tests.py index 127e89cd6e31..dddacc8784af 100644 --- a/sdk/communication/azure-communication-administration/tests/user_credential_tests.py +++ b/sdk/communication/azure-communication-identity/tests/user_credential_tests.py @@ -5,9 +5,9 @@ # -------------------------------------------------------------------------- from unittest import TestCase from unittest.mock import MagicMock -from azure.communication.administration._shared.user_credential import CommunicationTokenCredential -from azure.communication.administration._shared.user_token_refresh_options import CommunicationTokenRefreshOptions -from azure.communication.administration._shared.utils import create_access_token +from azure.communication.identity._shared.user_credential import CommunicationTokenCredential +from azure.communication.identity._shared.user_token_refresh_options import CommunicationTokenRefreshOptions +from azure.communication.identity._shared.utils import create_access_token class TestCommunicationTokenCredential(TestCase):