diff --git a/scripts/devops_tasks/test_run_samples.py b/scripts/devops_tasks/test_run_samples.py index d7bd4c35b426..a2021474a56a 100644 --- a/scripts/devops_tasks/test_run_samples.py +++ b/scripts/devops_tasks/test_run_samples.py @@ -153,6 +153,12 @@ "sample_abstract_summary.py", "sample_abstract_summary_async.py", ], + "azure-storage-blob": [ + "blob_samples_proxy_configuration.py", + "blob_samples_container_access_policy.py", + "blob_samples_container_access_policy_async.py", + "blob_samples_client_side_encryption_keyvault.py" + ], } def run_check_call_with_timeout( diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py b/sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py index d532d6aa6d8f..b81b13e5395f 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py @@ -16,10 +16,10 @@ USAGE: python blob_samples_authentication.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account 2) OAUTH_STORAGE_ACCOUNT_NAME - the oauth storage account name - 3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account - 4) AZURE_STORAGE_ACCESS_KEY - the storage account access key + 3) STORAGE_ACCOUNT_NAME - the name of the storage account + 4) STORAGE_ACCOUNT_KEY - the storage account access key """ import os @@ -27,18 +27,18 @@ class AuthSamples(object): url = "https://{}.blob.core.windows.net".format( - os.getenv("AZURE_STORAGE_ACCOUNT_NAME") + os.getenv("STORAGE_ACCOUNT_NAME") ) oauth_url = "https://{}.blob.core.windows.net".format( os.getenv("OAUTH_STORAGE_ACCOUNT_NAME") ) - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") - shared_access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") + shared_access_key = os.getenv("STORAGE_ACCOUNT_KEY") def auth_connection_string(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: auth_connection_string") sys.exit(1) # [START auth_from_connection_string] @@ -63,7 +63,7 @@ def auth_connection_string(self): def auth_shared_key(self): if self.shared_access_key is None: - print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + "Test: auth_shared_key") sys.exit(1) # [START create_blob_service_client] @@ -89,7 +89,7 @@ def auth_blob_url(self): def auth_shared_access_signature(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: auth_shared_access_signature") sys.exit(1) # Instantiate a BlobServiceClient using a connection string diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_authentication_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_authentication_async.py index c9be2ed37050..201583658209 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_authentication_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_authentication_async.py @@ -16,10 +16,10 @@ USAGE: python blob_samples_authentication_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account 2) OAUTH_STORAGE_ACCOUNT_NAME - the oauth storage account name - 3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account - 4) AZURE_STORAGE_ACCESS_KEY - the storage account access key + 3) STORAGE_ACCOUNT_NAME - the name of the storage account + 4) STORAGE_ACCOUNT_KEY - the storage account access key """ @@ -29,18 +29,18 @@ class AuthSamplesAsync(object): url = "https://{}.blob.core.windows.net".format( - os.getenv("AZURE_STORAGE_ACCOUNT_NAME") + os.getenv("STORAGE_ACCOUNT_NAME") ) oauth_url = "https://{}.blob.core.windows.net".format( os.getenv("OAUTH_STORAGE_ACCOUNT_NAME") ) - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") - shared_access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") + shared_access_key = os.getenv("STORAGE_ACCOUNT_KEY") async def auth_connection_string_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: auth_connection_string_async") sys.exit(1) # [START auth_from_connection_string] @@ -62,7 +62,7 @@ async def auth_connection_string_async(self): async def auth_shared_key_async(self): if self.shared_access_key is None: - print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + "Test: auth_shared_key_async") sys.exit(1) # [START create_blob_service_client] @@ -85,7 +85,7 @@ async def auth_blob_url_async(self): async def auth_shared_access_signature_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: auth_shared_access_signature_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_batch_delete_blobs.py b/sdk/storage/azure-storage-blob/samples/blob_samples_batch_delete_blobs.py index 9636cc34023e..73f940ad7ec5 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_batch_delete_blobs.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_batch_delete_blobs.py @@ -10,18 +10,19 @@ USAGE: python blob_samples_batch_delete_blobs.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ -SOURCE_FOLDER = "./sample-blobs/" +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FOLDER = os.path.join(current_dir, "./sample-blobs/") def batch_delete_blobs_sample(local_path): # Set the connection string and container name values to initialize the Container Client - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') if connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: batch_delete_blobs_sample") sys.exit(1) diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption.py b/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption.py index 83a0b386ea00..8b7426793ea7 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption.py @@ -13,12 +13,12 @@ This example contains sample code for the KeyWrapper and KeyResolver classes needed to use Storage client side encryption, as well as code that illustrates key usage patterns for client side encryption features. This sample expects that - the `AZURE_STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT + the `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT be hardcoded in any code derived from this sample. USAGE: python blob_samples_client_side_encryption.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -275,9 +275,9 @@ def alternate_key_algorithms(self): self.container_client.delete_container() try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) # Configure max_single_put_size to make blobs in this sample smaller diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption_keyvault.py b/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption_keyvault.py index f2b6a10bde9b..6fa7898bb734 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption_keyvault.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption_keyvault.py @@ -14,20 +14,16 @@ service for client side encryption, storing and retrieving the key encryption key (kek) from within Azure KeyVault. This sample requires a service principal be set configured with access to KeyVault, and that the vault contains a 256-bit base64- - encoded secret named "symmetric-key". Additionally, a number of environment + encoded key named "symmetric-key". Additionally, a number of environment variables, listed below, must be set. Since these often contain sensitive information, they SHOULD NOT be replaced with hardcoded values in any code derived from this sample. USAGE: python blob_samples_client_side_encryption_keyvault.py Set the environment variables with your own values before running the sample: 1) AZURE_STORAGE_ACCOUNT_URL - the storage account url - 2) ACTIVE_DIRECTORY_APPLICATION_ID - Azure Active Directory application ID - 3) ACTIVE_DIRECTORY_APPLICATION_SECRET - Azure Active Directory application secret - 4) ACTIVE_DIRECTORY_TENANT_ID - Azure Active Directory tenant ID - 5) AZURE_KEYVAULT_DNS_NAME: The keyvault account dns name + 2) AZURE_KEYVAULT_DNS_NAME: The keyvault account dns name """ -import base64 import os import sys import uuid @@ -35,17 +31,13 @@ from azure.identity import DefaultAzureCredential from azure.keyvault.keys.crypto import CryptographyClient, KeyWrapAlgorithm -from azure.keyvault.keys import KeyVaultKey, KeyType -from azure.keyvault.secrets import SecretClient +from azure.keyvault.keys import KeyClient from azure.storage.blob import BlobServiceClient # Environment variable keys which must be set to run this sample -STORAGE_URL = 'AZURE_STORAGE_ACCOUNT_URL' -KEYVAULT_URL = 'AZURE_KEYVAULT_DNS_NAME' -CLIENT_ID = 'ACTIVE_DIRECTORY_APPLICATION_ID' -CLIENT_SECRET = 'ACTIVE_DIRECTORY_APPLICATION_SECRET' -TENANT_ID = 'ACTIVE_DIRECTORY_TENANT_ID' +STORAGE_URL = 'STORAGE_ACCOUNT_BLOB_URL' +KEYVAULT_URL = 'KEYVAULT_URL' def get_env_var(key): try: @@ -62,19 +54,19 @@ class KeyWrapper: automatic client-side encyrption and decryption routines. """ def __init__(self, kek, credential): - self.algorithm = KeyWrapAlgorithm.aes_256 + self.algorithm = KeyWrapAlgorithm.rsa_oaep_256 self.kek = kek self.kid = kek.id self.client = CryptographyClient(kek, credential) def wrap_key(self, key): - if self.algorithm != KeyWrapAlgorithm.aes_256: + if self.algorithm != KeyWrapAlgorithm.rsa_oaep_256: raise ValueError('Unknown key wrap algorithm. {}'.format(self.algorithm)) wrapped = self.client.wrap_key(key=key, algorithm=self.algorithm) return wrapped.encrypted_key def unwrap_key(self, key, _): - if self.algorithm != KeyWrapAlgorithm.aes_256: + if self.algorithm != KeyWrapAlgorithm.rsa_oaep_256: raise ValueError('Unknown key wrap algorithm. {}'.format(self.algorithm)) unwrapped = self.client.unwrap_key(encrypted_key=key, algorithm=self.algorithm) return unwrapped.key @@ -91,12 +83,10 @@ def get_kid(self): # Construct a token credential for use by Storage and KeyVault clients. credential = DefaultAzureCredential() -secret_client = SecretClient(keyvault_url, credential=credential) +key_client = KeyClient(keyvault_url, credential=credential) -# The secret is url-safe base64 encoded bytes, content type 'application/octet-stream' -secret = secret_client.get_secret('symmetric-key') -key_bytes = base64.urlsafe_b64decode(secret.value) -kvk = KeyVaultKey(key_id=secret.id, key_ops=['unwrapKey', 'wrapKey'], k=key_bytes, kty=KeyType.oct) +# The key is url-safe base64 encoded bytes +kvk = key_client.create_rsa_key(name="symmetric-key", size=2048, key_operations=["unwrapKey", "wrapKey"]) kek = KeyWrapper(kvk, credential) storage_client = BlobServiceClient(storage_url, credential=credential) diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_common.py b/sdk/storage/azure-storage-blob/samples/blob_samples_common.py index df674ffda1bf..0c4577a6301d 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_common.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_common.py @@ -14,7 +14,7 @@ USAGE: python blob_samples_common.py Set the environment variables with your own values before running the sample. - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -23,18 +23,19 @@ from azure.core.exceptions import HttpResponseError, ResourceExistsError from azure.storage.blob import BlobServiceClient -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt') class CommonBlobSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING_SOFT") #--Begin Blob Samples----------------------------------------------------------------- def blob_snapshots(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: blob_snapshots") sys.exit(1) @@ -74,7 +75,7 @@ def blob_snapshots(self): def soft_delete_and_undelete_blob(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: soft_delete_and_undelete_blob") sys.exit(1) @@ -120,7 +121,7 @@ def soft_delete_and_undelete_blob(self): def delete_multiple_blobs(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: delete_multiple_blobs") sys.exit(1) # Instantiate a BlobServiceClient using a connection string @@ -157,7 +158,7 @@ def delete_multiple_blobs(self): def acquire_lease_on_blob(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: acquire_lease_on_blob") sys.exit(1) @@ -194,7 +195,7 @@ def acquire_lease_on_blob(self): def start_copy_blob_from_url_and_abort_copy(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: start_copy_blob_from_url_and_abort_copy") sys.exit(1) # Instantiate a BlobServiceClient using a connection string diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_common_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_common_async.py index 18f6343d3713..336331fbea18 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_common_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_common_async.py @@ -14,7 +14,7 @@ USAGE: python blob_samples_common_async.py Set the environment variables with your own values before running the sample. - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -22,19 +22,19 @@ import asyncio from azure.core.exceptions import ResourceExistsError - -SOURCE_FILE = './SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt') class CommonBlobSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING_SOFT") #--Begin Blob Samples----------------------------------------------------------------- async def blob_snapshots_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: blob_snapshots_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string @@ -74,7 +74,7 @@ async def blob_snapshots_async(self): async def soft_delete_and_undelete_blob_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: soft_delete_and_undelete_blob_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string @@ -120,7 +120,7 @@ async def soft_delete_and_undelete_blob_async(self): async def delete_multiple_blobs_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: delete_multiple_blobs_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string @@ -158,7 +158,7 @@ async def delete_multiple_blobs_async(self): async def acquire_lease_on_blob_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: acquire_lease_on_blob_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string @@ -195,7 +195,7 @@ async def acquire_lease_on_blob_async(self): async def start_copy_blob_from_url_and_abort_copy_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: start_copy_blob_from_url_and_abort_copy_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy.py b/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy.py index c90a8323a128..2cda34fa17ab 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy.py @@ -12,12 +12,12 @@ DESCRIPTION: This example shows how to set the container access policy when creating the container and also how to get the access policy of a container after the container has been - created. This sample expects that the `AZURE_STORAGE_CONNECTION_STRING` environment + created. This sample expects that the `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT be hardcoded in any code derived from this sample. USAGE: python blob_samples_container_access_policy.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account EXAMPLE OUTPUT: @@ -36,14 +36,14 @@ from azure.storage.blob import AccessPolicy, BlobServiceClient, ContainerSasPermissions, PublicAccess try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) def get_and_set_container_access_policy(): service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING) - container_client = service_client.get_container_client("mynewconwertainer") + container_client = service_client.get_container_client("mynewcontaineraccess") print("\n..Creating container") container_client.create_container() @@ -52,7 +52,6 @@ def get_and_set_container_access_policy(): access_policy = AccessPolicy(permission=ContainerSasPermissions(read=True, write=True), expiry=datetime.utcnow() + timedelta(hours=1), start=datetime.utcnow() - timedelta(minutes=1)) - identifiers = {'read': access_policy} # Specifies full public read access for container and blob data. diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy_async.py index 28f23e475ccc..1190465df430 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy_async.py @@ -16,7 +16,7 @@ USAGE: python blob_samples_container_access_policy_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account EXAMPLE OUTPUT: @@ -37,14 +37,14 @@ from azure.storage.blob.aio import BlobServiceClient try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) async def get_and_set_container_access_policy(): service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING) - container_client = service_client.get_container_client("mynewcontainer") + container_client = service_client.get_container_client("mynewcontaineraccessasync") async with service_client: print("\n..Creating container") @@ -52,7 +52,6 @@ async def get_and_set_container_access_policy(): await container_client.create_container() except ResourceExistsError: pass - # Create access policy access_policy = AccessPolicy(permission=ContainerSasPermissions(read=True, write=True), expiry=datetime.utcnow() + timedelta(hours=1), diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_containers.py b/sdk/storage/azure-storage-blob/samples/blob_samples_containers.py index d0127e8a42ab..207124c0c168 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_containers.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_containers.py @@ -14,7 +14,7 @@ USAGE: python blob_samples_container.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -23,18 +23,19 @@ from azure.core.exceptions import ResourceExistsError -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt') class ContainerSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") #--Begin Blob Samples----------------------------------------------------------------- def container_sample(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: container_sample") sys.exit(1) @@ -70,7 +71,7 @@ def container_sample(self): def acquire_lease_on_container(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: acquire_lease_on_container") sys.exit(1) @@ -97,7 +98,7 @@ def acquire_lease_on_container(self): def set_metadata_on_container(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: set_metadata_on_container") sys.exit(1) @@ -129,7 +130,7 @@ def set_metadata_on_container(self): def container_access_policy(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: container_access_policy") sys.exit(1) # Instantiate a BlobServiceClient using a connection string @@ -191,7 +192,7 @@ def container_access_policy(self): def list_blobs_in_container(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: list_blobs_in_container") sys.exit(1) @@ -223,7 +224,7 @@ def list_blobs_in_container(self): def get_blob_client_from_container(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_blob_client_from_container") sys.exit(1) @@ -250,7 +251,7 @@ def get_blob_client_from_container(self): def get_container_client_from_blob_client(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_container_client_from_blob_client") sys.exit(1) # Instantiate a BlobServiceClient using a connection string diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_containers_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_containers_async.py index 2ce2d249a3fe..9517e47ccd64 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_containers_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_containers_async.py @@ -14,7 +14,7 @@ USAGE: python blob_samples_container_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -22,16 +22,17 @@ import asyncio from datetime import datetime, timedelta -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt') class ContainerSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") # --Begin Blob Samples----------------------------------------------------------------- async def container_sample_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: container_sample_async") sys.exit(1) @@ -68,7 +69,7 @@ async def container_sample_async(self): async def acquire_lease_on_container_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: acquire_lease_on_container_async") sys.exit(1) @@ -93,7 +94,7 @@ async def acquire_lease_on_container_async(self): async def set_metadata_on_container_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: set_metadata_on_container_async") sys.exit(1) @@ -126,7 +127,7 @@ async def set_metadata_on_container_async(self): async def container_access_policy_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: container_access_policy_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string @@ -189,7 +190,7 @@ async def container_access_policy_async(self): async def list_blobs_in_container_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: list_blobs_in_container_async") sys.exit(1) @@ -222,7 +223,7 @@ async def list_blobs_in_container_async(self): async def get_blob_client_from_container_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_blob_client_from_container_async") sys.exit(1) @@ -247,7 +248,7 @@ async def get_blob_client_from_container_async(self): async def get_container_client_from_blob_client_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_container_client_from_blob_client_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob.py b/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob.py index f2f03b172fa6..78aea0e6b5fe 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob.py @@ -12,7 +12,7 @@ This sample demos how to copy a blob from a URL. USAGE: python blob_samples_copy_blob.py Set the environment variables with your own values before running the sample. - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -22,15 +22,16 @@ def main(): try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) status = None blob_service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING) source_blob = "https://www.gutenberg.org/files/59466/59466-0.txt" + blob_service_client.create_container('mycontainer') copied_blob = blob_service_client.get_blob_client("mycontainer", '59466-0.txt') # Copy started copied_blob.start_copy_from_url(source_blob) diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob_async.py index dbc291649b54..e8a8802a1776 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_copy_blob_async.py @@ -12,7 +12,7 @@ This sample demos how to copy a blob from a URL. USAGE: python blob_samples_copy_blob_async.py Set the environment variables with your own values before running the sample. - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -23,17 +23,18 @@ async def main(): try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) status = None blob_service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING) async with blob_service_client: source_blob = "https://www.gutenberg.org/files/59466/59466-0.txt" - copied_blob = blob_service_client.get_blob_client("mycontainer", '59466-0.txt') + await blob_service_client.create_container('mycontainerasync') + copied_blob = blob_service_client.get_blob_client("mycontainerasync", '59466-0.txt') # Copy started" await copied_blob.start_copy_from_url(source_blob) for i in range(10): diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface.py b/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface.py index 4c29216a54dd..a100323ee90d 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface.py @@ -17,16 +17,17 @@ To run this sample, provide the name of the storage container to operate on as the script argument (e.g. `python3 directory_interface.py my-container`). - This sample expects that the `AZURE_STORAGE_CONNECTION_STRING` environment + This sample expects that the `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT be hardcoded in any code derived from this sample. USAGE: python blob_samples_directory_interface.py CONTAINER_NAME Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account ''' import os -from azure.storage.blob import BlobServiceClient +from azure.storage.blob import BlobServiceClient, ContainerClient +from azure.core.exceptions import ResourceExistsError class DirectoryClient: def __init__(self, connection_string, container_name): @@ -164,17 +165,17 @@ def rmdir(self, path): import sys try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print('AZURE_STORAGE_CONNECTION_STRING must be set') + print('STORAGE_CONNECTION_STRING must be set') sys.exit(1) +CONTAINER_NAME = "mycontainerdirectory2" +container = ContainerClient.from_connection_string(CONNECTION_STRING, CONTAINER_NAME) try: - CONTAINER_NAME = sys.argv[1] -except IndexError: - print('usage: directory_interface.py CONTAINER_NAME') - print('error: the following arguments are required: CONTAINER_NAME') - sys.exit(1) + container.create_container() +except ResourceExistsError: + print("The specified container already exists.") SAMPLE_DIRS = [ 'cats/calico', diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface_mimetype.py b/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface_mimetype.py index 5bb143de2fcf..e8bee0f0ca62 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface_mimetype.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_directory_interface_mimetype.py @@ -14,7 +14,7 @@ uploading file. (e.g. 'text/html' is set when uploading .html files) USAGE: python blob_samples_directory_interface_mimetype.py CONTAINER_NAME Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account ''' import sys @@ -23,7 +23,8 @@ from blob_samples_directory_interface import DirectoryClient import mimetypes import os -from azure.storage.blob import ContentSettings +from azure.storage.blob import ContentSettings, ContainerClient +from azure.core.exceptions import ResourceExistsError class DirectoryClientEx(DirectoryClient): # overriding upload_file method @@ -40,17 +41,17 @@ def upload_file(self, source, dest): # Sample setup try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print('AZURE_STORAGE_CONNECTION_STRING must be set') + print('STORAGE_CONNECTION_STRING must be set') sys.exit(1) +CONTAINER_NAME = "mycontainerdirectory" +container = ContainerClient.from_connection_string(CONNECTION_STRING, CONTAINER_NAME) try: - CONTAINER_NAME = sys.argv[1] -except IndexError: - print('usage: directory_interface.py CONTAINER_NAME') - print('error: the following arguments are required: CONTAINER_NAME') - sys.exit(1) + container.create_container() +except ResourceExistsError: + print("The specified container already exists.") SAMPLE_DIRS = [ 'cats/calico', diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs.py b/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs.py index 296fcd7e11ba..bf5f2d70475e 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs.py @@ -12,7 +12,7 @@ This sample demos how to enumerate a container and print all blobs. USAGE: python blob_sammples_enumerate_blobs.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -21,14 +21,14 @@ def main(): try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) - container = ContainerClient.from_connection_string(CONNECTION_STRING, container_name="mycontainer") - + container = ContainerClient.from_connection_string(CONNECTION_STRING, container_name="mycontainerenumerate") + container.create_container() blob_list = container.list_blobs() for blob in blob_list: print(blob.name + '\n') diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs_async.py index c0b64657cede..45f4a8187961 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_enumerate_blobs_async.py @@ -12,7 +12,7 @@ This sample demos how to enumerate a container and print all blobs. USAGE: python blob_samples_enumerate_blobs_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -22,13 +22,13 @@ async def main(): try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) - container = ContainerClient.from_connection_string(CONNECTION_STRING, container_name="mycontainer") - + container = ContainerClient.from_connection_string(CONNECTION_STRING, container_name="mycontainerenumerateasync") + await container.create_container() async with container: async for blob in container.list_blobs(): print(blob.name + '\n') diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world.py b/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world.py index a96d9a8d5880..321aeacc45ba 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world.py @@ -13,7 +13,7 @@ a blob using the blob_client. USAGE: python blob_samples_hello_world.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -21,19 +21,20 @@ # set up -SOURCE_FILE = 'SampleSource.txt' -DEST_FILE = 'BlockDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt') +DEST_FILE = os.path.join(current_dir, 'BlockDestination.txt') class BlobSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") #--Begin Blob Samples----------------------------------------------------------------- def create_container_sample(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_container_sample") sys.exit(1) @@ -42,12 +43,11 @@ def create_container_sample(self): blob_service_client = BlobServiceClient.from_connection_string(self.connection_string) # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("mycontainer") + container_client = blob_service_client.get_container_client("mycontainer11") try: # Create new container in the service container_client.create_container() - # List containers in the storage account list_response = blob_service_client.list_containers() @@ -57,7 +57,7 @@ def create_container_sample(self): def block_blob_sample(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: block_blob_sample") sys.exit(1) @@ -66,7 +66,7 @@ def block_blob_sample(self): blob_service_client = BlobServiceClient.from_connection_string(self.connection_string) # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("myblockcontainersync") + container_client = blob_service_client.get_container_client("myblockcontainersync1") try: # Create new Container in the service @@ -97,7 +97,7 @@ def block_blob_sample(self): def stream_block_blob(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: stream_block_blob") sys.exit(1) @@ -109,7 +109,7 @@ def stream_block_blob(self): max_chunk_get_size=1024*1024) # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("containersync") + container_client = blob_service_client.get_container_client("containersync1") # Generate 4MB of data data = b'a'*4*1024*1024 @@ -146,7 +146,7 @@ def stream_block_blob(self): def page_blob_sample(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: page_blob_sample") sys.exit(1) @@ -155,7 +155,7 @@ def page_blob_sample(self): blob_service_client = BlobServiceClient.from_connection_string(self.connection_string) # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("mypagecontainersync") + container_client = blob_service_client.get_container_client("mypagecontainersync1") try: # Create new Container in the Service @@ -182,7 +182,7 @@ def page_blob_sample(self): def append_blob_sample(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: append_blob_sample") sys.exit(1) @@ -191,7 +191,7 @@ def append_blob_sample(self): blob_service_client = BlobServiceClient.from_connection_string(self.connection_string) # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("myappendcontainersync") + container_client = blob_service_client.get_container_client("myappendcontainersync1") try: # Create new Container in the Service diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world_async.py index 0fdff6f7845b..9078b313d7bc 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_hello_world_async.py @@ -13,7 +13,7 @@ a blob using the blob_client. USAGE: python blob_samples_hello_world_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -21,19 +21,20 @@ import asyncio # set up -DEST_FILE = 'BlockDestination.txt' -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt') +DEST_FILE = os.path.join(current_dir, 'BlockDestination.txt') class BlobSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") #--Begin Blob Samples----------------------------------------------------------------- async def create_container_sample_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_container_sample_async") sys.exit(1) @@ -43,7 +44,7 @@ async def create_container_sample_async(self): async with blob_service_client: # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("mycontainerasync") + container_client = blob_service_client.get_container_client("mycontainerasync11") try: # Create new container in the service @@ -53,14 +54,13 @@ async def create_container_sample_async(self): my_containers = [] async for container in blob_service_client.list_containers(): my_containers.append(container) - finally: # Delete the container await container_client.delete_container() async def block_blob_sample_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: block_blob_sample_async") sys.exit(1) @@ -70,7 +70,7 @@ async def block_blob_sample_async(self): async with blob_service_client: # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("myblockcontainerasync") + container_client = blob_service_client.get_container_client("myblockcontainerasync1") try: # Create new Container in the service @@ -102,7 +102,7 @@ async def block_blob_sample_async(self): async def stream_block_blob(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: stream_block_blob_async") sys.exit(1) @@ -116,7 +116,7 @@ async def stream_block_blob(self): async with blob_service_client: # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("containerasync") + container_client = blob_service_client.get_container_client("containerasync1") # Generate 4MB of data data = b'a'*4*1024*1024 @@ -153,7 +153,7 @@ async def stream_block_blob(self): async def page_blob_sample_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: page_blob_sample_async") sys.exit(1) @@ -163,7 +163,7 @@ async def page_blob_sample_async(self): async with blob_service_client: # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("mypagecontainerasync") + container_client = blob_service_client.get_container_client("mypagecontainerasync1") try: # Create new Container in the Service @@ -191,7 +191,7 @@ async def page_blob_sample_async(self): async def append_blob_sample_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: append_blob_sample_async") sys.exit(1) @@ -201,7 +201,7 @@ async def append_blob_sample_async(self): async with blob_service_client: # Instantiate a new ContainerClient - container_client = blob_service_client.get_container_client("myappendcontainerasync") + container_client = blob_service_client.get_container_client("myappendcontainerasync1") try: # Create new Container in the Service diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_network_activity_logging.py b/sdk/storage/azure-storage-blob/samples/blob_samples_network_activity_logging.py index 8d894864d977..4856584c735f 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_network_activity_logging.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_network_activity_logging.py @@ -12,12 +12,12 @@ DESCRIPTION: This example shows how to enable logging to console, using the storage library as an example. This sample expects that the - `AZURE_STORAGE_CONNECTION_STRING` environment variable is set. + `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT be hardcoded in any code derived from this sample. USAGE: python blob_samples_network_activity_logging.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account EXAMPLE OUTPUT: Request with logging enabled and log level set to DEBUG. @@ -36,9 +36,9 @@ # Retrieve connection string from environment variables # and construct a blob service client. -connection_string = os.environ.get('AZURE_STORAGE_CONNECTION_STRING', None) +connection_string = os.environ.get('STORAGE_CONNECTION_STRING', None) if not connection_string: - print('AZURE_STORAGE_CONNECTION_STRING required.') + print('STORAGE_CONNECTION_STRING required.') sys.exit(1) service_client = BlobServiceClient.from_connection_string(connection_string) diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_proxy_configuration.py b/sdk/storage/azure-storage-blob/samples/blob_samples_proxy_configuration.py index b3102918efb5..3676e55c6c9b 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_proxy_configuration.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_proxy_configuration.py @@ -60,4 +60,4 @@ service_client = BlobServiceClient.from_connection_string(connection_string) containers = list(service_client.list_containers(logging_enable=True)) -print("{} containers.".format(len(containers))) +print("{} containers.".format(len(containers))) \ No newline at end of file diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_query.py b/sdk/storage/azure-storage-blob/samples/blob_samples_query.py index 0b1f19e49ba5..b68fac1dcec5 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_query.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_query.py @@ -12,19 +12,21 @@ This sample demos how to read quick query data. USAGE: python blob_samples_query.py Set the environment variables with your own values before running the sample. - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os import sys from azure.storage.blob import BlobServiceClient, DelimitedJsonDialect, DelimitedTextDialect +current_dir = os.path.dirname(os.path.abspath(__file__)) +BASE_FILE = os.path.join(current_dir, './sample-blobs/quick_query.csv') def main(): try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) blob_service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING) @@ -41,7 +43,7 @@ def on_error(error): # upload the csv file blob_client = blob_service_client.get_blob_client(container_name, "csvfile") - with open("./sample-blobs/quick_query.csv", "rb") as stream: + with open(BASE_FILE, "rb") as stream: blob_client.upload_blob(stream, overwrite=True) # select the second column of the csv file diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_service.py b/sdk/storage/azure-storage-blob/samples/blob_samples_service.py index 837ee89e3f4f..02833c736780 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_service.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_service.py @@ -12,7 +12,7 @@ This sample demos basic operations of the blob service client. USAGE: python blob_samples_service.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os import sys @@ -20,11 +20,11 @@ class BlobServiceSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def get_storage_account_information(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_storage_account_information") sys.exit(1) @@ -39,7 +39,7 @@ def get_storage_account_information(self): def blob_service_properties(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: blob_service_properties") sys.exit(1) @@ -73,7 +73,7 @@ def blob_service_properties(self): def blob_service_stats(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: blob_service_stats") sys.exit(1) @@ -87,7 +87,7 @@ def blob_service_stats(self): def container_operations(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: container_operations") sys.exit(1) @@ -127,7 +127,7 @@ def container_operations(self): def get_blob_and_container_clients(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_blob_and_container_clients") sys.exit(1) @@ -162,7 +162,7 @@ def get_blob_and_container_clients(self): def get_blob_service_client_from_container_client(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_blob_service_client_from_container_client") sys.exit(1) diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_service_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_service_async.py index 4915f8f83503..5769eab25afc 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_service_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_service_async.py @@ -12,7 +12,7 @@ This sample demos basic operations of the blob service client. USAGE: python blob_samples_service_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -22,11 +22,11 @@ class BlobServiceSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def get_storage_account_information_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_storage_account_information_async") sys.exit(1) @@ -42,7 +42,7 @@ async def get_storage_account_information_async(self): async def blob_service_properties_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: blob_service_properties_async") sys.exit(1) @@ -77,7 +77,7 @@ async def blob_service_properties_async(self): async def blob_service_stats_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: blob_service_stats_async") sys.exit(1) @@ -92,7 +92,7 @@ async def blob_service_stats_async(self): async def container_operations_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: container_operations_async") sys.exit(1) @@ -139,7 +139,7 @@ async def container_operations_async(self): async def get_blob_and_container_clients_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_blob_and_container_clients_async") sys.exit(1) @@ -180,19 +180,19 @@ async def get_blob_and_container_clients_async(self): async def get_blob_service_client_from_container_client_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_blob_service_client_from_container_client_async") sys.exit(1) # Instantiate a BlobServiceClient using a connection string from azure.storage.blob.aio import ContainerClient - container_client1 = ContainerClient.from_connection_string(self.connection_string, "container") + container_client1 = ContainerClient.from_connection_string(self.connection_string, "containerasync") await container_client1.create_container() # [START get_blob_service_client_from_container_client] blob_service_client = container_client1._get_blob_service_client() print(await blob_service_client.get_service_properties()) - container_client2 = blob_service_client.get_container_client("container") + container_client2 = blob_service_client.get_container_client("containerasync") print(await container_client2.get_container_properties()) await container_client2.delete_container() diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy.py b/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy.py index 09efd04f4128..d2f77ea7cada 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy.py @@ -13,12 +13,12 @@ This example walks the containers and blobs within a storage account, displaying them in a hierarchical structure and, when present, showing the number of snapshots that are available per blob. This sample expects - that the `AZURE_STORAGE_CONNECTION_STRING` environment variable is set. + that the `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT be hardcoded in any code derived from this sample. USAGE: python blob_samples_walk_blob_hierarchy.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account EXAMPLE OUTPUT: @@ -46,9 +46,9 @@ from azure.storage.blob import BlobPrefix try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) def walk_container(client, container): diff --git a/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy_async.py b/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy_async.py index 54e2f78698d5..53e5e37899af 100644 --- a/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy_async.py +++ b/sdk/storage/azure-storage-blob/samples/blob_samples_walk_blob_hierarchy_async.py @@ -13,12 +13,12 @@ This example walks the containers and blobs within a storage account, displaying them in a hierarchical structure and, when present, showing the number of snapshots that are available per blob. This sample expects - that the `AZURE_STORAGE_CONNECTION_STRING` environment variable is set. + that the `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT be hardcoded in any code derived from this sample. USAGE: python blob_samples_walk_blob_hierarchy_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account EXAMPLE OUTPUT: @@ -45,9 +45,9 @@ from azure.storage.blob.aio import BlobServiceClient, BlobPrefix try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("STORAGE_CONNECTION_STRING must be set.") sys.exit(1) async def walk_container(client, container): diff --git a/sdk/storage/azure-storage-file-datalake/samples/README.md b/sdk/storage/azure-storage-file-datalake/samples/README.md index a75e2ac2c40c..ba632c0de043 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/README.md +++ b/sdk/storage/azure-storage-file-datalake/samples/README.md @@ -56,7 +56,7 @@ pip install azure-storage-file-datalake --pre ## Running the samples 1. Open a terminal window and `cd` to the directory that the samples are saved in. -2. Set the environment variables `STORAGE_ACCOUNT_NAME` and `STORAGE_ACCOUNT_KEY` with your own values. +2. Set the environment variables `DATALAKE_STORAGE_ACCOUNT_NAME` and `DATALAKE_STORAGE_ACCOUNT_KEY` with your own values. 3. run the file, eg.`python datalake_samples_upload_download.py` ## Next steps diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control.py index 5299c15c643f..0b0c9960f398 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control.py @@ -13,8 +13,8 @@ USAGE: python datalake_samples_access_control.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import os @@ -77,8 +77,8 @@ def create_file(): def run(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_async.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_async.py index d80661d8f578..3f37c0c6741a 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_async.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_async.py @@ -13,8 +13,8 @@ USAGE: python datalake_samples_access_control_async.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import asyncio @@ -77,9 +77,8 @@ async def create_file(): async def main(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") - + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( "https", diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive.py index 72e7cf6a4140..3b393947e17f 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive.py @@ -13,8 +13,8 @@ USAGE: python datalake_samples_access_control_recursive.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import os @@ -100,8 +100,8 @@ def create_file(): def run(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive_async.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive_async.py index 931e2749ad44..581e7b8a9f24 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive_async.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_access_control_recursive_async.py @@ -13,8 +13,8 @@ USAGE: python datalake_samples_access_control_recursive_async.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import os @@ -102,8 +102,8 @@ async def create_file(): async def main(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( @@ -113,7 +113,7 @@ async def main(): async with service_client: # generate a random name for testing purpose - fs_name = "testfs{}".format(random.randint(1, 1000)) + fs_name = "testfs{}recursiveasync".format(random.randint(1, 1000)) print("Generating a test filesystem named '{}'.".format(fs_name)) # create the filesystem diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory.py index 536141b108db..a8b25790ba03 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory.py @@ -13,8 +13,8 @@ USAGE: python datalake_samples_directory.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import os @@ -85,8 +85,8 @@ def create_file(): def run(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( @@ -95,7 +95,7 @@ def run(): ), credential=account_key) # generate a random name for testing purpose - fs_name = "testfs{}".format(random.randint(1, 1000)) + fs_name = "dicretorytestfs{}".format(random.randint(1, 1000)) print("Generating a test filesystem named '{}'.".format(fs_name)) # create the filesystem diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory_async.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory_async.py index c4502e9feff5..fd7fd1e1dca5 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory_async.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_directory_async.py @@ -13,8 +13,8 @@ USAGE: python datalake_samples_directory_async.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import asyncio @@ -31,7 +31,7 @@ async def directory_sample(filesystem_client): # create a parent directory - dir_name = "testdir" + dir_name = "testdirasync" print("Creating a directory named '{}'.".format(dir_name)) # Create directory from file system client @@ -51,7 +51,7 @@ async def directory_sample(filesystem_client): # rename the directory # [START rename_directory] - new_dir_name = "testdir2" + new_dir_name = "testdir2async" print("Renaming the directory named '{}' to '{}'.".format(dir_name, new_dir_name)) new_directory = await directory_client\ .rename_directory(new_name=directory_client.file_system_name + '/' + new_dir_name) @@ -86,8 +86,8 @@ async def create_file(): async def main(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system.py index 33c2955d10aa..d322da0540c5 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system.py @@ -14,19 +14,20 @@ USAGE: python datalake_samples_file_system.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) DATALAKE_STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os from azure.core.exceptions import ResourceExistsError -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class FileSystemSamples(object): - connection_string = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + connection_string = os.environ['DATALAKE_STORAGE_CONNECTION_STRING'] #--Begin File System Samples----------------------------------------------------------------- diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system_async.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system_async.py index 7ce964edd823..3eb60d6a9862 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system_async.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_file_system_async.py @@ -14,19 +14,20 @@ USAGE: python datalake_samples_file_system_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) DATALAKE_STORAGE_CONNECTION_STRING - the connection string to your storage account """ import asyncio import os from azure.core.exceptions import ResourceExistsError -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class FileSystemSamplesAsync(object): - connection_string = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + connection_string = os.environ['DATALAKE_STORAGE_CONNECTION_STRING'] #--Begin File System Samples----------------------------------------------------------------- @@ -39,7 +40,7 @@ async def file_system_sample(self): async with datalake_service_client: # Instantiate a FileSystemClient - file_system_client = datalake_service_client.get_file_system_client("mynewfilesystems") + file_system_client = datalake_service_client.get_file_system_client("mynewfilesystemsasync") # [END create_file_system_client_from_service] try: @@ -66,7 +67,7 @@ async def acquire_lease_on_file_system(self): async with datalake_service_client: # Instantiate a FileSystemClient - file_system_client = datalake_service_client.get_file_system_client("myleasefilesystem") + file_system_client = datalake_service_client.get_file_system_client("myleasefilesystemasync") # Create new File System try: @@ -90,7 +91,7 @@ async def set_metadata_on_file_system(self): async with datalake_service_client: # Instantiate a FileSystemClient - file_system_client = datalake_service_client.get_file_system_client("mymetadatafilesystemsync") + file_system_client = datalake_service_client.get_file_system_client("mymetadatafilesystemsyncasync") try: # Create new File System @@ -119,7 +120,7 @@ async def list_paths_in_file_system(self): async with datalake_service_client: # Instantiate a FileSystemClient - file_system_client = datalake_service_client.get_file_system_client("mypathfilesystem") + file_system_client = datalake_service_client.get_file_system_client("mypathfilesystemasync") # Create new File System await file_system_client.create_file_system() @@ -150,7 +151,7 @@ async def get_file_client_from_file_system(self): async with datalake_service_client: # Instantiate a FileSystemClient - file_system_client = datalake_service_client.get_file_system_client("myclientfilesystem") + file_system_client = datalake_service_client.get_file_system_client("myclientfilesystemasync") # Create new File System try: @@ -174,7 +175,7 @@ async def get_directory_client_from_file_system(self): async with datalake_service_client: # Instantiate a FileSystemClient - file_system_client = datalake_service_client.get_file_system_client("mydirectoryfilesystem") + file_system_client = datalake_service_client.get_file_system_client("mydirectoryfilesystemasync") # Create new File System try: @@ -193,7 +194,7 @@ async def get_directory_client_from_file_system(self): async def create_file_from_file_system(self): # [START create_file_system_client_from_connection_string] from azure.storage.filedatalake.aio import FileSystemClient - file_system_client = FileSystemClient.from_connection_string(self.connection_string, "filesystemforcreate") + file_system_client = FileSystemClient.from_connection_string(self.connection_string, "filesystemforcreateasync") # [END create_file_system_client_from_connection_string] async with file_system_client: diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client.py index a55396e2bb22..800a38666e75 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client.py @@ -12,12 +12,12 @@ USAGE: python datalake_samples_instantiate_client.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) DATALAKE_STORAGE_CONNECTION_STRING - the connection string to your storage account connection str could be obtained from portal.azure.com your storage account. """ import os -connection_string = os.environ['AZURE_STORAGE_CONNECTION_STRING'] +connection_string = os.environ['DATALAKE_STORAGE_CONNECTION_STRING'] def instantiate_directory_client_from_conn_str(): diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client_async.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client_async.py index b639e2c8d3ab..70c065b4e3f3 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client_async.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_instantiate_client_async.py @@ -12,12 +12,12 @@ USAGE: python datalake_samples_instantiate_client_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) DATALAKE_STORAGE_CONNECTION_STRING - the connection string to your storage account connection str could be obtained from portal.azure.com your storage account. """ import asyncio import os -connection_string = os.environ['AZURE_STORAGE_CONNECTION_STRING'] +connection_string = os.environ['DATALAKE_STORAGE_CONNECTION_STRING'] async def instantiate_directory_client_from_conn_str(): diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_query.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_query.py index 3d9b51ad772c..63862dfb894d 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_query.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_query.py @@ -12,7 +12,7 @@ This sample demos how to read quick query data. USAGE: python datalake_samples_query.py Set the environment variables with your own values before running the sample. - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) DATALAKE_STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os import sys @@ -53,10 +53,10 @@ def main(): try: - CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING'] + CONNECTION_STRING = os.environ['DATALAKE_STORAGE_CONNECTION_STRING'] except KeyError: - print("AZURE_STORAGE_CONNECTION_STRING must be set.") + print("DATALAKE_STORAGE_CONNECTION_STRING must be set.") sys.exit(1) datalake_service_client = DataLakeServiceClient.from_connection_string(CONNECTION_STRING) diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service.py index 47d2cc4a9358..54afa6cd6514 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service.py @@ -18,8 +18,8 @@ USAGE: python datalake_samples_service.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - 2) STORAGE_ACCOUNT_NAME + 1) DATALAKE_STORAGE_CONNECTION_STRING + 2) DATALAKE_STORAGE_ACCOUNT_NAME """ import os @@ -27,8 +27,9 @@ class DataLakeServiceSamples(object): - connection_string = os.environ['AZURE_STORAGE_CONNECTION_STRING'] - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") + connection_string = os.environ['DATALAKE_STORAGE_CONNECTION_STRING'] + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + #--Begin DataLake Service Samples----------------------------------------------------------------- @@ -57,7 +58,7 @@ def data_lake_service_sample(self): # Create file systems # [START create_file_system_from_service_client] - datalake_service_client.create_file_system("filesystem") + datalake_service_client.create_file_system("filesystemservice") # [END create_file_system_from_service_client] file_system_client = datalake_service_client.create_file_system("anotherfilesystem") @@ -96,7 +97,7 @@ def data_lake_service_sample(self): # Delete File Systems # [START delete_file_system_from_service_client] - datalake_service_client.delete_file_system("filesystem") + datalake_service_client.delete_file_system("filesystemservice") # [END delete_file_system_from_service_client] file_system_client.delete_file_system() diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service_async.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service_async.py index c3fa6d8af934..bdc9e35ea6ff 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service_async.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_service_async.py @@ -18,16 +18,15 @@ USAGE: python datalake_samples_service_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - 2) STORAGE_ACCOUNT_NAME + 1) DATALAKE_STORAGE_CONNECTION_STRING + 2) DATALAKE_STORAGE_ACCOUNT_NAME """ import asyncio import os - -connection_string = os.environ['AZURE_STORAGE_CONNECTION_STRING'] -account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") +connection_string = os.environ['DATALAKE_STORAGE_CONNECTION_STRING'] +account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") #--Begin DataLake Service Samples----------------------------------------------------------------- @@ -36,6 +35,8 @@ async def main(): # Instantiate a DataLakeServiceClient using a connection string # [START create_datalake_service_client] from azure.storage.filedatalake.aio import DataLakeServiceClient + from datetime import datetime, timedelta, timezone + datalake_service_client = DataLakeServiceClient.from_connection_string(connection_string) # [END create_datalake_service_client] @@ -44,7 +45,7 @@ async def main(): from azure.identity.aio import DefaultAzureCredential token_credential = DefaultAzureCredential() datalake_service_client = DataLakeServiceClient("https://{}.dfs.core.windows.net".format(account_name), - credential=token_credential) + credential=token_credential) # [END create_datalake_service_client_oauth] async with datalake_service_client: @@ -57,9 +58,9 @@ async def main(): # Create file systems # [START create_file_system_from_service_client] - await datalake_service_client.create_file_system("filesystem") + await datalake_service_client.create_file_system("filesystemasync") # [END create_file_system_from_service_client] - file_system_client = await datalake_service_client.create_file_system("anotherfilesystem") + file_system_client = await datalake_service_client.create_file_system("anotherfilesystemasync") # List file systems # [START list_file_systems] @@ -96,7 +97,7 @@ async def main(): # Delete File Systems # [START delete_file_system_from_service_client] - await datalake_service_client.delete_file_system("filesystem") + await datalake_service_client.delete_file_system("filesystemasync") # [END delete_file_system_from_service_client] await file_system_client.delete_file_system() diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download.py index 52f0122d62b5..8d3d46ea3a75 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download.py @@ -20,8 +20,8 @@ USAGE: python datalake_samples_upload_download.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import os @@ -30,7 +30,8 @@ from azure.storage.filedatalake import ( DataLakeServiceClient, ) -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") def upload_download_sample(filesystem_client): # create a file before writing content to it @@ -99,8 +100,8 @@ def get_random_bytes(size): def run(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( @@ -109,7 +110,7 @@ def run(): ), credential=account_key) # generate a random name for testing purpose - fs_name = "testfs{}".format(random.randint(1, 1000)) + fs_name = "testfs{}download".format(random.randint(1, 1000)) print("Generating a test filesystem named '{}'.".format(fs_name)) # create the filesystem diff --git a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download_async.py b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download_async.py index 4f0d781cfe1d..016df1d6aff2 100644 --- a/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download_async.py +++ b/sdk/storage/azure-storage-file-datalake/samples/datalake_samples_upload_download_async.py @@ -20,8 +20,8 @@ USAGE: python datalake_samples_upload_download_async.py Set the environment variables with your own values before running the sample: - 1) STORAGE_ACCOUNT_NAME - the storage account name - 2) STORAGE_ACCOUNT_KEY - the storage account key + 1) DATALAKE_STORAGE_ACCOUNT_NAME - the storage account name + 2) DATALAKE_STORAGE_ACCOUNT_KEY - the storage account key """ import asyncio import os @@ -30,7 +30,8 @@ from azure.storage.filedatalake.aio import ( DataLakeServiceClient, ) -SOURCE_FILE = 'SampleSource.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") async def upload_download_sample(filesystem_client): # create a file before writing content to it @@ -99,8 +100,8 @@ def get_random_bytes(size): async def main(): - account_name = os.getenv('STORAGE_ACCOUNT_NAME', "") - account_key = os.getenv('STORAGE_ACCOUNT_KEY', "") + account_name = os.getenv('DATALAKE_STORAGE_ACCOUNT_NAME', "") + account_key = os.getenv('DATALAKE_STORAGE_ACCOUNT_KEY', "") # set up the service client with the credentials from the environment variables service_client = DataLakeServiceClient(account_url="{}://{}.dfs.core.windows.net".format( @@ -110,7 +111,7 @@ async def main(): async with service_client: # generate a random name for testing purpose - fs_name = "testfs{}".format(random.randint(1, 1000)) + fs_name = "testfs{}asyncdownload".format(random.randint(1, 1000)) print("Generating a test filesystem named '{}'.".format(fs_name)) # create the filesystem diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py index 213bc6ed1c68..a4eeb424e463 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication.py @@ -19,28 +19,30 @@ python file_samples_authentication.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account - 2) AZURE_STORAGE_ACCOUNT_URL - the queue service account URL - 3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account - 4) AZURE_STORAGE_ACCESS_KEY - the storage account access key + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account + 2) STORAGE_ACCOUNT_FILE_SHARE_URL - the queue service account URL + 3) STORAGE_ACCOUNT_NAME - the name of the storage account + 4) STORAGE_ACCOUNT_KEY - the storage account access key """ import os import sys from datetime import datetime, timedelta +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") class FileAuthSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") - account_url = os.getenv("AZURE_STORAGE_ACCOUNT_URL") - account_name = os.getenv("AZURE_STORAGE_ACCOUNT_NAME") - access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY") + account_url = os.getenv("STORAGE_ACCOUNT_FILE_SHARE_URL") + account_name = os.getenv("STORAGE_ACCOUNT_NAME") + access_key = os.getenv("STORAGE_ACCOUNT_KEY") def authentication_connection_string(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: authentication_connection_string") sys.exit(1) @@ -52,12 +54,12 @@ def authentication_connection_string(self): def authentication_shared_access_key(self): if self.account_url is None: - print("Missing required environment variable: AZURE_STORAGE_ACCOUNT_URL." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + "Test: authentication_shared_access_key") sys.exit(1) if self.access_key is None: - print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + "Test: authentication_shared_access_key") sys.exit(1) @@ -72,17 +74,17 @@ def authentication_shared_access_key(self): def authentication_shared_access_signature(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: authentication_shared_access_signature") sys.exit(1) if self.account_name is None: - print("Missing required environment variable: AZURE_STORAGE_ACCOUNT_NAME." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_NAME." + '\n' + "Test: authentication_shared_access_signature") sys.exit(1) if self.access_key is None: - print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + "Test: authentication_shared_access_signature") sys.exit(1) @@ -105,7 +107,7 @@ def authentication_shared_access_signature(self): def authentication_default_azure_credential(self): if self.account_url is None: - print("Missing required environment variable: AZURE_STORAGE_ACCOUNT_URL." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + "Test: authentication_default_azure_credential") sys.exit(1) @@ -127,8 +129,13 @@ def authentication_default_azure_credential(self): # Only Directory and File operations, and a certain few Share operations, are currently supported for OAuth. # Create a ShareFileClient from the ShareServiceClient. - share_client = share_service_client.get_share_client('myshare') - share_file_client = share_client.get_file_client('mydirectory/myfile') + share_client = share_service_client.get_share_client("myshare") + share_client.create_share() + share_client.create_directory('mydirectory') + directory_client = share_client.get_directory_client('mydirectory') + with open(DEST_FILE, "wb") as data: + directory_client.upload_file('myfile', data=data) + share_file_client = directory_client.get_file_client('myfile') properties = share_file_client.get_file_properties() # [END file_share_oauth] diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_authentication_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication_async.py index db1e4a9acc6a..37cfb1546302 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_authentication_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_authentication_async.py @@ -19,10 +19,10 @@ python file_samples_authentication_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account - 2) AZURE_STORAGE_ACCOUNT_URL - the queue service account URL - 3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account - 4) AZURE_STORAGE_ACCESS_KEY - the storage account access key + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account + 2) STORAGE_ACCOUNT_FILE_SHARE_URL - the queue service account URL + 3) STORAGE_ACCOUNT_NAME - the name of the storage account + 4) STORAGE_ACCOUNT_KEY - the storage account access key """ import asyncio @@ -30,18 +30,20 @@ import sys from datetime import datetime, timedelta +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") class FileAuthSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") - account_url = os.getenv("AZURE_STORAGE_ACCOUNT_URL") - account_name = os.getenv("AZURE_STORAGE_ACCOUNT_NAME") - access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY") + account_url = os.getenv("STORAGE_ACCOUNT_FILE_SHARE_URL") + account_name = os.getenv("STORAGE_ACCOUNT_NAME") + access_key = os.getenv("STORAGE_ACCOUNT_KEY") async def authentication_connection_string_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: authentication_connection_string_async") sys.exit(1) @@ -53,12 +55,12 @@ async def authentication_connection_string_async(self): async def authentication_shared_access_key_async(self): if self.account_url is None: - print("Missing required environment variable: AZURE_STORAGE_ACCOUNT_URL." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + "Test: authentication_shared_access_key_async") sys.exit(1) if self.access_key is None: - print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + "Test: authentication_shared_access_key_async") sys.exit(1) @@ -73,17 +75,17 @@ async def authentication_shared_access_key_async(self): async def authentication_shared_access_signature_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: authentication_shared_access_signature_async") sys.exit(1) if self.account_name is None: - print("Missing required environment variable: AZURE_STORAGE_ACCOUNT_NAME." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_NAME." + '\n' + "Test: authentication_shared_access_signature_async") sys.exit(1) if self.access_key is None: - print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' + "Test: authentication_shared_access_signature_async") sys.exit(1) @@ -104,7 +106,7 @@ async def authentication_shared_access_signature_async(self): async def authentication_default_azure_credential_async(self): if self.account_url is None: - print("Missing required environment variable: AZURE_STORAGE_ACCOUNT_URL." + '\n' + + print("Missing required environment variable: STORAGE_ACCOUNT_FILE_SHARE_URL." + '\n' + "Test: authentication_default_azure_credential_async") sys.exit(1) @@ -123,11 +125,15 @@ async def authentication_default_azure_credential_async(self): # When using a token credential, you MUST also specify a token_intent token_intent='backup' ) - # Only Directory and File operations, and a certain few Share operations, are currently supported for OAuth. # Create a ShareFileClient from the ShareServiceClient. - share_client = share_service_client.get_share_client('myshare') - share_file_client = share_client.get_file_client('mydirectory/myfile') + share_client = share_service_client.get_share_client("myshareasync") + await share_client.create_share() + await share_client.create_directory('mydirectory') + directory_client = share_client.get_directory_client('mydirectory') + with open(DEST_FILE, "wb") as data: + await directory_client.upload_file('myfile', data=data) + share_file_client = directory_client.get_file_client('myfile') properties = await share_file_client.get_file_properties() # [END file_share_oauth] diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_client.py b/sdk/storage/azure-storage-file-share/samples/file_samples_client.py index a138454d3215..98cc9db0a6f3 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_client.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_client.py @@ -17,25 +17,26 @@ python file_samples_client.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account 2) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account """ import os import sys -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class FileSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") - account_name = os.getenv("AZURE_STORAGE_ACCOUNT_NAME") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") + account_name = os.getenv("STORAGE_ACCOUNT_NAME") def simple_file_operations(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: simple_file_operations") sys.exit(1) @@ -81,7 +82,7 @@ def simple_file_operations(self): def copy_file_from_url(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: copy_file_from_url") sys.exit(1) @@ -118,7 +119,7 @@ def copy_file_from_url(self): def acquire_file_lease(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: acquire_file_lease") sys.exit(1) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_client_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_client_async.py index 8e96f7b02720..6b78b23818ea 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_client_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_client_async.py @@ -17,8 +17,8 @@ python file_samples_client_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account - 2) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account + 2) STORAGE_ACCOUNT_NAME - the name of the storage account """ @@ -26,25 +26,25 @@ import os import sys - -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class FileSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") - account_name = os.getenv("AZURE_STORAGE_ACCOUNT_NAME") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") + account_name = os.getenv("STORAGE_ACCOUNT_NAME") async def simple_file_operations_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: simple_file_operations_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "filesamples1") + share = ShareClient.from_connection_string(self.connection_string, "filesamples1async") # Create the share async with share: @@ -85,13 +85,13 @@ async def simple_file_operations_async(self): async def copy_file_from_url_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: copy_file_from_url_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "filesamples2") + share = ShareClient.from_connection_string(self.connection_string, "filesamples2async") # Create the share async with share: @@ -109,7 +109,7 @@ async def copy_file_from_url_async(self): # Build the url from which to copy the file source_url = "https://{}.file.core.windows.net/{}/{}".format( self.account_name, - 'filesamples2', + 'filesamples2async', 'sourcefile' ) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py b/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py index e6068e3075e8..756218476608 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_directory.py @@ -17,23 +17,24 @@ python file_samples_directory.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os import sys -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class DirectorySamples(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') def create_directory_and_file(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_directory_and_file") sys.exit(1) @@ -73,7 +74,7 @@ def create_directory_and_file(self): def create_subdirectory_and_file(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_subdirectory_and_file") sys.exit(1) @@ -122,7 +123,7 @@ def create_subdirectory_and_file(self): def get_subdirectory_client(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_subdirectory_client") sys.exit(1) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py index a64d6985773e..7455d243f40e 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_directory_async.py @@ -17,30 +17,31 @@ python file_samples_directory_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import asyncio import os import sys -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class DirectorySamplesAsync(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') async def create_directory_and_file_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_directory_and_file_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "directorysamples1") + share = ShareClient.from_connection_string(self.connection_string, "directorysamples1async") # Create the share async with share: @@ -75,13 +76,13 @@ async def create_directory_and_file_async(self): async def create_subdirectory_and_file_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_subdirectory_and_file_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "directorysamples2") + share = ShareClient.from_connection_string(self.connection_string, "directorysamples2async") # Create the share async with share: @@ -127,13 +128,13 @@ async def create_subdirectory_and_file_async(self): async def get_subdirectory_client_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_subdirectory_client_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "directorysamples3") + share = ShareClient.from_connection_string(self.connection_string, "directorysamples3async") # Create the share async with share: diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py index 167cc0cf3d43..c8835ddf4a25 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world.py @@ -17,23 +17,24 @@ python file_samples_hello_world.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os import sys -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class HelloWorldSamples(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') def create_client_with_connection_string(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_client_with_connection_string") sys.exit(1) @@ -43,7 +44,7 @@ def create_client_with_connection_string(self): def create_file_share(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_file_share") sys.exit(1) @@ -65,7 +66,7 @@ def create_file_share(self): def upload_a_file_to_share(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: upload_a_file_to_share") sys.exit(1) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py index c925a836f365..7da6919838b9 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_hello_world_async.py @@ -17,24 +17,25 @@ python file_samples_hello_world_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import asyncio import os import sys -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class HelloWorldSamplesAsync(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') async def create_client_with_connection_string_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_client_with_connection_string_async") sys.exit(1) @@ -45,13 +46,13 @@ async def create_client_with_connection_string_async(self): async def create_file_share_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_file_share_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, share_name="helloworld1") + share = ShareClient.from_connection_string(self.connection_string, share_name="helloworld1async") # Create the share async with share: @@ -68,13 +69,13 @@ async def create_file_share_async(self): async def upload_a_file_to_share_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: upload_a_file_to_share_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, share_name='helloworld2') + share = ShareClient.from_connection_string(self.connection_string, share_name='helloworld2async') # Create the share async with share: @@ -86,7 +87,7 @@ async def upload_a_file_to_share_async(self): from azure.storage.fileshare.aio import ShareFileClient file = ShareFileClient.from_connection_string( self.connection_string, - share_name='helloworld2', + share_name='helloworld2async', file_path="myfile") # [END create_file_client] diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_service.py b/sdk/storage/azure-storage-file-share/samples/file_samples_service.py index 0c1a6772eeb1..2fbc65c80774 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_service.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_service.py @@ -18,23 +18,24 @@ python file_samples_service.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os import sys -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class FileShareServiceSamples(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') def file_service_properties(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: file_service_properties") sys.exit(1) @@ -77,7 +78,7 @@ def file_service_properties(self): def list_shares_in_service(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: list_shares_in_service") sys.exit(1) @@ -105,7 +106,7 @@ def list_shares_in_service(self): def get_share_client(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_share_client") sys.exit(1) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py index 7b5a9d7c2d5c..1658aa158b23 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_service_async.py @@ -18,24 +18,25 @@ python file_samples_service_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import asyncio import os import sys -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class FileShareServiceSamplesAsync(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') async def file_service_properties_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: file_service_properties_async") sys.exit(1) @@ -79,7 +80,7 @@ async def file_service_properties_async(self): async def list_shares_in_service_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: list_shares_in_service_async") sys.exit(1) @@ -89,7 +90,7 @@ async def list_shares_in_service_async(self): async with file_service: # [START fsc_create_shares] - await file_service.create_share(share_name="fileshare1") + await file_service.create_share(share_name="fileshare1async") # [END fsc_create_shares] try: # [START fsc_list_shares] @@ -105,12 +106,12 @@ async def list_shares_in_service_async(self): finally: # [START fsc_delete_shares] - await file_service.delete_share(share_name="fileshare1") + await file_service.delete_share(share_name="fileshare1async") # [END fsc_delete_shares] async def get_share_client_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_share_client_async") sys.exit(1) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_share.py b/sdk/storage/azure-storage-file-share/samples/file_samples_share.py index 909f603fa711..21547765cef6 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_share.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_share.py @@ -18,7 +18,7 @@ python file_samples_share.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -26,17 +26,18 @@ from azure.storage.fileshare import ShareAccessTier -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class ShareSamples(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') def create_share_snapshot(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_share_snapshot") sys.exit(1) @@ -59,7 +60,7 @@ def create_share_snapshot(self): def set_share_quota_and_metadata(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: set_share_quota_and_metadata") sys.exit(1) @@ -91,7 +92,7 @@ def set_share_quota_and_metadata(self): def set_share_properties(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: set_share_properties") sys.exit(1) @@ -126,7 +127,7 @@ def set_share_properties(self): def list_directories_and_files(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: list_directories_and_files") sys.exit(1) @@ -156,7 +157,7 @@ def list_directories_and_files(self): def get_directory_or_file_client(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_directory_or_file_client") sys.exit(1) @@ -172,7 +173,7 @@ def get_directory_or_file_client(self): def acquire_share_lease(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: acquire_share_lease") sys.exit(1) diff --git a/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py b/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py index 7ac44df4b936..93aef67615bf 100644 --- a/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py +++ b/sdk/storage/azure-storage-file-share/samples/file_samples_share_async.py @@ -18,7 +18,7 @@ python file_samples_share_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import asyncio @@ -27,23 +27,24 @@ from azure.storage.fileshare import ShareAccessTier -SOURCE_FILE = './SampleSource.txt' -DEST_FILE = './SampleDestination.txt' +current_dir = os.path.dirname(os.path.abspath(__file__)) +DEST_FILE = os.path.join(current_dir, "SampleDestination.txt") +SOURCE_FILE = os.path.join(current_dir, "SampleSource.txt") class ShareSamplesAsync(object): - connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING') + connection_string = os.getenv('STORAGE_CONNECTION_STRING') async def create_share_snapshot_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: create_share_snapshot_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "sharesamples1") + share = ShareClient.from_connection_string(self.connection_string, "sharesamples1async") async with share: # [START create_share] @@ -61,13 +62,13 @@ async def create_share_snapshot_async(self): async def set_share_quota_and_metadata_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: set_share_quota_and_metadata_async") sys.exit(1) # [START create_share_client_from_conn_string] from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "sharesamples2") + share = ShareClient.from_connection_string(self.connection_string, "sharesamples2async") # [END create_share_client_from_conn_string] # Create the share @@ -94,13 +95,13 @@ async def set_share_quota_and_metadata_async(self): async def set_share_properties_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: set_share_properties_async") sys.exit(1) from azure.storage.fileshare.aio import ShareClient - share1 = ShareClient.from_connection_string(self.connection_string, "sharesamples3a") - share2 = ShareClient.from_connection_string(self.connection_string, "sharesamples3b") + share1 = ShareClient.from_connection_string(self.connection_string, "sharesamples3aasync") + share2 = ShareClient.from_connection_string(self.connection_string, "sharesamples3basync") # Create the share async with share1 and share2: @@ -132,13 +133,13 @@ async def set_share_properties_async(self): async def list_directories_and_files_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: list_directories_and_files_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "sharesamples4") + share = ShareClient.from_connection_string(self.connection_string, "sharesamples4async") # Create the share async with share: @@ -165,13 +166,13 @@ async def list_directories_and_files_async(self): async def get_directory_or_file_client_async(self): if self.connection_string is None: - print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' + + print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' + "Test: get_directory_or_file_client_async") sys.exit(1) # Instantiate the ShareClient from a connection string from azure.storage.fileshare.aio import ShareClient - share = ShareClient.from_connection_string(self.connection_string, "sharesamples5") + share = ShareClient.from_connection_string(self.connection_string, "sharesamples5async") # Get the directory client to interact with a specific directory my_dir = share.get_directory_client("dir1") diff --git a/sdk/storage/azure-storage-queue/samples/network_activity_logging.py b/sdk/storage/azure-storage-queue/samples/network_activity_logging.py index a6440ebdf02a..91b36adc2940 100644 --- a/sdk/storage/azure-storage-queue/samples/network_activity_logging.py +++ b/sdk/storage/azure-storage-queue/samples/network_activity_logging.py @@ -12,13 +12,13 @@ DESCRIPTION: This example shows how to enable logging to console, using the storage library as an example. This sample expects that the - `AZURE_STORAGE_CONNECTION_STRING` environment variable is set. + `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT be hardcoded in any code derived from this sample. USAGE: python network_activity_logging.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account EXAMPLE OUTPUT: Request with logging enabled and log level set to DEBUG. @@ -39,9 +39,9 @@ # Retrieve connection string from environment variables # and construct a blob service client. -connection_string = os.environ.get('AZURE_STORAGE_CONNECTION_STRING', None) +connection_string = os.environ.get('STORAGE_CONNECTION_STRING', None) if not connection_string: - print('AZURE_STORAGE_CONNECTION_STRING required.') + print('STORAGE_CONNECTION_STRING required.') sys.exit(1) service_client = QueueServiceClient.from_connection_string(connection_string) @@ -63,6 +63,6 @@ messages = queue_client.peek_messages(max_messages=20, logging_enable=True) for message in messages: try: - print(' Message: {!r}'.format(base64.b64decode(message.content))) - except binascii.Error: + print(' Message: {!r}'.format(base64.b64decode(message.content))) + except (binascii.Error, ValueError) as e: print(' Message: {}'.format(message.content)) diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py index f4ca011bcb5b..c940a627010d 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication.py @@ -19,10 +19,10 @@ python queue_samples_authentication.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account - 2) AZURE_STORAGE_ACCOUNT_URL - the queue service account URL - 3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account - 4) AZURE_STORAGE_ACCESS_KEY - the storage account access key + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account + 2) STORAGE_ACCOUNT_QUEUE_URL - the queue service account URL + 3) STORAGE_ACCOUNT_NAME - the name of the storage account + 4) STORAGE_ACCOUNT_KEY - the storage account access key """ @@ -33,11 +33,10 @@ class QueueAuthSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") - - account_url = os.getenv("AZURE_STORAGE_ACCOUNT_URL") - account_name = os.getenv("AZURE_STORAGE_ACCOUNT_NAME") - access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") + account_url = os.getenv("STORAGE_ACCOUNT_QUEUE_URL") + account_name = os.getenv("STORAGE_ACCOUNT_NAME") + access_key = os.getenv("STORAGE_ACCOUNT_KEY") def authentication_by_connection_string(self): if self.connection_string is None: @@ -79,7 +78,6 @@ def authentication_by_oauth(self): # Get a token credential for authentication from azure.identity import DefaultAzureCredential token_credential = DefaultAzureCredential() - # Instantiate a QueueServiceClient using a token credential from azure.storage.queue import QueueServiceClient queue_service = QueueServiceClient(account_url=self.account_url, credential=token_credential) diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py index 35a13c30b9ee..707e3adf6538 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_authentication_async.py @@ -19,10 +19,10 @@ python queue_samples_authentication_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account - 2) AZURE_STORAGE_ACCOUNT_URL - the queue service account URL - 3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account - 4) AZURE_STORAGE_ACCESS_KEY - the storage account access key + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account + 2) STORAGE_ACCOUNT_QUEUE_URL - the queue service account URL + 3) STORAGE_ACCOUNT_NAME - the name of the storage account + 4) STORAGE_ACCOUNT_KEY - the storage account access key """ @@ -34,12 +34,10 @@ class QueueAuthSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") - - account_url = os.getenv("AZURE_STORAGE_ACCOUNT_URL") - account_name = os.getenv("AZURE_STORAGE_ACCOUNT_NAME") - access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY") - + connection_string = os.getenv("STORAGE_CONNECTION_STRING") + account_url = os.getenv("STORAGE_ACCOUNT_QUEUE_URL") + account_name = os.getenv("STORAGE_ACCOUNT_NAME") + access_key = os.getenv("STORAGE_ACCOUNT_KEY") async def authentication_by_connection_string_async(self): if self.connection_string is None: print("Missing required environment variable(s). Please see specific test for more details." + '\n' + @@ -67,7 +65,6 @@ async def authentication_by_shared_key_async(self): from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient(account_url=self.account_url, credential=self.access_key) # [END async_create_queue_service_client] - # Get information for the Queue Service async with queue_service: properties = await queue_service.get_service_properties() @@ -82,7 +79,6 @@ async def authentication_by_oauth_async(self): # Get a token credential for authentication from azure.identity.aio import DefaultAzureCredential token_credential = DefaultAzureCredential() - # Instantiate a QueueServiceClient using a token credential from azure.storage.queue.aio import QueueServiceClient queue_service = QueueServiceClient(account_url=self.account_url, credential=token_credential) @@ -108,7 +104,6 @@ async def authentication_by_shared_access_signature_async(self): # Create a SAS token to use for authentication of a client from azure.storage.queue import generate_account_sas, ResourceTypes, AccountSasPermissions - sas_token = generate_account_sas( self.account_name, self.access_key, @@ -116,7 +111,6 @@ async def authentication_by_shared_access_signature_async(self): permission=AccountSasPermissions(read=True), 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 diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py index d798563b4e90..3957feee19fc 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world.py @@ -17,17 +17,16 @@ python queue_samples_hello_world.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ - import os import sys class QueueHelloWorldSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def create_client_with_connection_string(self): if self.connection_string is None: diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py index 34aa77894fb2..376826daec81 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_hello_world_async.py @@ -17,7 +17,7 @@ python queue_samples_hello_world_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ @@ -28,7 +28,7 @@ class QueueHelloWorldSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def create_client_with_connection_string_async(self): if self.connection_string is None: @@ -52,7 +52,7 @@ async def queue_and_messages_example_async(self): # Instantiate the QueueClient from a connection string from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(conn_str=self.connection_string, queue_name="myqueue") + queue = QueueClient.from_connection_string(conn_str=self.connection_string, queue_name="asyncmyqueue") async with queue: # Create the queue diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_message.py b/sdk/storage/azure-storage-queue/samples/queue_samples_message.py index 4bc278b616df..c734ce59752a 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_message.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_message.py @@ -19,7 +19,7 @@ python queue_samples_message.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ @@ -30,7 +30,7 @@ class QueueMessageSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def set_access_policy(self): if self.connection_string is None: diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py index c65c5cde245d..884942c15ed0 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_message_async.py @@ -19,7 +19,7 @@ python queue_samples_message_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ from datetime import datetime, timedelta @@ -30,7 +30,7 @@ class QueueMessageSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def set_access_policy_async(self): if self.connection_string is None: @@ -39,7 +39,7 @@ async def set_access_policy_async(self): # [START async_create_queue_client_from_connection_string] from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue1") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync1") if queue.account_name is None: print("Connection string did not provide an account name." + '\n' + "Test: set_access_policy_async") @@ -98,7 +98,7 @@ async def queue_metadata_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue2") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync2") # Create the queue async with queue: @@ -125,7 +125,7 @@ async def send_and_receive_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue3") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync3") # Create the queue async with queue: @@ -173,7 +173,7 @@ async def receive_one_message_from_queue(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue4") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync4") # Create the queue async with queue: @@ -210,7 +210,7 @@ async def delete_and_clear_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue5") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync5") # Create the queue async with queue: @@ -250,7 +250,7 @@ async def peek_messages_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue6") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync6") # Create the queue async with queue: @@ -289,7 +289,7 @@ async def update_message_async(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue7") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync7") # Create the queue async with queue: @@ -323,7 +323,7 @@ async def receive_messages_with_max_messages(self): # Instantiate a queue client from azure.storage.queue.aio import QueueClient - queue = QueueClient.from_connection_string(self.connection_string, "myqueue8") + queue = QueueClient.from_connection_string(self.connection_string, "myqueueasync8") # Create the queue async with queue: diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_service.py b/sdk/storage/azure-storage-queue/samples/queue_samples_service.py index d10c230db526..9905cf3f3067 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_service.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_service.py @@ -17,7 +17,7 @@ python queue_samples_service.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ import os @@ -26,7 +26,7 @@ class QueueServiceSamples(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") def queue_service_properties(self): if self.connection_string is None: @@ -83,7 +83,7 @@ def queues_in_account(self): queue_service = QueueServiceClient.from_connection_string(conn_str=self.connection_string) # [START qsc_create_queue] - queue_service.create_queue("myqueue1") + queue_service.create_queue("myqueueservice1") # [END qsc_create_queue] try: @@ -101,7 +101,7 @@ def queues_in_account(self): finally: # [START qsc_delete_queue] - queue_service.delete_queue("myqueue1") + queue_service.delete_queue("myqueueservice1") # [END qsc_delete_queue] def get_queue_client(self): @@ -115,7 +115,7 @@ def get_queue_client(self): # [START get_queue_client] # Get the queue client to interact with a specific queue - queue = queue_service.get_queue_client(queue="myqueue2") + queue = queue_service.get_queue_client(queue="myqueueservice2") # [END get_queue_client] diff --git a/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py b/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py index b57816180892..b802abc36020 100644 --- a/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py +++ b/sdk/storage/azure-storage-queue/samples/queue_samples_service_async.py @@ -17,7 +17,7 @@ python queue_samples_service_async.py Set the environment variables with your own values before running the sample: - 1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account + 1) STORAGE_CONNECTION_STRING - the connection string to your storage account """ @@ -28,7 +28,7 @@ class QueueServiceSamplesAsync(object): - connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING") + connection_string = os.getenv("STORAGE_CONNECTION_STRING") async def queue_service_properties_async(self): if self.connection_string is None: @@ -87,7 +87,7 @@ async def queues_in_account_async(self): async with queue_service: # [START async_qsc_create_queue] - await queue_service.create_queue("myqueue1") + await queue_service.create_queue("asyncmyqueue1") # [END async_qsc_create_queue] try: @@ -105,7 +105,7 @@ async def queues_in_account_async(self): finally: # [START async_qsc_delete_queue] - await queue_service.delete_queue("myqueue1") + await queue_service.delete_queue("asyncmyqueue1") # [END async_qsc_delete_queue] async def get_queue_client_async(self): @@ -119,7 +119,7 @@ async def get_queue_client_async(self): # [START async_get_queue_client] # Get the queue client to interact with a specific queue - queue = queue_service.get_queue_client(queue="myqueue2") + queue = queue_service.get_queue_client(queue="asyncmyqueue2") # [END async_get_queue_client] diff --git a/sdk/storage/cspell.yaml b/sdk/storage/cspell.yaml new file mode 100644 index 000000000000..c7af8c446eb7 --- /dev/null +++ b/sdk/storage/cspell.yaml @@ -0,0 +1,23 @@ +# This file configures spell checking. Items in "words" were initially populated +# with words that might be spelling errors. Review these words and take +# appropriate action. For more information, see: https://aka.ms/ci-fix#spell-check + +# Spell checking is not case sensitive +# Keep word lists in alphabetical order so the file is easier to manage +version: "0.2" +words: + - dicretorytestfs + - mynewfilesystemsasync + - myleasefilesystemasync + - mymetadatafilesystemsyncasync + - mypathfilesystemasync + - myclientfilesystemasync + - mydirectoryfilesystemasync + - aasync + - basync + - mycontainerdirectory + - recursiveasync + - asyncdownload + - download + - testdir2async + - testdirasync diff --git a/sdk/storage/test-resources.json b/sdk/storage/test-resources.json index d4415295b49e..9997f885ef8b 100644 --- a/sdk/storage/test-resources.json +++ b/sdk/storage/test-resources.json @@ -558,6 +558,30 @@ "STORAGE_ACCOUNT_KEY": { "type": "string", "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), variables('storageApiVersion')).keys[0].value]" + }, + "STORAGE_CONNECTION_STRING": { + "type": "string", + "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('primaryAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('primaryAccountName')), '2023-01-01').keys[0].value, ';EndpointSuffix=', parameters('endpointSuffix'))]" + }, + "STORAGE_CONNECTION_STRING_SOFT": { + "type": "string", + "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('softDeleteAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('softDeleteAccountName')), '2023-01-01').keys[0].value, ';EndpointSuffix=', parameters('endpointSuffix'))]" + }, + "OAUTH_STORAGE_ACCOUNT_NAME": { + "type": "string", + "value": "[variables('primaryAccountName')]" + }, + "STORAGE_ACCOUNT_BLOB_URL": { + "type": "string", + "value": "[format('https://{0}.blob.core.windows.net', variables('primaryAccountName'))]" + }, + "STORAGE_ACCOUNT_QUEUE_URL": { + "type": "string", + "value": "[format('https://{0}.queue.core.windows.net', variables('primaryAccountName'))]" + }, + "STORAGE_ACCOUNT_FILE_SHARE_URL": { + "type": "string", + "value": "[format('https://{0}.file.core.windows.net', variables('primaryAccountName'))]" }, "SECONDARY_STORAGE_ACCOUNT_NAME": { "type": "string", @@ -615,6 +639,10 @@ "type": "string", "value": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('dataLakeAccountName')), variables('storageApiVersion')).keys[0].value]" }, + "DATALAKE_STORAGE_CONNECTION_STRING": { + "type": "string", + "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('dataLakeAccountName'), ';AccountKey=', listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('dataLakeAccountName')), '2023-01-01').keys[0].value, ';EndpointSuffix=', parameters('endpointSuffix'))]" + }, "STORAGE_DATA_LAKE_SOFT_DELETE_ACCOUNT_NAME": { "type": "string", "value": "[variables('dataLakeSoftDeleteAccountName')]" diff --git a/sdk/storage/tests.yml b/sdk/storage/tests.yml index 4c42d78f74c2..f6e25af11bbc 100644 --- a/sdk/storage/tests.yml +++ b/sdk/storage/tests.yml @@ -22,6 +22,7 @@ extends: # Use dedicated storage pool in canadacentral with higher memory capacity - Pool=.*LINUXPOOL.*/azsdk-pool-mms-ubuntu-2004-storage - Pool=.*WINDOWSPOOL.*/azsdk-pool-mms-win-2022-general + - TestSamples=.*/true ${{ if contains(variables['Build.DefinitionName'], 'tests-weekly') }}: MatrixConfigs: - Name: Storage_all_versions_live_test @@ -31,4 +32,4 @@ extends: EnvVars: AZURE_SKIP_LIVE_RECORDING: 'True' AZURE_TEST_RUN_LIVE: 'true' - AZURE_SUBSCRIPTION_ID: $(STORAGE_SUBSCRIPTION_ID) + AZURE_SUBSCRIPTION_ID: $(STORAGE_SUBSCRIPTION_ID) \ No newline at end of file