Skip to content

Commit 000080f

Browse files
committed
finish storage
1 parent 01b5841 commit 000080f

File tree

67 files changed

+520
-444
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+520
-444
lines changed

Diff for: scripts/devops_tasks/test_run_samples.py

+7
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,13 @@
153153
"sample_abstract_summary.py",
154154
"sample_abstract_summary_async.py",
155155
],
156+
"azure-storage-blob": [
157+
"blob_samples_proxy_configuration.py",
158+
],
159+
"azure-storage-file-datalake": [
160+
"datalake_samples-service.py",
161+
"datalake_samples-service_async.py",
162+
]
156163
}
157164

158165
def run_check_call_with_timeout(

Diff for: sdk/storage/azure-storage-blob/dev_requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
-e ../../core/azure-core
33
-e ../../identity/azure-identity
44
azure-mgmt-storage==20.1.0
5-
aiohttp>=3.0
5+
aiohttp>=3.0
6+
azure-keyvault

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_authentication.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@
1616
USAGE:
1717
python blob_samples_authentication.py
1818
Set the environment variables with your own values before running the sample:
19-
1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account
19+
1) STORAGE_CONNECTION_STRING - the connection string to your storage account
2020
2) OAUTH_STORAGE_ACCOUNT_NAME - the oauth storage account name
21-
3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account
22-
4) AZURE_STORAGE_ACCESS_KEY - the storage account access key
21+
3) STORAGE_ACCOUNT_NAME - the name of the storage account
22+
4) STORAGE_ACCOUNT_KEY - the storage account access key
2323
"""
2424

2525
import os
2626
import sys
2727

2828
class AuthSamples(object):
2929
url = "https://{}.blob.core.windows.net".format(
30-
os.getenv("AZURE_STORAGE_ACCOUNT_NAME")
30+
os.getenv("STORAGE_ACCOUNT_NAME")
3131
)
3232
oauth_url = "https://{}.blob.core.windows.net".format(
3333
os.getenv("OAUTH_STORAGE_ACCOUNT_NAME")
3434
)
3535

36-
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
37-
shared_access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY")
36+
connection_string = os.getenv("STORAGE_CONNECTION_STRING")
37+
shared_access_key = os.getenv("STORAGE_ACCOUNT_KEY")
3838

3939
def auth_connection_string(self):
4040
if self.connection_string is None:
41-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
41+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
4242
"Test: auth_connection_string")
4343
sys.exit(1)
4444
# [START auth_from_connection_string]
@@ -63,7 +63,7 @@ def auth_connection_string(self):
6363

6464
def auth_shared_key(self):
6565
if self.shared_access_key is None:
66-
print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' +
66+
print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' +
6767
"Test: auth_shared_key")
6868
sys.exit(1)
6969
# [START create_blob_service_client]
@@ -89,7 +89,7 @@ def auth_blob_url(self):
8989

9090
def auth_shared_access_signature(self):
9191
if self.connection_string is None:
92-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
92+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
9393
"Test: auth_shared_access_signature")
9494
sys.exit(1)
9595
# Instantiate a BlobServiceClient using a connection string
@@ -140,4 +140,4 @@ def auth_default_azure_credential(self):
140140
sample.auth_connection_string()
141141
sample.auth_shared_access_signature()
142142
sample.auth_blob_url()
143-
sample.auth_default_azure_credential()
143+
# sample.auth_default_azure_credential()

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_authentication_async.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
USAGE:
1717
python blob_samples_authentication_async.py
1818
Set the environment variables with your own values before running the sample:
19-
1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account
19+
1) STORAGE_CONNECTION_STRING - the connection string to your storage account
2020
2) OAUTH_STORAGE_ACCOUNT_NAME - the oauth storage account name
21-
3) AZURE_STORAGE_ACCOUNT_NAME - the name of the storage account
22-
4) AZURE_STORAGE_ACCESS_KEY - the storage account access key
21+
3) STORAGE_ACCOUNT_NAME - the name of the storage account
22+
4) STORAGE_ACCOUNT_KEY - the storage account access key
2323
"""
2424

2525

@@ -29,18 +29,18 @@
2929

