Skip to content

Commit 5de3cef

Browse files
authored
{Storage} Fix secondary storage account read access (#14605)
* fix second * fix test
1 parent 7680db9 commit 5de3cef

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

src/azure-cli-core/azure/cli/core/commands/client_factory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ def _get_mgmt_service_client(cli_ctx,
174174

175175

176176
def get_data_service_client(cli_ctx, service_type, account_name, account_key, connection_string=None,
177-
sas_token=None, socket_timeout=None, token_credential=None, endpoint_suffix=None):
177+
sas_token=None, socket_timeout=None, token_credential=None, endpoint_suffix=None,
178+
location_mode=None):
178179
logger.debug('Getting data service client service_type=%s', service_type.__name__)
179180
try:
180181
client_kwargs = {'account_name': account_name,
@@ -188,6 +189,8 @@ def get_data_service_client(cli_ctx, service_type, account_name, account_key, co
188189
if endpoint_suffix:
189190
client_kwargs['endpoint_suffix'] = endpoint_suffix
190191
client = service_type(**client_kwargs)
192+
if location_mode:
193+
client.location_mode = location_mode
191194
except ValueError as exc:
192195
_ERROR_STORAGE_MISSING_INFO = get_sdk(cli_ctx, ResourceType.DATA_STORAGE,
193196
'common._error#_ERROR_STORAGE_MISSING_INFO')

src/azure-cli/azure/cli/command_modules/storage/_client_factory.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@
2323

2424

2525
def get_storage_data_service_client(cli_ctx, service, name=None, key=None, connection_string=None, sas_token=None,
26-
socket_timeout=None, token_credential=None):
26+
socket_timeout=None, token_credential=None, location_mode=None):
2727
return get_data_service_client(cli_ctx, service, name, key, connection_string, sas_token,
2828
socket_timeout=socket_timeout,
2929
token_credential=token_credential,
30-
endpoint_suffix=cli_ctx.cloud.suffixes.storage_endpoint)
30+
endpoint_suffix=cli_ctx.cloud.suffixes.storage_endpoint,
31+
location_mode=location_mode)
3132

3233

3334
def generic_data_service_factory(cli_ctx, service, name=None, key=None, connection_string=None, sas_token=None,
34-
socket_timeout=None, token_credential=None):
35+
socket_timeout=None, token_credential=None, location_mode=None):
3536
try:
3637
return get_storage_data_service_client(cli_ctx, service, name, key, connection_string, sas_token,
37-
socket_timeout, token_credential)
38+
socket_timeout, token_credential, location_mode=location_mode)
3839
except ValueError as val_exception:
3940
_ERROR_STORAGE_MISSING_INFO = get_sdk(cli_ctx, ResourceType.DATA_STORAGE,
4041
'common._error#_ERROR_STORAGE_MISSING_INFO')
@@ -78,7 +79,8 @@ def blob_data_service_factory(cli_ctx, kwargs):
7879
connection_string=kwargs.pop('connection_string', None),
7980
sas_token=kwargs.pop('sas_token', None),
8081
socket_timeout=kwargs.pop('socket_timeout', None),
81-
token_credential=kwargs.pop('token_credential', None))
82+
token_credential=kwargs.pop('token_credential', None),
83+
location_mode=kwargs.pop('location_mode', None))
8284

8385

8486
def table_data_service_factory(cli_ctx, kwargs):

src/azure-cli/azure/cli/command_modules/storage/_validators.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ def validate_client_parameters(cmd, namespace):
168168
if n.sas_token:
169169
n.sas_token = n.sas_token.lstrip('?')
170170

171+
# account name with secondary
172+
if n.account_name and n.account_name.endswith('-secondary'):
173+
n.location_mode = 'secondary'
174+
n.account_name = n.account_name[:-10]
175+
171176
# if account name is specified but no key, attempt to query
172177
if n.account_name and not n.account_key and not n.sas_token:
173178
logger.warning('There is no credential provided in your command and environment, we will query account key '

0 commit comments

Comments
 (0)