Skip to content

Commit dfee0e1

Browse files
authored
[Keyvault] BREAKING CHANGE: az keyvault storage: Remove this command group since service doesn't maintain anymore (#27619)
* fully remove �z keyvault storage command group * fix linter
1 parent 3209b95 commit dfee0e1

File tree

8 files changed

+2
-2929
lines changed

8 files changed

+2
-2929
lines changed

src/azure-cli/azure/cli/command_modules/keyvault/_help.py

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -855,69 +855,6 @@
855855
az keyvault show-deleted --name MyKeyVault
856856
"""
857857

858-
helps['keyvault storage'] = """
859-
type: group
860-
short-summary: Manage storage accounts.
861-
"""
862-
863-
helps['keyvault storage add'] = """
864-
type: command
865-
examples:
866-
- name: Create a storage account and setup a vault to manage its keys
867-
text: |
868-
$id = az storage account create -g resourcegroup -n storageacct --query id
869-
870-
# assign the Azure Key Vault service the "Storage Account Key Operator Service Role" role.
871-
az role assignment create --role "Storage Account Key Operator Service Role" --scope $id \\
872-
--assignee cfa8b339-82a2-471a-a3c9-0fc0be7a4093
873-
874-
az keyvault storage add --vault-name vault -n storageacct --active-key-name key1 \\
875-
--auto-regenerate-key --regeneration-period P90D --resource-id $id
876-
"""
877-
878-
helps['keyvault storage remove'] = """
879-
type: command
880-
short-summary: Remove a Key Vault managed Azure Storage Account and all associated SAS definitions. This operation requires the storage/delete permission.
881-
examples:
882-
- name: Remove a Key Vault managed Azure Storage Account and all associated SAS definitions (autogenerated)
883-
text: |
884-
az keyvault storage remove --id "/subscriptions/00000000-0000-0000-0000-00000000000000000/resourceGroups/myrg/providers/Microsoft.KeyVault/vaults/mykv/privateEndpointConnections/mykv.00000000-0000-0000-0000-00000000000000000"
885-
crafted: true
886-
- name: Remove a Key Vault managed Azure Storage Account and all associated SAS definitions (autogenerated)
887-
text: |
888-
az keyvault storage remove --name MyStorageAccount --vault-name MyVault
889-
crafted: true
890-
"""
891-
892-
helps['keyvault storage sas-definition'] = """
893-
type: group
894-
short-summary: Manage storage account SAS definitions.
895-
"""
896-
897-
helps['keyvault storage sas-definition create'] = """
898-
type: command
899-
examples:
900-
- name: Add a sas-definition for an account sas-token
901-
text: |4
902-
$sastoken = az storage account generate-sas --expiry 2020-01-01 --permissions rw --resource-types sco --services bfqt --https-only --account-name storageacct --account-key 00000000
903-
904-
az keyvault storage sas-definition create --vault-name vault --account-name storageacct -n rwallserviceaccess --validity-period P2D --sas-type account --template-uri $sastoken
905-
- name: Add a sas-definition for a blob sas-token
906-
text: >4
907-
$sastoken = az storage blob generate-sas --account-name storageacct --account-key 00000000 -c container1 -n blob1 --https-only --permissions rw
908-
909-
$url = az storage blob url --account-name storageacct -c container1 -n blob1
910-
911-
az keyvault storage sas-definition create --vault-name vault --account-name storageacct -n rwblobaccess --validity-period P2D --sas-type service --template-uri $url?$sastoken
912-
- name: Add a sas-definition for a container sas-token
913-
text: >4
914-
$sastoken = az storage container generate-sas --account-name storageacct --account-key 00000000 -n container1 --https-only --permissions rw
915-
916-
$url = "https://{storage-account-name}.blob.core.windows.net/{container-name}" # The prefix of your blob url
917-
918-
az keyvault storage sas-definition create --vault-name vault --account-name storageacct -n rwcontaineraccess --validity-period P2D --sas-type service --template-uri $url?$sastoken
919-
"""
920-
921858
helps['keyvault update'] = """
922859
type: command
923860
short-summary: Update the properties of a Vault.

