Skip to content

Commit 19da7a4

Browse files
authored
[Communication] - SDK - Adding feature to make samples run in the pipeline (Azure#18234)
* Adding feature to make samples run in the pipeline * Refactored samples * Refactored sms samples * Ignoring chat samples * Addressed comments * README correction * Readding new lines
1 parent 1b4f510 commit 19da7a4

19 files changed

+72
-38
lines changed

scripts/devops_tasks/test_run_samples.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@
100100
"mgmt_topic_async.py",
101101
"proxy_async.py",
102102
"receive_deferred_message_queue_async.py"
103+
],
104+
"azure-communication-chat": [
105+
"chat_client_sample_async.py",
106+
"chat_client_sample.py",
107+
"chat_thread_client_sample_async.py",
108+
"chat_thread_client_sample.py"
109+
],
110+
"azure-communication-phonenumbers": [
111+
"purchase_phone_number_sample_async.py",
112+
"purchase_phone_number_sample.py",
113+
"release_phone_number_sample_async.py",
114+
"release_phone_number_sample.py"
103115
]
104116
}
105117

sdk/communication/azure-communication-identity/samples/identity_samples.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,18 @@
1414
USAGE:
1515
python identity_samples.py
1616
Set the environment variables with your own values before running the sample:
17-
1) AZURE_COMMUNICATION_SERVICE_ENDPOINT - Communication Service endpoint url
1817
2) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - the connection string in your ACS account
1918
3) AZURE_CLIENT_ID - the client ID of your active directory application
2019
4) AZURE_CLIENT_SECRET - the secret of your active directory application
2120
5) AZURE_TENANT_ID - the tenant ID of your active directory application
2221
"""
2322
import os
23+
from azure.communication.identity._shared.utils import parse_connection_str
2424

2525
class CommunicationIdentityClientSamples(object):
2626

2727
def __init__(self):
2828
self.connection_string = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
29-
self.endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT')
3029
self.client_id = os.getenv('AZURE_CLIENT_ID')
3130
self.client_secret = os.getenv('AZURE_CLIENT_SECRET')
3231
self.tenant_id = os.getenv('AZURE_TENANT_ID')
@@ -39,7 +38,8 @@ def get_token(self):
3938

4039
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
4140
from azure.identity import DefaultAzureCredential
42-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
41+
endpoint, _ = parse_connection_str(self.connection_string)
42+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
4343
else:
4444
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
4545
user = identity_client.create_user()
@@ -55,7 +55,8 @@ def revoke_tokens(self):
5555

5656
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
5757
from azure.identity import DefaultAzureCredential
58-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
58+
endpoint, _ = parse_connection_str(self.connection_string)
59+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
5960
else:
6061
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
6162
user = identity_client.create_user()
@@ -69,7 +70,8 @@ def create_user(self):
6970

7071
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
7172
from azure.identity import DefaultAzureCredential
72-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
73+
endpoint, _ = parse_connection_str(self.connection_string)
74+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
7375
else:
7476
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
7577
print("Creating new user")
@@ -83,7 +85,8 @@ def create_user_and_token(self):
8385
)
8486
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
8587
from azure.identity import DefaultAzureCredential
86-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
88+
endpoint, _ = parse_connection_str(self.connection_string)
89+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
8790
else:
8891
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
8992
print("Creating new user with token")
@@ -96,7 +99,8 @@ def delete_user(self):
9699

97100
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
98101
from azure.identity import DefaultAzureCredential
99-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
102+
endpoint, _ = parse_connection_str(self.connection_string)
103+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
100104
else:
101105
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
102106
user = identity_client.create_user()

sdk/communication/azure-communication-identity/samples/identity_samples_async.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
4) AZURE_CLIENT_SECRET - the secret of your active directory application
2121
5) AZURE_TENANT_ID - the tenant ID of your active directory application
2222
"""
23-
23+
from azure.communication.identity._shared.utils import parse_connection_str
2424
import asyncio
2525
import os
2626

