Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -443,7 +443,6 @@ def load_arguments(self, _):
c.argument('public_network_access', options_list=['--public-network-access', '-p'], arg_type=get_enum_type(['ENABLED', 'DISABLED']), help="Sets public network access in server to either Enabled or Disabled.")
c.argument('disable_ttl', options_list=['--disable-ttl', '-d'], arg_type=get_three_state_flag(), help="Enable or disable restoring with ttl disabled.")
c.argument('source_backup_location', help="This is the location of the source account where backups are located. Provide this value if the source and target are in different locations.")
c.argument('disable_local_auth', arg_type=get_three_state_flag(), help="Disable key-based authentication on the Cosmos DB account")

# Mongo role definition
with self.argument_context('cosmosdb mongodb role definition') as c:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,26 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.util import todict
from knack.util import todict


def transform_network_rule_json_output(result):
# 'result' is a plain dict produced by azure.cli.core.util.todict (which, unlike
# knack.util.todict, understands the typespec-generated SDK models). Rename the
# service endpoint flag to the historical CLI casing and drop the msrest-era
# 'additionalProperties' artifact if present.
result = todict(result)
result['ignoreMissingVnetServiceEndpoint'] = result.pop('ignoreMissingVNetServiceEndpoint', None)
result.pop('additionalProperties', None)
del result['additionalProperties']
return result
Comment on lines 9 to 13


def transform_network_rule_list_output(result):
return [transform_network_rule_json_output(item) for item in todict(result)]
new_result = []
for item in result:
new_result.append(transform_network_rule_json_output(item))
return new_result


def transform_db_account_json_output(result):
# Only convert to a dict when there are virtual network rules to rewrite. Assigning
# plain dicts back onto the model would be coerced back into VirtualNetworkRule
# instances (dropping the renamed key), so we convert the whole account to a dict
# up front and rewrite the rules there.
if hasattr(result, 'virtual_network_rules') and result.virtual_network_rules:
result = todict(result)
result['virtualNetworkRules'] = [
transform_network_rule_json_output(rule)
for rule in result.get('virtualNetworkRules') or []
]
result.virtual_network_rules = transform_network_rule_list_output(result.virtual_network_rules)
return result


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,20 +522,20 @@ def setup_fleet_commands(self):
operations_tmpl='azure.mgmt.cosmosdb.operations#FleetspaceAccountOperations.{}',
client_factory=cf_fleetspace_account)

with self.command_group('cosmosdb fleet', cosmosdb_fleet_sdk, client_factory=cf_fleet) as g:
with self.command_group('cosmosdb fleet', cosmosdb_fleet_sdk, client_factory=cf_fleet, is_preview=True) as g:
g.custom_command('create', 'cli_cosmosdb_fleet_create')
g.custom_command('list', 'cli_list_cosmosdb_fleets')
g.show_command('show', 'get')
g.command('delete', 'begin_delete', confirmation=True)

with self.command_group('cosmosdb fleetspace', cosmosdb_fleetspace_sdk, client_factory=cf_fleetspace) as g:
with self.command_group('cosmosdb fleetspace', cosmosdb_fleetspace_sdk, client_factory=cf_fleetspace, is_preview=True) as g:
g.custom_command('create', 'cli_cosmosdb_fleetspace_create')
g.command('list', 'list')
g.show_command('show', 'get')
g.custom_command('update', 'cli_cosmosdb_fleetspace_update')
g.command('delete', 'begin_delete', confirmation=True)

with self.command_group('cosmosdb fleetspace account', cosmosdb_fleetspace_account_sdk, client_factory=cf_fleetspace_account) as g:
with self.command_group('cosmosdb fleetspace account', cosmosdb_fleetspace_account_sdk, client_factory=cf_fleetspace_account, is_preview=True) as g:
g.custom_command('create', 'cli_cosmosdb_fleetspace_account_create')
g.command('list', 'list')
g.show_command('show', 'get')
Expand Down
52 changes: 13 additions & 39 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
ServiceType,
MongoRoleDefinitionCreateUpdateParameters,
MongoUserDefinitionCreateUpdateParameters,
Privilege,
PrivilegeResource,
Role,
RegionForOnlineOffline,
FleetResource,
FleetspaceResource,
Expand Down Expand Up @@ -423,7 +420,7 @@ def _create_database_account(client,
enable_burst_capacity=enable_burst_capacity,
enable_per_region_per_partition_autoscale=enable_prpp_autoscale,
minimal_tls_version=minimal_tls_version,
enable_priority_based_execution=enable_pbe,
enable_pbe=enable_pbe,
default_priority_level=default_priority_level
)

Expand Down Expand Up @@ -582,7 +579,7 @@ def cli_cosmosdb_update(client,
enable_burst_capacity=enable_burst_capacity,
enable_per_region_per_partition_autoscale=enable_prpp_autoscale,
minimal_tls_version=minimal_tls_version,
enable_priority_based_execution=enable_pbe,
enable_pbe=enable_pbe,
default_priority_level=default_priority_level)