3030
class AuthSamplesAsync(object):
3131
url = "https://{}.blob.core.windows.net".format(
32-
os.getenv("AZURE_STORAGE_ACCOUNT_NAME")
32+
os.getenv("STORAGE_ACCOUNT_NAME")
3333
)
3434
oauth_url = "https://{}.blob.core.windows.net".format(
3535
os.getenv("OAUTH_STORAGE_ACCOUNT_NAME")
3636
)
3737

38-
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
39-
shared_access_key = os.getenv("AZURE_STORAGE_ACCESS_KEY")
38+
connection_string = os.getenv("STORAGE_CONNECTION_STRING")
39+
shared_access_key = os.getenv("STORAGE_ACCOUNT_KEY")
4040

4141
async def auth_connection_string_async(self):
4242
if self.connection_string is None:
43-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
43+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
4444
"Test: auth_connection_string_async")
4545
sys.exit(1)
4646
# [START auth_from_connection_string]
@@ -62,7 +62,7 @@ async def auth_connection_string_async(self):
6262

6363
async def auth_shared_key_async(self):
6464
if self.shared_access_key is None:
65-
print("Missing required environment variable: AZURE_STORAGE_ACCESS_KEY." + '\n' +
65+
print("Missing required environment variable: STORAGE_ACCOUNT_KEY." + '\n' +
6666
"Test: auth_shared_key_async")
6767
sys.exit(1)
6868
# [START create_blob_service_client]
@@ -85,7 +85,7 @@ async def auth_blob_url_async(self):
8585

8686
async def auth_shared_access_signature_async(self):
8787
if self.connection_string is None:
88-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
88+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
8989
"Test: auth_shared_access_signature_async")
9090
sys.exit(1)
9191
# Instantiate a BlobServiceClient using a connection string

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_batch_delete_blobs.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,19 @@
1010
USAGE:
1111
python blob_samples_batch_delete_blobs.py
1212
Set the environment variables with your own values before running the sample:
13-
1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account
13+
1) STORAGE_CONNECTION_STRING - the connection string to your storage account
1414
"""
1515

16-
SOURCE_FOLDER = "./sample-blobs/"
16+
current_dir = os.path.dirname(os.path.abspath(__file__))
17+
SOURCE_FOLDER = os.path.join(current_dir, "./sample-blobs/")
1718

1819

1920
def batch_delete_blobs_sample(local_path):
2021
# Set the connection string and container name values to initialize the Container Client
21-
connection_string = os.getenv('AZURE_STORAGE_CONNECTION_STRING')
22+
connection_string = os.getenv('STORAGE_CONNECTION_STRING')
2223

2324
if connection_string is None:
24-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
25+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
2526
"Test: batch_delete_blobs_sample")
2627
sys.exit(1)
2728

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
This example contains sample code for the KeyWrapper and KeyResolver classes
1414
needed to use Storage client side encryption, as well as code that illustrates
1515
key usage patterns for client side encryption features. This sample expects that
16-
the `AZURE_STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT
16+
the `STORAGE_CONNECTION_STRING` environment variable is set. It SHOULD NOT
1717
be hardcoded in any code derived from this sample.
1818
1919
USAGE: python blob_samples_client_side_encryption.py
2020
Set the environment variables with your own values before running the sample:
21-
1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account
21+
1) STORAGE_CONNECTION_STRING - the connection string to your storage account
2222
"""
2323

2424
import os
@@ -275,9 +275,9 @@ def alternate_key_algorithms(self):
275275
self.container_client.delete_container()
276276

277277
try:
278-
CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING']
278+
CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING']
279279
except KeyError:
280-
print("AZURE_STORAGE_CONNECTION_STRING must be set.")
280+
print("STORAGE_CONNECTION_STRING must be set.")
281281
sys.exit(1)
282282

283283
# Configure max_single_put_size to make blobs in this sample smaller

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_client_side_encryption_keyvault.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
from azure.storage.blob import BlobServiceClient
4242