src/azure-cli/azure/cli/command_modules/keyvault/_params.py

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
validate_key_import_source, validate_key_type, validate_policy_permissions, validate_principal,
2525
validate_resource_group_name, validate_x509_certificate_chain,
2626
secret_text_encoding_values, secret_binary_encoding_values, validate_subnet, validate_ip_address,
27-
validate_vault_or_hsm, validate_key_id, validate_sas_definition_id, validate_storage_account_id,
28-
validate_storage_disabled_attribute, validate_deleted_vault_or_hsm_name, validate_encryption, validate_decryption,
27+
validate_vault_or_hsm, validate_key_id,
28+
validate_deleted_vault_or_hsm_name, validate_encryption, validate_decryption,
2929
validate_vault_name_and_hsm_name, set_vault_base_url, validate_keyvault_resource_id,
3030
process_hsm_name, KeyEncryptionDataType, process_key_release_policy, process_certificate_policy,
3131
process_certificate_import)
@@ -38,11 +38,6 @@
3838

3939
# pylint: disable=too-many-locals, too-many-branches, too-many-statements, line-too-long
4040
def load_arguments(self, _):
41-
(JsonWebKeyOperation, SasTokenType,
42-
SasDefinitionAttributes, StorageAccountAttributes) = self.get_models(
43-
'JsonWebKeyOperation', 'SasTokenType',
44-
'SasDefinitionAttributes', 'StorageAccountAttributes',
45-
resource_type=ResourceType.DATA_KEYVAULT)
4641

4742
JsonWebKeyType = self.get_sdk('KeyType', resource_type=ResourceType.DATA_KEYVAULT_KEYS, mod='_enums')
4843
KeyCurveName = self.get_sdk('KeyCurveName', resource_type=ResourceType.DATA_KEYVAULT_KEYS, mod='_enums')
@@ -674,77 +669,6 @@ class CLISecurityDomainOperation(str, Enum):
674669

675670
# endregion
676671

