async def _test_queues_in_account(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( self.connection_string) # [START async_qsc_create_queue] await queue_service.create_queue("asynctestqueue") # [END async_qsc_create_queue] try: # [START async_qsc_list_queues] # List all the queues in the service list_queues = queue_service.list_queues() async for queue in list_queues: print(queue) # List the queues in the service that start with the name "test" list_test_queues = queue_service.list_queues( name_starts_with="test") async for queue in list_test_queues: print(queue) # [END async_qsc_list_queues] finally: # [START async_qsc_delete_queue] await queue_service.delete_queue("asynctestqueue")
async def test_queue_service_properties(self, resource_group, location, storage_account, storage_account_key): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( self.connection_string(storage_account, storage_account_key)) # [START async_set_queue_service_properties] # Create service properties from azure.storage.queue.aio import Logging, Metrics, CorsRule, RetentionPolicy # Create logging settings logging = Logging(read=True, write=True, delete=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Create metrics for requests statistics hour_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) minute_metrics = Metrics(enabled=True, include_apis=True, retention_policy=RetentionPolicy(enabled=True, days=5)) # Create CORS rules cors_rule1 = CorsRule(['www.xyz.com'], ['GET']) allowed_origins = ['www.xyz.com', "www.ab.com", "www.bc.com"] allowed_methods = ['GET', 'PUT'] max_age_in_seconds = 500 exposed_headers = [ "x-ms-meta-data*", "x-ms-meta-source*", "x-ms-meta-abc", "x-ms-meta-bcd" ] allowed_headers = [ "x-ms-meta-data*", "x-ms-meta-target*", "x-ms-meta-xyz", "x-ms-meta-foo" ] cors_rule2 = CorsRule(allowed_origins, allowed_methods, max_age_in_seconds=max_age_in_seconds, exposed_headers=exposed_headers, allowed_headers=allowed_headers) cors = [cors_rule1, cors_rule2] # Set the service properties await queue_service.set_service_properties(logging, hour_metrics, minute_metrics, cors) # [END async_set_queue_service_properties] # [START async_get_queue_service_properties] properties = await queue_service.get_service_properties()
async def _test_get_queue_client(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient, QueueClient queue_service = QueueServiceClient.from_connection_string( self.connection_string) # [START async_get_queue_client] # Get the queue client to interact with a specific queue queue = queue_service.get_queue_client("myasyncqueue")
async def create_client_with_connection_string_async(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( conn_str=self.connection_string) # Get queue service properties async with queue_service: properties = await queue_service.get_service_properties()
async def test_get_queue_client(self, resource_group, location, storage_account, storage_account_key): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient, QueueClient queue_service = QueueServiceClient.from_connection_string( self.connection_string(storage_account, storage_account_key)) # [START async_get_queue_client] # Get the queue client to interact with a specific queue queue = queue_service.get_queue_client("myasyncqueue")
async def _test_create_client_with_connection_string(self): # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( self.connection_string, transport=AiohttpTestTransport()) # Get queue service properties properties = await queue_service.get_service_properties() assert properties is not None
async def auth_connection_string(self): # Instantiate a QueueServiceClient using a connection string # [START async_auth_from_connection_string] from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( conn_str=self.connection_string) # [END async_auth_from_connection_string] # Get information for the Queue Service properties = await queue_service.get_service_properties()
async def test_create_client_with_connection_string(self, resource_group, location, storage_account, storage_account_key): conn_str = self.connection_string(storage_account, storage_account_key) # Instantiate the QueueServiceClient from a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string(conn_str) # Get queue service properties properties = await queue_service.get_service_properties() assert properties is not None
async def _test_auth_connection_string(self): # Instantiate a QueueServiceClient using a connection string # [START auth_from_connection_string] from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( self.connection_string, transport=AiohttpTestTransport()) # [END auth_from_connection_string] # Get information for the Queue Service properties = await queue_service.get_service_properties() assert properties is not None
async def _test_auth_shared_access_signature(self): # Instantiate a QueueServiceClient using a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string(self.connection_string) # Create a SAS token to use for authentication of a client sas_token = queue_service.generate_shared_access_signature( resource_types="object", permission="read", expiry=datetime.utcnow() + timedelta(hours=1) ) assert sas_token is not None
async def _test_auth_shared_access_signature(self): # SAS URL is calculated from storage key, so this test runs live only if TestMode.need_recording_file(self.test_mode): return # Instantiate a QueueServiceClient using a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( self.connection_string, transport=AiohttpTestTransport()) # Create a SAS token to use for authentication of a client sas_token = queue_service.generate_shared_access_signature( resource_types="object", permission="read", expiry=datetime.utcnow() + timedelta(hours=1)) assert sas_token is not None
async def auth_shared_access_signature(self): # Instantiate a QueueServiceClient using a connection string from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient.from_connection_string( conn_str=self.connection_string) # Create a SAS token to use for authentication of a client from azure.storage.queue import generate_account_sas sas_token = generate_account_sas(queue_service.account_name, queue_service.credential.account_key, resource_types="object", permission="read", expiry=datetime.utcnow() + timedelta(hours=1)) token_auth_queue_service = QueueServiceClient( account_url=self.account_url, credential=sas_token) # Get information for the Queue Service properties = await token_auth_queue_service.get_service_properties()