Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Storage] Fix #22845: az storage account genarete-sas: Fix the flag --auth-mode login cause AttributeError #22854

Merged
merged 10 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import os
from azure.cli.command_modules.storage._client_factory import storage_client_factory, cf_sa_for_keys
from azure.cli.command_modules.storage._validators import _query_account_key
from azure.cli.core.util import get_file_json, shell_safe_json_parse, find_child_item
from azure.cli.core.profiles import ResourceType, get_sdk
from knack.log import get_logger
Expand All @@ -30,18 +31,23 @@ def regenerate_key(cmd, client, account_name, key_name, resource_group_name=None
def generate_sas(cmd, client, services, resource_types, permission, expiry, start=None,
ip=None, protocol=None, **kwargs):
from azure.cli.core.azclierror import RequiredArgumentMissingError
if not client.account_name or not client.credential or not client.credential.account_key:
error_msg = """
Missing/Invalid credentials to access storage service. The following variations are accepted:
(1) account name and key (--account-name and --account-key options or
set AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_KEY environment variables)
(2) account name (--account-name option or AZURE_STORAGE_ACCOUNT environment variable;
this will make calls to query for a storage account key using login credentials)
(3) connection string (--connection-string option or
set AZURE_STORAGE_CONNECTION_STRING environment variable); some shells will require
quoting to preserve literal character interpretation.
"""
raise RequiredArgumentMissingError(error_msg)

try:
if not client.account_name or not client.credential or not client.credential.account_key:
error_msg = """
Missing/Invalid credentials to access storage service. The following variations are accepted:
(1) account name and key (--account-name and --account-key options or
set AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_KEY environment variables)
(2) account name (--account-name option or AZURE_STORAGE_ACCOUNT environment variable;
this will make calls to query for a storage account key using login credentials)
(3) connection string (--connection-string option or
set AZURE_STORAGE_CONNECTION_STRING environment variable); some shells will require
quoting to preserve literal character interpretation.
"""
raise RequiredArgumentMissingError(error_msg)
except AttributeError:
if client.account_name:
client.credential.account_key = _query_account_key(cmd.cli_ctx, client.account_name)
evelyn-ys marked this conversation as resolved.
Show resolved Hide resolved

t_account_sas = get_sdk(cmd.cli_ctx, ResourceType.DATA_STORAGE_BLOB,
'_shared.shared_access_signature#SharedAccessSignature')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
interactions: []
version: 1
version: 1