677-
# region KeyVault Storage Account
678-
with self.argument_context('keyvault storage', arg_group='Id') as c:
679-
c.argument('storage_account_name', options_list=['--name', '-n'],
680-
help='Name to identify the storage account in the vault.', id_part='child_name_1',
681-
completer=get_keyvault_name_completion_list('storage_account'))
682-
c.argument('vault_base_url', vault_name_type, type=get_vault_base_url_type(self.cli_ctx), id_part=None)
683-
684-
for scope in ['keyvault storage add', 'keyvault storage update']:
685-
with self.argument_context(scope) as c:
686-
c.extra('disabled', arg_type=get_three_state_flag(), help='Add the storage account in a disabled state.',
687-
validator=validate_storage_disabled_attribute(
688-
'storage_account_attributes', StorageAccountAttributes))
689-
c.ignore('storage_account_attributes')
690-
c.argument('auto_regenerate_key', arg_type=get_three_state_flag(), required=False)
691-
c.argument('regeneration_period', help='The key regeneration time duration specified in ISO-8601 format, '
692-
'such as "P30D" for rotation every 30 days.')
693-
for scope in ['backup', 'show', 'update', 'remove', 'regenerate-key']:
694-
with self.argument_context('keyvault storage ' + scope, arg_group='Id') as c:
695-
c.extra('identifier', options_list=['--id'],
696-
help='Id of the storage account. If specified all other \'Id\' arguments should be omitted.',
697-
validator=validate_storage_account_id)
698-
c.argument('storage_account_name', required=False,
699-
help='Name to identify the storage account in the vault. Required if --id is not specified.')
700-
c.argument('vault_base_url', help='Name of the Key Vault. Required if --id is not specified.',
701-
required=False)
702-
703-
with self.argument_context('keyvault storage backup') as c:
704-
c.argument('file_path', options_list=['--file', '-f'], type=file_type, completer=FilesCompleter(),
705-
help='Local file path in which to store storage account backup.')
706-
707-
with self.argument_context('keyvault storage restore') as c:
708-
c.argument('file_path', options_list=['--file', '-f'], type=file_type, completer=FilesCompleter(),
709-
help='Local key backup from which to restore storage account.')
710-
711-
with self.argument_context('keyvault storage sas-definition', arg_group='Id') as c:
712-
c.argument('storage_account_name', options_list=['--account-name'],
713-
help='Name to identify the storage account in the vault.', id_part='child_name_1',
714-
completer=get_keyvault_name_completion_list('storage_account'))
715-
c.argument('sas_definition_name', options_list=['--name', '-n'],
716-
help='Name to identify the SAS definition in the vault.', id_part='child_name_2')
717-
718-
for scope in ['keyvault storage sas-definition create', 'keyvault storage sas-definition update']:
719-
with self.argument_context(scope) as c:
720-
c.extra('disabled', arg_type=get_three_state_flag(), help='Add the storage account in a disabled state.',
721-
validator=validate_storage_disabled_attribute('sas_definition_attributes', SasDefinitionAttributes))
722-
c.ignore('sas_definition_attributes')
723-
c.argument('sas_type', arg_type=get_enum_type(SasTokenType))
724-
c.argument('template_uri',
725-
help='The SAS definition token template signed with the key 00000000. '
726-
'In the case of an account token this is only the sas token itself, for service tokens, '
727-
'the full service endpoint url along with the sas token. Tokens created according to the '
728-
'SAS definition will have the same properties as the template.')
729-
c.argument('validity_period',
730-
help='The validity period of SAS tokens created according to the SAS definition in ISO-8601, '
731-
'such as "PT12H" for 12 hour tokens.')
732-
c.argument('auto_regenerate_key', arg_type=get_three_state_flag())
733-
734-
for scope in ['keyvault storage sas-definition delete', 'keyvault storage sas-definition show',
735-
'keyvault storage sas-definition update']:
736-
with self.argument_context(scope, arg_group='Id') as c:
737-
c.extra('identifier', options_list=['--id'],
738-
help='Id of the SAS definition. If specified all other \'Id\' arguments should be omitted.',
739-
validator=validate_sas_definition_id)
740-
c.argument('storage_account_name', required=False,
741-
help='Name to identify the storage account in the vault. Required if --id is not specified.')
742-
c.argument('sas_definition_name', required=False,
743-
help='Name to identify the SAS definition in the vault. Required if --id is not specified.')
744-
c.argument('vault_base_url', help='Name of the Key Vault. Required if --id is not specified.',
745-
required=False)
746-
# endregion
747-
748672
# KeyVault Certificate
749673
with self.argument_context('keyvault certificate issuer admin') as c:
750674
c.argument('email', help='Admin e-mail address. Must be unique within the vault.')

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

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -696,44 +696,6 @@ def _validate(ns):
696696
return _validate
697697

698698

699-
def validate_sas_definition_id(ns):
700-
from .vendored_sdks.azure_keyvault_t1 import StorageSasDefinitionId
701-
acct_name = getattr(ns, 'storage_account_name', None)
702-
sas_name = getattr(ns, 'sas_definition_name', None)
703-
vault = getattr(ns, 'vault_base_url', None)
704-
identifier = getattr(ns, 'identifier', None)
705-
706-
if identifier:
707-
ident = StorageSasDefinitionId(uri=identifier)
708-
setattr(ns, 'sas_definition_name', getattr(ident, 'sas_definition'))
709-
setattr(ns, 'storage_account_name', getattr(ident, 'account_name'))
710-
setattr(ns, 'vault_base_url', ident.vault)
711-
elif not (acct_name and sas_name and vault):
712-
raise CLIError('incorrect usage: --id ID | --vault-name VAULT --account-name --name NAME')
713-
714-
715-
def validate_storage_account_id(ns):
716-
from .vendored_sdks.azure_keyvault_t1 import StorageAccountId
717-
acct_name = getattr(ns, 'storage_account_name', None)
718-
vault = getattr(ns, 'vault_base_url', None)
719-
identifier = getattr(ns, 'identifier', None)
720-
721-
if identifier:
722-
ident = StorageAccountId(uri=identifier)
723-
setattr(ns, 'storage_account_name', ident.name)
724-
setattr(ns, 'vault_base_url', ident.vault)
725-
elif not (acct_name and vault):
726-
raise CLIError('incorrect usage: --id ID | --vault-name VAULT --name NAME')
727-
728-
729-
def validate_storage_disabled_attribute(attr_arg_name, attr_type):
730-
def _validate(ns):
731-
disabled = getattr(ns, 'disabled', None)
732-
attr_arg = attr_type(enabled=(not disabled))
733-
setattr(ns, attr_arg_name, attr_arg)
734-
return _validate
735-
736-
737699
def validate_encryption(ns):
738700
if ns.data_type == KeyEncryptionDataType.BASE64:
739701
ns.value = base64.b64decode(ns.value.encode('utf-8'))

