Skip to content

Commit

Permalink
[Storage] Fix Azure#16079: public blob gives error (Azure#16578)
Browse files Browse the repository at this point in the history
* support rest without credential

* fix style
  • Loading branch information
Juliehzl authored Jan 21, 2021
1 parent f58842b commit b1c1498
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
16 changes: 3 additions & 13 deletions src/azure-cli/azure/cli/command_modules/storage/_client_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ def get_account_url(cli_ctx, account_name, service):


def cf_blob_service(cli_ctx, kwargs):
from knack.util import CLIError
client_kwargs = _prepare_client_kwargs_track2(cli_ctx)
t_blob_service = get_sdk(cli_ctx, ResourceType.DATA_STORAGE_BLOB,
'_blob_service_client#BlobServiceClient')
Expand All @@ -219,10 +218,7 @@ def cf_blob_service(cli_ctx, kwargs):
account_url = get_account_url(cli_ctx, account_name=account_name, service='blob')
credential = account_key or sas_token or token_credential

if account_url and credential:
return t_blob_service(account_url=account_url, credential=credential, **client_kwargs)
raise CLIError("Please provide valid connection string, or account name with account key, "
"sas token or login auth mode.")
return t_blob_service(account_url=account_url, credential=credential, **client_kwargs)


def cf_blob_client(cli_ctx, kwargs):
Expand Down Expand Up @@ -258,9 +254,7 @@ def cf_adls_service(cli_ctx, kwargs):
account_url = get_account_url(cli_ctx, account_name=account_name, service='dfs')
credential = account_key or sas_token or token_credential

if account_url and credential:
return t_adls_service(account_url=account_url, credential=credential, **client_kwargs)
return None
return t_adls_service(account_url=account_url, credential=credential, **client_kwargs)


def cf_adls_file_system(cli_ctx, kwargs):
Expand All @@ -281,7 +275,6 @@ def cf_or_policy(cli_ctx, _):


def cf_queue_service(cli_ctx, kwargs):
from knack.util import CLIError
client_kwargs = _prepare_client_kwargs_track2(cli_ctx)
t_queue_service = get_sdk(cli_ctx, ResourceType.DATA_STORAGE_QUEUE, '_queue_service_client#QueueServiceClient')
connection_string = kwargs.pop('connection_string', None)
Expand All @@ -296,10 +289,7 @@ def cf_queue_service(cli_ctx, kwargs):
account_url = get_account_url(cli_ctx, account_name=account_name, service='queue')
credential = account_key or sas_token or token_credential

if account_url and credential:
return t_queue_service(account_url=account_url, credential=credential, **client_kwargs)
raise CLIError("Please provide valid connection string, or account name with account key, "
"sas token or login auth mode.")
return t_queue_service(account_url=account_url, credential=credential, **client_kwargs)


def cf_queue_client(cli_ctx, kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ def validate_client_parameters(cmd, namespace):
'https://docs.microsoft.com/en-us/azure/storage/common/storage-auth-aad-rbac-cli. \n'
'Setting the corresponding environment variables can avoid inputting credentials in '
'your command. Please use --help to get more information.')
n.account_key = _query_account_key(cmd.cli_ctx, n.account_name)
try:
n.account_key = _query_account_key(cmd.cli_ctx, n.account_name)
except Exception: # pylint: disable=broad-except
pass


def validate_encryption_key(cmd, namespace):
Expand Down

0 comments on commit b1c1498

Please sign in to comment.