1
1
import logging
2
+ import os
2
3
import threading
3
4
from datetime import datetime , timedelta
4
5
@@ -17,38 +18,45 @@ class AzureRemoteTree(BaseRemoteTree):
17
18
PATH_CLS = CloudURLInfo
18
19
REQUIRES = {
19
20
"azure-storage-blob" : "azure.storage.blob" ,
20
- "azure-cli-core " : "azure.cli.core " ,
21
+ "knack " : "knack " ,
21
22
}
22
23
PARAM_CHECKSUM = "etag"
23
24
COPY_POLL_SECONDS = 5
24
25
LIST_OBJECT_PAGE_SIZE = 5000
25
26
26
27
def __init__ (self , repo , config ):
27
- from azure .cli .core import get_default_cli
28
-
29
28
super ().__init__ (repo , config )
30
29
31
- # NOTE: az_config takes care of env vars
32
- az_config = get_default_cli ().config
33
-
34
30
url = config .get ("url" , "azure://" )
35
31
self .path_info = self .PATH_CLS (url )
36
32
37
33
if not self .path_info .bucket :
38
- container = az_config .get ("storage" , "container_name" , None )
34
+ container = self . _az_config .get ("storage" , "container_name" , None )
39
35
self .path_info = self .PATH_CLS (f"azure://{ container } " )
40
36
41
37
self ._conn_kwargs = {
42
- opt : config .get (opt ) or az_config .get ("storage" , opt , None )
38
+ opt : config .get (opt ) or self . _az_config .get ("storage" , opt , None )
43
39
for opt in ["connection_string" , "sas_token" ]
44
40
}
45
- self ._conn_kwargs ["account_name" ] = az_config .get (
41
+ self ._conn_kwargs ["account_name" ] = self . _az_config .get (
46
42
"storage" , "account" , None
47
43
)
48
- self ._conn_kwargs ["account_key" ] = az_config .get (
44
+ self ._conn_kwargs ["account_key" ] = self . _az_config .get (
49
45
"storage" , "key" , None
50
46
)
51
47
48
+ @cached_property
49
+ def _az_config (self ):
50
+ # NOTE: ideally we would've used get_default_cli().config from
51
+ # azure.cli.core, but azure-cli-core has a lot of conflicts with other
52
+ # dependencies. So instead we are just use knack directly
53
+ from knack .config import CLIConfig
54
+
55
+ config_dir = os .getenv (
56
+ "AZURE_CONFIG_DIR" , os .path .expanduser (os .path .join ("~" , ".azure" ))
57
+ )
58
+ return CLIConfig (config_dir = config_dir , config_env_var_prefix = "AZURE" )
59
+
52
60
@wrap_prop (threading .Lock ())
53
61
@cached_property
54
62
def blob_service (self ):
0 commit comments