Skip to content

Commit 9e831a6

Browse files
authored
[Storage] Fix #32048: az storage blob sync: Fix using azcopy with account-key without login into azcli (#32127)
1 parent 42086ea commit 9e831a6

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

  • src/azure-cli/azure/cli/command_modules/storage/azcopy

src/azure-cli/azure/cli/command_modules/storage/azcopy/util.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,22 @@ def login_auth_for_azcopy(cmd):
146146

147147

148148
def client_auth_for_azcopy(cmd, client):
149-
# prefer oauth mode
150-
if client.credential:
149+
# prefer oauth mode, if account-key is not provided
150+
is_oauth = True
151+
credential = client.credential
152+
if credential:
153+
if isinstance(credential, dict) and "account_key" in credential:
154+
is_oauth = False
155+
elif hasattr(credential, "account_key"):
156+
is_oauth = False
157+
elif isinstance(credential, str):
158+
sas_indicators = ["sig=", "sv=", "sr=", "se=", "sp="]
159+
for indicator in sas_indicators:
160+
if indicator in credential:
161+
is_oauth = False
162+
break
163+
164+
if is_oauth:
151165
raw_token = Profile(cli_ctx=cmd.cli_ctx).get_raw_token(resource=STORAGE_RESOURCE_ENDPOINT)
152166
token_info = raw_token[0][2]
153167
try:

0 commit comments

Comments
 (0)