Skip to content

Commit 88f77c4

Browse files
author
Gorav Singal
committed
Azure changes
Azure changes git url changes git url changes To original changes To original changes Azure changes Azure changes Azure changes Azure changes Update Dockerfile Update azurefs.py Update azurefs.py Updating dependencies Updating dependencies Update Dockerfile Update azurefs.py Minor fixes Minor fixes
1 parent 3c187af commit 88f77c4

File tree

5 files changed

+38
-32
lines changed

5 files changed

+38
-32
lines changed

hubblestack/fileserver/azurefs.py

+34-20
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
from hubblestack.utils.signing import find_wrapf
6161

6262
try:
63-
import azure.storage.common
64-
import azure.storage.blob
63+
from azure.storage.blob import BlobServiceClient
6564
HAS_AZURE = True
6665
except ImportError:
6766
HAS_AZURE = False
@@ -193,7 +192,7 @@ def update():
193192
blob_service = _get_container_service(container)
194193
name = container['container_name']
195194
try:
196-
blob_list = blob_service.list_blobs(name)
195+
blob_list = blob_service.list_blobs()
197196
except Exception as exc:
198197
log.exception('Error occurred fetching blob list for azurefs')
199198

@@ -224,8 +223,14 @@ def update():
224223
log.exception('Problem occurred trying to invalidate cache for container "{0}"'.format(name))
225224
continue
226225

226+
blobs_data = []
227+
for blob in blob_list:
228+
# list_blobs returns an iterator
229+
# and we iterate over it more than once
230+
blobs_data.append(blob)
231+
227232
# Walk the cache directory searching for deletions
228-
blob_names = [blob.name for blob in blob_list]
233+
blob_names = [blob.name for blob in blobs_data]
229234
blob_set = set(blob_names)
230235
for root, dirs, files in os.walk(path):
231236
for f in files:
@@ -240,12 +245,12 @@ def update():
240245
if not dirs and not files:
241246
shutil.rmtree(root)
242247

243-
for blob in blob_list:
248+
for blob in blobs_data:
244249
fname = os.path.join(path, blob.name)
245250
update = False
246251
if os.path.exists(fname):
247252
# File exists, check the hashes
248-
source_md5 = blob.properties.content_settings.content_md5
253+
source_md5 = blob.content_settings.content_md5
249254
local_md5_hex = hubblestack.utils.hashutils.get_hash(fname, 'md5')
250255
local_md5 = base64.b64encode(bytes.fromhex(local_md5_hex))
251256
if local_md5 != source_md5:
@@ -263,7 +268,10 @@ def update():
263268
fp_.write('')
264269

265270
try:
266-
blob_service.get_blob_to_path(name, blob.name, fname)
271+
blob_client = blob_service.get_blob_client(blob)
272+
273+
with open(fname, "wb") as download_file:
274+
download_file.write(blob_client.download_blob().readall())
267275
except Exception as exc:
268276
log.exception('Error occurred fetching blob from azurefs')
269277

@@ -400,21 +408,27 @@ def _get_container_service(container):
400408
401409
Try account_key, sas_token, and no auth in that order
402410
"""
403-
if 'account_key' in container:
404-
account = azure.storage.common.CloudStorageAccount(container['account_name'], account_key=container['account_key'])
405-
elif 'sas_token' in container:
406-
account = azure.storage.common.CloudStorageAccount(container['account_name'], sas_token=container['sas_token'])
407-
else:
408-
account = azure.storage.common.CloudStorageAccount(container['account_name'])
409-
blob_service = account.create_block_blob_service()
410-
if 'proxy' in container and len(container['proxy'].split(':')) == 2:
411-
blob_service.set_proxy(container['proxy'].split(':')[0], container['proxy'].split(':')[1])
411+
account_url = f'https://{container["account_name"]}.blob.core.windows.net'
412+
413+
proxies = None
414+
if 'proxy' in container:
415+
proxies = {'http': container['proxy']}
412416
# If 'proxy' isn't specified in container block, check if 'https_proxy' is set.
413-
elif 'https_proxy' in __opts__ and len(__opts__['https_proxy'].split(':')) == 2:
414-
blob_service.set_proxy(__opts__['https_proxy'].split(':')[0], __opts__['https_proxy'].split(':')[1])
415-
return blob_service
416-
417+
elif 'https_proxy' in __opts__:
418+
proxies = {'https': __opts__['https_proxy']}
419+
420+
# instantiate based upon credential
421+
if "account_key" in container:
422+
blob_service = BlobServiceClient(
423+
account_url=account_url, credential=container["account_key"], proxies=proxies)
424+
elif "sas_token" in container:
425+
blob_service = BlobServiceClient(
426+
account_url=account_url, credential=container["sas_token"], proxies=proxies)
427+
else:
428+
blob_service = BlobServiceClient(account_url=account_url, proxies=proxies)
417429

430+
return blob_service.get_container_client(container['container_name'])
431+
418432
def _validate_config():
419433
"""
420434
Validate azurefs config, return False if it doesn't validate

optional-requirements.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
azure==4.0.0
2-
azure-storage-common~=1.4
3-
azure-storage-blob~=1.3
1+
azure-storage-blob
42
boto3
53
botocore

pkg/abandoned/debian7/pyinstaller-requirements.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ salt-ssh
1414
gitpython
1515
pyinotify
1616
cffi
17-
azure==4.0.0
18-
azure-storage-common~=1.4
19-
azure-storage-blob~=1.3
17+
azure-storage-blob
2018
croniter
2119
vulners
2220
ntplib

pkg/dev/abandoned/debian7/pyinstaller-requirements.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ salt-ssh
1414
gitpython
1515
pyinotify
1616
cffi
17-
azure==4.0.0
18-
azure-storage-common~=1.4
19-
azure-storage-blob~=1.3
17+
azure-storage-blob
2018
croniter
2119
vulners
2220
ntplib

requirements.txt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# This file was generated by mk-requires.sh
22

33
ansi2html
4-
azure==4.0.0
5-
azure-storage-common~=1.4
6-
azure-storage-blob~=1.3
4+
azure-storage-blob
75
backports-abc
86
boto3
97
botocore

0 commit comments

Comments
 (0)