From 00e294c819d8fd9f42cae7badfb3c432e7f6c0c8 Mon Sep 17 00:00:00 2001 From: Bert Ong <823691+beltr0n@users.noreply.github.com> Date: Wed, 3 Feb 2021 18:14:12 -0800 Subject: [PATCH] Revert "[Communication] - Phone Number Management - Added support for AAD auth (#16075)" This reverts commit 1c69e0c7089b57862fa2794dbc8f063fe13b6034. --- .../CHANGELOG.md | 5 ++- .../README.md | 17 ---------- .../_phone_number_administration_client.py | 5 +-- ...hone_number_administration_client_async.py | 5 +-- .../tests/_shared/fake_token_credential.py | 13 ------- .../tests/_shared/utils.py | 14 -------- ...l_phone_numbers_from_managed_identity.yaml | 34 ------------------- ...l_phone_numbers_from_managed_identity.yaml | 25 -------------- ...test_phone_number_administration_client.py | 13 +------ ...hone_number_administration_client_async.py | 16 --------- 10 files changed, 9 insertions(+), 138 deletions(-) delete mode 100644 sdk/communication/azure-communication-administration/tests/_shared/fake_token_credential.py delete mode 100644 sdk/communication/azure-communication-administration/tests/_shared/utils.py delete mode 100644 sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_list_all_phone_numbers_from_managed_identity.yaml delete mode 100644 sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_list_all_phone_numbers_from_managed_identity.yaml diff --git a/sdk/communication/azure-communication-administration/CHANGELOG.md b/sdk/communication/azure-communication-administration/CHANGELOG.md index 63bca17b0a86..3ab815d73c1b 100644 --- a/sdk/communication/azure-communication-administration/CHANGELOG.md +++ b/sdk/communication/azure-communication-administration/CHANGELOG.md @@ -24,10 +24,9 @@ Caller must provide one of the following: - Added `MicrosoftTeamsUserIdentifier` ##### `IdentityClient` -- Added support for Azure Active Directory authentication +- Added support for Azure Active Directory authentication for the Identity client + -#### `PhoneNumberAdministrationClient` -- Added support for Azure Active Directory authentication ## 1.0.0b3 (2020-11-16) ### Breaking Changes diff --git a/sdk/communication/azure-communication-administration/README.md b/sdk/communication/azure-communication-administration/README.md index 9b9ca27c8d5f..4e22a0500161 100644 --- a/sdk/communication/azure-communication-administration/README.md +++ b/sdk/communication/azure-communication-administration/README.md @@ -20,22 +20,6 @@ pip install azure-communication-administration ## CommunicationPhoneNumberClient ### Initializing Phone Number Client -```python -# You can find your endpoint and access token from your resource in the Azure Portal -import os -from azure.communication.administration import PhoneNumberAdministrationClient -from azure.identity import DefaultAzureCredential - -endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT') - -# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have your -# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables. -phone_number_administration_client = PhoneNumberAdministrationClient(endpoint, DefaultAzureCredential()) - -``` -### Initializing Phone Number Client Using Connection String -Connection string authentication is also available for Phone Number Client. - ```python # You can find your endpoint and access token from your resource in the Azure Portal import os @@ -44,7 +28,6 @@ from azure.communication.administration import PhoneNumberAdministrationClient connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') phone_number_administration_client = PhoneNumberAdministrationClient.from_connection_string(connection_str) ``` - ### Phone plans overview Phone plans come in two types; Geographic and Toll-Free. Geographic phone plans are phone plans associated with a location, whose phone numbers' area codes are associated with the area code of a geographic location. Toll-Free phone plans are phone plans not associated location. For example, in the US, toll-free numbers can come with area codes such as 800 or 888. diff --git a/sdk/communication/azure-communication-administration/azure/communication/administration/_phone_number_administration_client.py b/sdk/communication/azure-communication-administration/azure/communication/administration/_phone_number_administration_client.py index d4ac20b2bab3..f34a07d5b0e4 100644 --- a/sdk/communication/azure-communication-administration/azure/communication/administration/_phone_number_administration_client.py +++ b/sdk/communication/azure-communication-administration/azure/communication/administration/_phone_number_administration_client.py @@ -31,7 +31,8 @@ UpdatePhoneNumberCapabilitiesResponse ) -from ._shared.utils import parse_connection_str, get_authentication_policy +from ._shared.utils import parse_connection_str +from ._shared.policy import HMACCredentialsPolicy from ._version import SDK_MONIKER class PhoneNumberAdministrationClient(object): @@ -63,7 +64,7 @@ def __init__( self._endpoint = endpoint self._phone_number_administration_client = PhoneNumberAdministrationClientGen( self._endpoint, - authentication_policy=get_authentication_policy(endpoint, credential), + authentication_policy=HMACCredentialsPolicy(endpoint, credential), sdk_moniker=SDK_MONIKER, **kwargs) 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 86939133891b..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 @@ -38,7 +38,8 @@ UpdatePhoneNumberCapabilitiesResponse ) -from .._shared.utils import parse_connection_str, get_authentication_policy +from .._shared.utils import parse_connection_str +from .._shared.policy import HMACCredentialsPolicy class PhoneNumberAdministrationClient(object): """Azure Communication Services Phone Number Management client. @@ -69,7 +70,7 @@ def __init__( self._endpoint = endpoint self._phone_number_administration_client = PhoneNumberAdministrationClientGen( self._endpoint, - authentication_policy=get_authentication_policy(endpoint, credential, is_async=True), + authentication_policy=HMACCredentialsPolicy(endpoint, credential), sdk_moniker=SDK_MONIKER, **kwargs) diff --git a/sdk/communication/azure-communication-administration/tests/_shared/fake_token_credential.py b/sdk/communication/azure-communication-administration/tests/_shared/fake_token_credential.py deleted file mode 100644 index b4fc2e6eaccf..000000000000 --- a/sdk/communication/azure-communication-administration/tests/_shared/fake_token_credential.py +++ /dev/null @@ -1,13 +0,0 @@ -# ------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# -------------------------------------------------------------------------- -from azure.core.credentials import AccessToken - -class FakeTokenCredential(object): - def __init__(self): - self.token = AccessToken("Fake Token", 0) - - def get_token(self, *args): - return self.token \ No newline at end of file diff --git a/sdk/communication/azure-communication-administration/tests/_shared/utils.py b/sdk/communication/azure-communication-administration/tests/_shared/utils.py deleted file mode 100644 index 4fcf96d313ff..000000000000 --- a/sdk/communication/azure-communication-administration/tests/_shared/utils.py +++ /dev/null @@ -1,14 +0,0 @@ -# ------------------------------------------------------------------------ -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for -# license information. -# ------------------------------------------------------------------------- -from .fake_token_credential import FakeTokenCredential -from azure.identity import DefaultAzureCredential - -def create_token_credential(): - # type: () -> FakeTokenCredential or DefaultAzureCredential - from devtools_testutils import is_live - if not is_live(): - return FakeTokenCredential() - return DefaultAzureCredential() diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_list_all_phone_numbers_from_managed_identity.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_list_all_phone_numbers_from_managed_identity.yaml deleted file mode 100644 index fbfeb1fcc4de..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client.test_list_all_phone_numbers_from_managed_identity.yaml +++ /dev/null @@ -1,34 +0,0 @@ -interactions: -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - User-Agent: - - azsdk-python-communication-administration/1.0.0b4 Python/3.8.5 (Windows-10-10.0.19041-SP0) - method: GET - uri: https://sanitized.communication.azure.com/administration/phonenumbers/phonenumbers?locale=en-US&skip=0&take=100&api-version=2020-07-20-preview1 - response: - body: - string: '{"phoneNumbers": "sanitized", "nextLink": null}' - headers: - content-type: - - application/json; charset=utf-8 - date: - - Thu, 28 Jan 2021 18:48:48 GMT - ms-cv: - - /rMw3sZH40i74G71li+lDA.0 - request-context: - - appId= - transfer-encoding: - - chunked - x-processing-time: - - 1124ms - status: - code: 200 - message: OK -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_list_all_phone_numbers_from_managed_identity.yaml b/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_list_all_phone_numbers_from_managed_identity.yaml deleted file mode 100644 index 4ad1a112d86c..000000000000 --- a/sdk/communication/azure-communication-administration/tests/recordings/test_phone_number_administration_client_async.test_list_all_phone_numbers_from_managed_identity.yaml +++ /dev/null @@ -1,25 +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: GET - uri: https://sanitized.communication.azure.com/administration/phonenumbers/phonenumbers?locale=en-US&skip=0&take=100&api-version=2020-07-20-preview1 - response: - body: - string: '{"phoneNumbers": "sanitized", "nextLink": null}' - headers: - content-type: application/json; charset=utf-8 - date: Thu, 28 Jan 2021 18:49:47 GMT - ms-cv: jqpEP/JsFUKDau9Y0tMhbw.0 - request-context: appId= - transfer-encoding: chunked - x-processing-time: 765ms - status: - code: 200 - message: OK - url: https://sanitized.communication.azure.com/administration/phonenumbers/phonenumbers?locale=en-US&skip=0&take=100&api-version=2020-07-20-preview1 -version: 1 diff --git a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py index 449a70993642..85823a26f162 100644 --- a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py +++ b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client.py @@ -12,17 +12,15 @@ NumberUpdateCapabilities, CreateSearchOptions ) -from azure.core.credentials import AccessToken from phone_number_helper import PhoneNumberUriReplacer from phone_number_testcase import PhoneNumberCommunicationTestCase from _shared.testcase import BodyReplacerProcessor -from _shared.utils import create_token_credential -from azure.communication.administration._shared.utils import parse_connection_str SKIP_PHONE_NUMBER_TESTS = True PHONE_NUMBER_TEST_SKIP_REASON= "Phone Number Administration live tests infra not ready yet" class PhoneNumberAdministrationClientTest(PhoneNumberCommunicationTestCase): + def setUp(self): super(PhoneNumberAdministrationClientTest, self).setUp() self.recording_processors.extend([ @@ -127,15 +125,6 @@ def setUp(self): self.capabilities_id = "capabilities_id" self.release_id = "release_id" - @pytest.mark.live_test_only - @pytest.mark.skipif(SKIP_PHONE_NUMBER_TESTS, reason=PHONE_NUMBER_TEST_SKIP_REASON) - def test_list_all_phone_numbers_from_managed_identity(self): - endpoint, access_key = parse_connection_str(self.connection_str) - credential = create_token_credential() - phone_number_client = PhoneNumberAdministrationClient(endpoint, credential) - pages = phone_number_client.list_all_phone_numbers() - assert pages.next() - @pytest.mark.live_test_only @pytest.mark.skipif(SKIP_PHONE_NUMBER_TESTS, reason=PHONE_NUMBER_TEST_SKIP_REASON) def test_list_all_phone_numbers(self): diff --git a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py index dccf1ae64fc9..43802c4ca8e0 100644 --- a/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py +++ b/sdk/communication/azure-communication-administration/tests/test_phone_number_administration_client_async.py @@ -6,7 +6,6 @@ # -------------------------------------------------------------------------- import pytest from azure.communication.administration.aio import PhoneNumberAdministrationClient -from azure.communication.administration._shared.utils import parse_connection_str from azure.communication.administration import ( PstnConfiguration, NumberUpdateCapabilities, @@ -15,7 +14,6 @@ from phone_number_helper import PhoneNumberUriReplacer from phone_number_testcase_async import AsyncPhoneNumberCommunicationTestCase from _shared.testcase import BodyReplacerProcessor, ResponseReplacerProcessor -from _shared.utils import create_token_credential import os SKIP_PHONE_NUMBER_TESTS = True @@ -128,20 +126,6 @@ def setUp(self): self.capabilities_id = "capabilities_id" self.release_id = "release_id" - @AsyncPhoneNumberCommunicationTestCase.await_prepared_test - @pytest.mark.live_test_only - @pytest.mark.skipif(SKIP_PHONE_NUMBER_TESTS, reason=PHONE_NUMBER_TEST_SKIP_REASON) - async def test_list_all_phone_numbers_from_managed_identity(self): - endpoint, access_key = parse_connection_str(self.connection_str) - credential = create_token_credential() - phone_number_client = PhoneNumberAdministrationClient(endpoint, credential) - async with phone_number_client: - pages = phone_number_client.list_all_phone_numbers() - items = [] - async for item in pages: - items.append(item) - assert len(items) > 0 - @AsyncPhoneNumberCommunicationTestCase.await_prepared_test @pytest.mark.live_test_only @pytest.mark.skipif(SKIP_PHONE_NUMBER_TESTS, reason=PHONE_NUMBER_TEST_SKIP_REASON)