Skip to content

Commit

Permalink
[SQL] az sql db: Add --encryption-protector-auto-rotation flag to…
Browse files Browse the repository at this point in the history
… cmdlets (#27024)

* [SQL] Add '--encryption-protector-auto-rotation' flag to cmdlets

* Updated to new sdk

* change in setup

* tests

* test re-record

* tests

* update to new sdk

* more tests recordings

* tests

* fixes in tests
  • Loading branch information
viparek authored Aug 31, 2023
1 parent 6583e8b commit 42db2d5
Show file tree
Hide file tree
Showing 36 changed files with 30,842 additions and 26,494 deletions.

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/azure-cli/azure/cli/command_modules/sql/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ def get_location_type_with_default_from_resource_group(cli_ctx):
options_list=['--federated-client-id'],
help='The federated client id for the SQL Database. It is used for cross tenant CMK scenario.')

database_encryption_protector_auto_rotation_param_type = CLIArgumentType(
options_list=['--encryption-protector-auto-rotation', '--epauto'],
help='Specifies the database encryption protector key auto rotation flag. Can be either true, false or null.',
required=False,
arg_type=get_three_state_flag())

database_availability_zone_param_type = CLIArgumentType(
options_list=['--availability-zone'],
help='Availability zone')
Expand Down Expand Up @@ -474,6 +480,9 @@ def _configure_db_dw_params(arg_ctx):
arg_ctx.argument('availability_zone',
arg_type=database_availability_zone_param_type)

arg_ctx.argument('encryption_protector_auto_rotation',
arg_type=database_encryption_protector_auto_rotation_param_type)


def _configure_db_dw_create_params(
arg_ctx,
Expand Down Expand Up @@ -574,6 +583,7 @@ def _configure_db_dw_create_params(
'user_assigned_identity_id',
'federated_client_id',
'availability_zone',
'encryption_protector_auto_rotation'
])

# Create args that will be used to build up the Database's Sku object
Expand Down Expand Up @@ -624,6 +634,9 @@ def _configure_db_dw_create_params(
arg_ctx.argument('federated_client_id',
arg_type=database_federated_client_id_param_type)

arg_ctx.argument('encryption_protector_auto_rotation',
arg_type=database_encryption_protector_auto_rotation_param_type)

# *** Step 3: Ignore params that are not applicable (based on engine & create mode) ***

# Only applicable to default create mode. Also only applicable to db.
Expand Down Expand Up @@ -682,6 +695,9 @@ def _configure_db_dw_create_params(
# Federated client id is not applicable to DataWarehouse
arg_ctx.ignore('federated_client_id')

# Encryption Protector auto rotation is not applicable to DataWarehouse
arg_ctx.ignore('encryption_protector_auto_rotation')

# Provisioning with capacity is not applicable to DataWarehouse
arg_ctx.ignore('capacity')

Expand Down
17 changes: 16 additions & 1 deletion src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,7 @@ def _db_dw_create(
user_assigned_identity_id=None,
keys=None,
encryption_protector=None,
encryption_protector_auto_rotation=None,
**kwargs):
'''
Creates a DB (with any create mode) or DW.
Expand Down Expand Up @@ -1137,6 +1138,8 @@ def _db_dw_create(
kwargs['keys'] = _get_database_keys(keys)
kwargs['encryption_protector'] = encryption_protector

kwargs['encryption_protector_auto_rotation'] = encryption_protector_auto_rotation

# Create
return sdk_no_wait(no_wait, client.begin_create_or_update,
server_name=dest_db.server_name,
Expand Down Expand Up @@ -1186,6 +1189,7 @@ def db_create(
user_assigned_identity_id=None,
keys=None,
encryption_protector=None,
encryption_protector_auto_rotation=None,
**kwargs):
'''
Creates a DB (with 'Default' create mode.)
Expand Down Expand Up @@ -1214,6 +1218,7 @@ def db_create(
user_assigned_identity_id=user_assigned_identity_id,
keys=keys,
encryption_protector=encryption_protector,
encryption_protector_auto_rotation=encryption_protector_auto_rotation,
**kwargs)


Expand Down Expand Up @@ -1246,6 +1251,7 @@ def db_copy(
user_assigned_identity_id=None,
keys=None,
encryption_protector=None,
encryption_protector_auto_rotation=None,
**kwargs):
'''
Copies a DB (i.e. create with 'Copy' create mode.)
Expand Down Expand Up @@ -1288,6 +1294,7 @@ def db_copy(
user_assigned_identity_id=user_assigned_identity_id,
keys=keys,
encryption_protector=encryption_protector,
encryption_protector_auto_rotation=encryption_protector_auto_rotation,
**kwargs)


Expand All @@ -1306,6 +1313,7 @@ def db_create_replica(
user_assigned_identity_id=None,
keys=None,
encryption_protector=None,
encryption_protector_auto_rotation=None,
**kwargs):
'''
Creates a secondary replica DB (i.e. create with 'Secondary' create mode.)
Expand Down Expand Up @@ -1351,6 +1359,7 @@ def db_create_replica(
user_assigned_identity_id=user_assigned_identity_id,
keys=keys,
encryption_protector=encryption_protector,
encryption_protector_auto_rotation=encryption_protector_auto_rotation,
**kwargs)


Expand Down Expand Up @@ -1399,6 +1408,7 @@ def db_restore(
user_assigned_identity_id=None,
keys=None,
encryption_protector=None,
encryption_protector_auto_rotation=None,
**kwargs):
'''
Restores an existing or deleted DB (i.e. create with 'Restore'
Expand Down Expand Up @@ -1436,6 +1446,7 @@ def db_restore(
user_assigned_identity_id=user_assigned_identity_id,
keys=keys,
encryption_protector=encryption_protector,
encryption_protector_auto_rotation=encryption_protector_auto_rotation,
**kwargs)


Expand Down Expand Up @@ -1717,7 +1728,8 @@ def db_update( # pylint: disable=too-many-locals
keys=None,
encryption_protector=None,
federated_client_id=None,
keys_to_remove=None):
keys_to_remove=None,
encryption_protector_auto_rotation=None):
'''
Applies requested parameters to a db resource instance for a DB update.
'''
Expand Down Expand Up @@ -1837,6 +1849,9 @@ def db_update( # pylint: disable=too-many-locals

instance.availability_zone = None

if encryption_protector_auto_rotation is not None:
instance.encryption_protector_auto_rotation = encryption_protector_auto_rotation

return instance


Expand Down
Loading

0 comments on commit 42db2d5

Please sign in to comment.