async_docdb_update = client.begin_update(resource_group_name, account_name, params)
Expand Down Expand Up @@ -1891,8 +1888,7 @@ def cli_cosmosdb_restore(cmd,
tables_to_restore=None,
public_network_access=None,
disable_ttl=None,
source_backup_location=None,
disable_local_auth=None):
source_backup_location=None):
from azure.cli.command_modules.cosmosdb._client_factory import cf_restorable_database_accounts
restorable_database_accounts_client = cf_restorable_database_accounts(cmd.cli_ctx, [])
restorable_database_accounts = restorable_database_accounts_client.list()
Expand Down Expand Up @@ -1943,8 +1939,7 @@ def cli_cosmosdb_restore(cmd,
arm_location=target_restorable_account.location,
public_network_access=public_network_access,
disable_ttl=disable_ttl,
source_backup_location=source_backup_location,
disable_local_auth=disable_local_auth)
source_backup_location=source_backup_location)


def _convert_to_utc_timestamp(timestamp_string):
Expand Down Expand Up @@ -2283,27 +2278,6 @@ def cli_cosmosdb_collection_update(client,
return result


def _convert_mongo_privileges(privileges):
"""Convert privileges from the user-provided (PascalCase) body into SDK model objects."""
if not privileges:
return privileges
converted = []
for privilege in privileges:
resource = privilege.get('Resource')
privilege_resource = None
if resource is not None:
privilege_resource = PrivilegeResource(db=resource.get('Db'), collection=resource.get('Collection'))
converted.append(Privilege(resource=privilege_resource, actions=privilege.get('Actions')))
return converted


def _convert_mongo_roles(roles):
"""Convert roles from the user-provided (PascalCase) body into SDK model objects."""
if not roles:
return roles
return [Role(db=role.get('Db'), role=role.get('Role')) for role in roles]


def cli_cosmosdb_mongo_role_definition_create(client,
resource_group_name,
account_name,
Expand All @@ -2313,8 +2287,8 @@ def cli_cosmosdb_mongo_role_definition_create(client,
role_name=mongo_role_definition_body['RoleName'],
type=mongo_role_definition_body['Type'],
database_name=mongo_role_definition_body['DatabaseName'],
privileges=_convert_mongo_privileges(mongo_role_definition_body['Privileges']),
roles=_convert_mongo_roles(mongo_role_definition_body['Roles']))
privileges=mongo_role_definition_body['Privileges'],
roles=mongo_role_definition_body['Roles'])

return client.begin_create_update_mongo_role_definition(mongo_role_definition_body['Id'], resource_group_name, account_name, mongo_role_definition_create_resource)

Expand All @@ -2334,8 +2308,8 @@ def cli_cosmosdb_mongo_role_definition_update(client,
role_name=mongo_role_definition.role_name,
type=mongo_role_definition_body['Type'],
database_name=mongo_role_definition_body['DatabaseName'],
privileges=_convert_mongo_privileges(mongo_role_definition_body['Privileges']),
roles=_convert_mongo_roles(mongo_role_definition_body['Roles']))
privileges=mongo_role_definition_body['Privileges'],
roles=mongo_role_definition_body['Roles'])

return client.begin_create_update_mongo_role_definition(mongo_role_definition_body['Id'], resource_group_name, account_name, mongo_role_definition_update_resource)

Expand Down Expand Up @@ -2364,7 +2338,7 @@ def cli_cosmosdb_mongo_user_definition_create(client,
database_name=mongo_user_definition_body['DatabaseName'],
custom_data=mongo_user_definition_body['CustomData'],
mechanisms=mongo_user_definition_body['Mechanisms'],
roles=_convert_mongo_roles(mongo_user_definition_body['Roles']))
roles=mongo_user_definition_body['Roles'])

return client.begin_create_update_mongo_user_definition(mongo_user_definition_body['Id'], resource_group_name, account_name, mongo_user_definition_create_resource)

Expand All @@ -2384,7 +2358,7 @@ def cli_cosmosdb_mongo_user_definition_update(client,
database_name=mongo_user_definition_body['DatabaseName'],
custom_data=mongo_user_definition_body['CustomData'],
mechanisms=mongo_user_definition_body['Mechanisms'],
roles=_convert_mongo_roles(mongo_user_definition_body['Roles']))
roles=mongo_user_definition_body['Roles'])

return sdk_no_wait(no_wait, client.begin_create_update_mongo_user_definition, mongo_user_definition_body['Id'], resource_group_name, account_name, mongo_user_definition_update_resource)

Expand Down Expand Up @@ -3014,7 +2988,7 @@ def cli_cosmosdb_sql_container_restore(cmd,
restorable_containers = restorable_containers_client.list(
restorable_database_account.location,
restorable_database_account.name,
restorable_sql_database_rid=database_rid)
database_rid)

latest_container_delete_time, latest_container_create_or_recreate_time = process_restorable_collections(restorable_containers, container_name, database_name)

Expand Down Expand Up @@ -3205,7 +3179,7 @@ def cli_cosmosdb_mongodb_collection_restore(cmd,
restorable_collections = restorable_collections_client.list(
restorable_database_account.location,
restorable_database_account.name,
restorable_mongodb_database_rid=database_rid)
database_rid)

latest_collection_delete_time, latest_collection_create_or_recreate_time = process_restorable_collections(restorable_collections, collection_name, database_name)

Expand Down Expand Up @@ -3396,7 +3370,7 @@ def cli_cosmosdb_gremlin_graph_restore(cmd,
restorable_graphs = restorable_graphs_client.list(
restorable_database_account.location,
restorable_database_account.name,
restorable_gremlin_database_rid=database_rid)
database_rid)

latest_graph_delete_time, latest_graph_create_or_recreate_time = process_restorable_collections(restorable_graphs, graph_name, database_name)

Expand Down
Loading
Loading