src/azure-cli/azure/cli/command_modules/keyvault/commands.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -331,39 +331,6 @@ def load_command_table(self, _):
331331
g.keyvault_command('show', 'get_setting')
332332
g.keyvault_custom('update', 'update_hsm_setting')
333333

334-
data_api_version = str(get_api_version(self.cli_ctx, ResourceType.DATA_KEYVAULT)).\
335-
replace('.', '_').replace('-', '_')
336-
337-
if data_api_version != '2016_10_01':
338-
with self.command_group('keyvault storage', data_entity.command_type, deprecate_info=self.deprecate()) as g:
339-
g.keyvault_command('add', 'set_storage_account')
340-
g.keyvault_command('list', 'get_storage_accounts', transform=keep_max_results)
341-
g.keyvault_command('show', 'get_storage_account')
342-
g.keyvault_command('update', 'update_storage_account')
343-
g.keyvault_command('remove', 'delete_storage_account')
344-
g.keyvault_command('regenerate-key', 'regenerate_storage_account_key')
345-
g.keyvault_command('list-deleted', 'get_deleted_storage_accounts', transform=keep_max_results)
346-
g.keyvault_command('show-deleted', 'get_deleted_storage_account')
347-
g.keyvault_command('purge', 'purge_deleted_storage_account')
348-
g.keyvault_command('recover', 'recover_deleted_storage_account')
349-
g.keyvault_custom('backup', 'backup_storage_account',
350-
doc_string_source=data_entity.operations_docs_tmpl.format('backup_storage_account'))
351-
g.keyvault_custom('restore', 'restore_storage_account',
352-
doc_string_source=data_entity.operations_docs_tmpl.format('restore_storage_account'))
353-
354-
if data_api_version != '2016_10_01':
355-
with self.command_group('keyvault storage sas-definition', data_entity.command_type) as g:
356-
g.keyvault_command('create', 'set_sas_definition',
357-
doc_string_source=data_entity.operations_docs_tmpl.format('set_sas_definition'))
358-
g.keyvault_command('list', 'get_sas_definitions', transform=keep_max_results)
359-
g.keyvault_command('show', 'get_sas_definition')
360-
g.keyvault_command('update', 'update_sas_definition',
361-
doc_string_source=data_entity.operations_docs_tmpl.format('update_sas_definition'))
362-
g.keyvault_command('delete', 'delete_sas_definition')
363-
g.keyvault_command('list-deleted', 'get_deleted_sas_definitions', transform=keep_max_results)
364-
g.keyvault_command('show-deleted', 'get_deleted_sas_definition')
365-
g.keyvault_command('recover', 'recover_deleted_sas_definition')
366-
367334
if not is_azure_stack_profile(self):
368335
with self.command_group('keyvault region', mgmt_hsms_regions_entity.command_type,
369336
client_factory=mgmt_hsms_regions_entity.client_factory, min_api='2023-02-01') as g:

src/azure-cli/azure/cli/command_modules/keyvault/custom.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1695,21 +1695,6 @@ def delete_certificate_issuer_admin(client, issuer_name, email):
16951695
# endregion
16961696

16971697

1698-
# region storage_account
1699-
def backup_storage_account(client, file_path, vault_base_url=None,
1700-
storage_account_name=None, identifier=None): # pylint: disable=unused-argument
1701-
backup = client.backup_storage_account(vault_base_url, storage_account_name).value
1702-
with open(file_path, 'wb') as output:
1703-
output.write(backup)
1704-
1705-
1706-
def restore_storage_account(client, vault_base_url, file_path):
1707-
with open(file_path, 'rb') as file_in:
1708-
data = file_in.read()
1709-
return client.restore_storage_account(vault_base_url, data)
1710-
# endregion
1711-
1712-
17131698
# region private_link
17141699
def _verify_vault_or_hsm_name(vault_name, hsm_name):
17151700
if not vault_name and not hsm_name:

0 commit comments

Comments
 (0)