4343
# Environment variable keys which must be set to run this sample
44-
STORAGE_URL = 'AZURE_STORAGE_ACCOUNT_URL'
45-
KEYVAULT_URL = 'AZURE_KEYVAULT_DNS_NAME'
44+
STORAGE_URL = 'STORAGE_ACCOUNT_BLOB_URL'
45+
KEYVAULT_URL = 'KEYVAULT_URL'
4646
CLIENT_ID = 'ACTIVE_DIRECTORY_APPLICATION_ID'
4747
CLIENT_SECRET = 'ACTIVE_DIRECTORY_APPLICATION_SECRET'
4848
TENANT_ID = 'ACTIVE_DIRECTORY_TENANT_ID'
@@ -93,6 +93,12 @@ def get_kid(self):
9393
credential = DefaultAzureCredential()
9494
secret_client = SecretClient(keyvault_url, credential=credential)
9595

96+
# Generate a random 256-bit key for AES
97+
key = os.urandom(32) # 32 bytes = 256 bits
98+
99+
# Base64 encode the binary key
100+
encoded_key = base64.urlsafe_b64encode(key).decode('utf-8')
101+
secret_client.set_secret(name="symmetric-key", value=encoded_key)
96102
# The secret is url-safe base64 encoded bytes, content type 'application/octet-stream'
97103
secret = secret_client.get_secret('symmetric-key')
98104
key_bytes = base64.urlsafe_b64decode(secret.value)

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_common.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
USAGE:
1515
python blob_samples_common.py
1616
Set the environment variables with your own values before running the sample.
17-
1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account
17+
1) STORAGE_CONNECTION_STRING - the connection string to your storage account
1818
"""
1919

2020
import os
@@ -23,18 +23,19 @@
2323
from azure.core.exceptions import HttpResponseError, ResourceExistsError
2424
from azure.storage.blob import BlobServiceClient
2525

26-
SOURCE_FILE = 'SampleSource.txt'
26+
current_dir = os.path.dirname(os.path.abspath(__file__))
27+
SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt')
2728

2829

2930
class CommonBlobSamples(object):
3031

31-
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
32+
connection_string = os.getenv("STORAGE_CONNECTION_STRING_SOFT")
3233

3334
#--Begin Blob Samples-----------------------------------------------------------------
3435

3536
def blob_snapshots(self):
3637
if self.connection_string is None:
37-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
38+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
3839
"Test: blob_snapshots")
3940
sys.exit(1)
4041

@@ -74,7 +75,7 @@ def blob_snapshots(self):
7475

7576
def soft_delete_and_undelete_blob(self):
7677
if self.connection_string is None:
77-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
78+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
7879
"Test: soft_delete_and_undelete_blob")
7980
sys.exit(1)
8081

@@ -120,7 +121,7 @@ def soft_delete_and_undelete_blob(self):
120121

121122
def delete_multiple_blobs(self):
122123
if self.connection_string is None:
123-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
124+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
124125
"Test: delete_multiple_blobs")
125126
sys.exit(1)
126127
# Instantiate a BlobServiceClient using a connection string
@@ -157,7 +158,7 @@ def delete_multiple_blobs(self):
157158

158159
def acquire_lease_on_blob(self):
159160
if self.connection_string is None:
160-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
161+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
161162
"Test: acquire_lease_on_blob")
162163
sys.exit(1)
163164

@@ -194,7 +195,7 @@ def acquire_lease_on_blob(self):
194195

195196
def start_copy_blob_from_url_and_abort_copy(self):
196197
if self.connection_string is None:
197-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
198+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
198199
"Test: start_copy_blob_from_url_and_abort_copy")
199200
sys.exit(1)
200201
# Instantiate a BlobServiceClient using a connection string

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_common_async.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@
1414
USAGE:
1515
python blob_samples_common_async.py
1616
Set the environment variables with your own values before running the sample.
17-
1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account
17+
1) STORAGE_CONNECTION_STRING - the connection string to your storage account
1818
"""
1919

2020
import os
2121
import sys
2222
import asyncio
2323
from azure.core.exceptions import ResourceExistsError
2424

25-
26-
SOURCE_FILE = './SampleSource.txt'
25+
current_dir = os.path.dirname(os.path.abspath(__file__))
26+
SOURCE_FILE = os.path.join(current_dir, 'SampleSource.txt')
2727

2828

2929
class CommonBlobSamplesAsync(object):
3030

31-
connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
31+
connection_string = os.getenv("STORAGE_CONNECTION_STRING_SOFT")
3232