@@ -39,7 +39,8 @@ async def get_token(self):
3939
from azure.communication.identity import CommunicationTokenScope
4040
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
4141
from azure.identity import DefaultAzureCredential
42-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
42+
endpoint, _ = parse_connection_str(self.connection_string)
43+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
4344
else:
4445
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
4546

@@ -54,7 +55,8 @@ async def revoke_tokens(self):
5455
from azure.communication.identity import CommunicationTokenScope
5556
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
5657
from azure.identity import DefaultAzureCredential
57-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
58+
endpoint, _ = parse_connection_str(self.connection_string)
59+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
5860
else:
5961
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
6062

@@ -69,7 +71,8 @@ async def create_user(self):
6971
from azure.communication.identity.aio import CommunicationIdentityClient
7072
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
7173
from azure.identity import DefaultAzureCredential
72-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
74+
endpoint, _ = parse_connection_str(self.connection_string)
75+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
7376
else:
7477
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
7578

@@ -83,7 +86,8 @@ async def create_user_and_token(self):
8386
from azure.communication.identity import CommunicationTokenScope
8487
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
8588
from azure.identity import DefaultAzureCredential
86-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
89+
endpoint, _ = parse_connection_str(self.connection_string)
90+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
8791
else:
8892
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
8993

@@ -97,7 +101,8 @@ async def delete_user(self):
97101
from azure.communication.identity.aio import CommunicationIdentityClient
98102
if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
99103
from azure.identity import DefaultAzureCredential
100-
identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential())
104+
endpoint, _ = parse_connection_str(self.connection_string)
105+
identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
101106
else:
102107
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
103108

sdk/communication/azure-communication-phonenumbers/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ search_result = poller.result()
102102

103103
### Purchase Phone Numbers
104104

105-
The result of your search can be used to purchase the specificied phone numbers. This can be done by passing the `search_id` from the search response to the purchase phone number API.
105+
The result of your search can be used to purchase the specified phone numbers. This can be done by passing the `search_id` from the search response to the purchase phone number API.
106106

107107
```python
108108
purchase_poller = phone_numbers_client.begin_purchase_phone_numbers(

sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_async_sample.py renamed to sdk/communication/azure-communication-phonenumbers/samples/get_purchased_phone_number_sample_async.py

File renamed without changes.

sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_async_sample.py renamed to sdk/communication/azure-communication-phonenumbers/samples/list_purchased_phone_numbers_sample_async.py

File renamed without changes.

sdk/communication/azure-communication-phonenumbers/samples/managed_identity_authentication_sample.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@
1313
USAGE:
1414
python managed_identity_authentication_sample.py
1515
Set the environment variables with your own values before running the sample:
16-
1) AZURE_COMMUNICATION_SERVICE_ENDPOINT - The endpoint of your Azure Communication Service
16+
1) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - The connection string of your Azure Communication Service resource
1717
2) AZURE_CLIENT_ID - The id of your registered Azure Active Directory application
1818
3) AZURE_CLIENT_SECRET - A client secret created for your registered AAD aplication
1919
4) AZURE_TENANT_ID - The tenant in which this application can be found
2020
"""
2121

2222
import os
2323
from azure.communication.phonenumbers import PhoneNumbersClient
24+
from azure.communication.phonenumbers._shared.utils import parse_connection_str
2425
from azure.identity import DefaultAzureCredential
2526

26-
endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT')
27+
connection_str = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')
28+
endpoint, _ = parse_connection_str(connection_str)
2729
phone_numbers_client = PhoneNumbersClient(endpoint, DefaultAzureCredential())
2830

2931
def list_purchased_phone_numbers_using_managed_identity():

sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_async_sample.py renamed to sdk/communication/azure-communication-phonenumbers/samples/purchase_phone_number_sample_async.py

File renamed without changes.

sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_async_sample.py renamed to sdk/communication/azure-communication-phonenumbers/samples/release_phone_number_sample_async.py

File renamed without changes.

sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_async_sample.py renamed to sdk/communication/azure-communication-phonenumbers/samples/search_available_phone_numbers_sample_async.py

File renamed without changes.

0 commit comments

Comments
 (0)