Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions dvc/remote/azure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
import threading
from datetime import datetime, timedelta

Expand All @@ -17,38 +18,45 @@ class AzureRemoteTree(BaseRemoteTree):
PATH_CLS = CloudURLInfo
REQUIRES = {
"azure-storage-blob": "azure.storage.blob",
"azure-cli-core": "azure.cli.core",
"knack": "knack",
}
PARAM_CHECKSUM = "etag"
COPY_POLL_SECONDS = 5
LIST_OBJECT_PAGE_SIZE = 5000

def __init__(self, repo, config):
from azure.cli.core import get_default_cli

super().__init__(repo, config)

# NOTE: az_config takes care of env vars
az_config = get_default_cli().config

url = config.get("url", "azure://")
self.path_info = self.PATH_CLS(url)

if not self.path_info.bucket:
container = az_config.get("storage", "container_name", None)
container = self._az_config.get("storage", "container_name", None)
self.path_info = self.PATH_CLS(f"azure://{container}")

self._conn_kwargs = {
opt: config.get(opt) or az_config.get("storage", opt, None)
opt: config.get(opt) or self._az_config.get("storage", opt, None)
for opt in ["connection_string", "sas_token"]
}
self._conn_kwargs["account_name"] = az_config.get(
self._conn_kwargs["account_name"] = self._az_config.get(
"storage", "account", None
)
self._conn_kwargs["account_key"] = az_config.get(
self._conn_kwargs["account_key"] = self._az_config.get(
"storage", "key", None
)

@cached_property
def _az_config(self):
# NOTE: ideally we would've used get_default_cli().config from
# azure.cli.core, but azure-cli-core has a lot of conflicts with other
# dependencies. So instead we are just use knack directly
from knack.config import CLIConfig

config_dir = os.getenv(
"AZURE_CONFIG_DIR", os.path.expanduser(os.path.join("~", ".azure"))
)
return CLIConfig(config_dir=config_dir, config_env_var_prefix="AZURE")

@wrap_prop(threading.Lock())
@cached_property
def blob_service(self):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def run(self):
gs = ["google-cloud-storage==1.19.0"]
gdrive = ["pydrive2>=1.4.14"]
s3 = ["boto3>=1.9.201"]
azure = ["azure-storage-blob==2.1.0", "azure-cli-core>=2.0.70"]
azure = ["azure-storage-blob==2.1.0", "knack"]
oss = ["oss2==2.6.1"]
ssh = ["paramiko>=2.5.0"]
hdfs = ["pyarrow>=0.17.0"]
Expand Down