3333
#--Begin Blob Samples-----------------------------------------------------------------
3434

3535
async def blob_snapshots_async(self):
3636
if self.connection_string is None:
37-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
37+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
3838
"Test: blob_snapshots_async")
3939
sys.exit(1)
4040
# Instantiate a BlobServiceClient using a connection string
@@ -74,7 +74,7 @@ async def blob_snapshots_async(self):
7474

7575
async def soft_delete_and_undelete_blob_async(self):
7676
if self.connection_string is None:
77-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
77+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
7878
"Test: soft_delete_and_undelete_blob_async")
7979
sys.exit(1)
8080
# Instantiate a BlobServiceClient using a connection string
@@ -120,7 +120,7 @@ async def soft_delete_and_undelete_blob_async(self):
120120

121121
async def delete_multiple_blobs_async(self):
122122
if self.connection_string is None:
123-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
123+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
124124
"Test: delete_multiple_blobs_async")
125125
sys.exit(1)
126126
# Instantiate a BlobServiceClient using a connection string
@@ -158,7 +158,7 @@ async def delete_multiple_blobs_async(self):
158158

159159
async def acquire_lease_on_blob_async(self):
160160
if self.connection_string is None:
161-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
161+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
162162
"Test: acquire_lease_on_blob_async")
163163
sys.exit(1)
164164
# Instantiate a BlobServiceClient using a connection string
@@ -195,7 +195,7 @@ async def acquire_lease_on_blob_async(self):
195195

196196
async def start_copy_blob_from_url_and_abort_copy_async(self):
197197
if self.connection_string is None:
198-
print("Missing required environment variable: AZURE_STORAGE_CONNECTION_STRING." + '\n' +
198+
print("Missing required environment variable: STORAGE_CONNECTION_STRING." + '\n' +
199199
"Test: start_copy_blob_from_url_and_abort_copy_async")
200200
sys.exit(1)
201201
# Instantiate a BlobServiceClient using a connection string

Diff for: sdk/storage/azure-storage-blob/samples/blob_samples_container_access_policy.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
DESCRIPTION:
1313
This example shows how to set the container access policy when creating the container
1414
and also how to get the access policy of a container after the container has been
15-
created. This sample expects that the `AZURE_STORAGE_CONNECTION_STRING` environment
15+
created. This sample expects that the `STORAGE_CONNECTION_STRING` environment
1616
variable is set. It SHOULD NOT be hardcoded in any code derived from this sample.
1717
1818
USAGE: python blob_samples_container_access_policy.py
1919
Set the environment variables with your own values before running the sample:
20-
1) AZURE_STORAGE_CONNECTION_STRING - the connection string to your storage account
20+
1) STORAGE_CONNECTION_STRING - the connection string to your storage account
2121
2222
EXAMPLE OUTPUT:
2323
@@ -36,14 +36,14 @@
3636
from azure.storage.blob import AccessPolicy, BlobServiceClient, ContainerSasPermissions, PublicAccess
3737

3838
try:
39-
CONNECTION_STRING = os.environ['AZURE_STORAGE_CONNECTION_STRING']
39+
CONNECTION_STRING = os.environ['STORAGE_CONNECTION_STRING']
4040
except KeyError:
41-
print("AZURE_STORAGE_CONNECTION_STRING must be set.")
41+
print("STORAGE_CONNECTION_STRING must be set.")
4242
sys.exit(1)
4343

4444
def get_and_set_container_access_policy():
4545
service_client = BlobServiceClient.from_connection_string(CONNECTION_STRING)
46-
container_client = service_client.get_container_client("mynewconwertainer")
46+
container_client = service_client.get_container_client("mynewcontaineraccess")
4747

4848
print("\n..Creating container")
4949
container_client.create_container()
@@ -52,7 +52,6 @@ def get_and_set_container_access_policy():
5252
access_policy = AccessPolicy(permission=ContainerSasPermissions(read=True, write=True),
5353
expiry=datetime.utcnow() + timedelta(hours=1),
5454
start=datetime.utcnow() - timedelta(minutes=1))
55-
5655
identifiers = {'read': access_policy}
5756

5857
# Specifies full public read access for container and blob data.

0 commit comments

Comments
 (0)