code
stringlengths
26
870k
docstring
stringlengths
1
65.6k
func_name
stringlengths
1
194
language
stringclasses
1 value
repo
stringlengths
8
68
path
stringlengths
5
194
url
stringlengths
46
254
license
stringclasses
4 values
def cli_cosmosdb_mongodb_database_exists(client, resource_group_name, account_name, database_name): """Checks if an Azure Cosmos DB MongoDB database exists""" try: client.get_mongo_db_database(resource_group_name, account_name, database_name) except HttpResponseError as ex: return _handle_exists_exception(ex) return True
Checks if an Azure Cosmos DB MongoDB database exists
cli_cosmosdb_mongodb_database_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongodb_collection_create(client, resource_group_name, account_name, database_name, collection_name, shard_key_path=None, indexes=None, throughput=None, max_throughput=None, analytical_storage_ttl=None): """Create an Azure Cosmos DB MongoDB collection""" mongodb_collection_resource = MongoDBCollectionResource(id=collection_name) _populate_mongodb_collection_definition(mongodb_collection_resource, shard_key_path, indexes, analytical_storage_ttl) options = _get_options(throughput, max_throughput) mongodb_collection_create_update_resource = MongoDBCollectionCreateUpdateParameters( resource=mongodb_collection_resource, options=options) return client.begin_create_update_mongo_db_collection(resource_group_name, account_name, database_name, collection_name, mongodb_collection_create_update_resource)
Create an Azure Cosmos DB MongoDB collection
cli_cosmosdb_mongodb_collection_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongodb_collection_update(client, resource_group_name, account_name, database_name, collection_name, indexes=None, analytical_storage_ttl=None): """Updates an Azure Cosmos DB MongoDB collection """ logger.debug('reading MongoDB collection') mongodb_collection = client.get_mongo_db_collection(resource_group_name, account_name, database_name, collection_name) mongodb_collection_resource = MongoDBCollectionResource(id=collection_name) mongodb_collection_resource.shard_key = mongodb_collection.resource.shard_key mongodb_collection_resource.indexes = mongodb_collection.resource.indexes mongodb_collection_resource.analytical_storage_ttl = mongodb_collection.resource.analytical_storage_ttl if _populate_mongodb_collection_definition(mongodb_collection_resource, None, indexes, analytical_storage_ttl): logger.debug('replacing MongoDB collection') mongodb_collection_create_update_resource = MongoDBCollectionCreateUpdateParameters( resource=mongodb_collection_resource, options={}) return client.begin_create_update_mongo_db_collection(resource_group_name, account_name, database_name, collection_name, mongodb_collection_create_update_resource)
Updates an Azure Cosmos DB MongoDB collection
cli_cosmosdb_mongodb_collection_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongodb_collection_exists(client, resource_group_name, account_name, database_name, collection_name): """Checks if an Azure Cosmos DB MongoDB collection exists""" try: client.get_mongo_db_collection(resource_group_name, account_name, database_name, collection_name) except HttpResponseError as ex: return _handle_exists_exception(ex) return True
Checks if an Azure Cosmos DB MongoDB collection exists
cli_cosmosdb_mongodb_collection_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_keyspace_create(client, resource_group_name, account_name, keyspace_name, throughput=None, max_throughput=None): """Create an Azure Cosmos DB Cassandra keyspace""" options = _get_options(throughput, max_throughput) cassandra_keyspace_resource = CassandraKeyspaceCreateUpdateParameters( resource=CassandraKeyspaceResource(id=keyspace_name), options=options) return client.begin_create_update_cassandra_keyspace(resource_group_name, account_name, keyspace_name, cassandra_keyspace_resource)
Create an Azure Cosmos DB Cassandra keyspace
cli_cosmosdb_cassandra_keyspace_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_keyspace_exists(client, resource_group_name, account_name, keyspace_name): """Checks if an Azure Cosmos DB Cassandra keyspace exists""" try: client.get_cassandra_keyspace(resource_group_name, account_name, keyspace_name) except HttpResponseError as ex: return _handle_exists_exception(ex) return True
Checks if an Azure Cosmos DB Cassandra keyspace exists
cli_cosmosdb_cassandra_keyspace_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_table_create(client, resource_group_name, account_name, keyspace_name, table_name, schema, default_ttl=None, throughput=None, max_throughput=None, analytical_storage_ttl=None): """Create an Azure Cosmos DB Cassandra table""" cassandra_table_resource = CassandraTableResource(id=table_name) _populate_cassandra_table_definition(cassandra_table_resource, default_ttl, schema, analytical_storage_ttl) options = _get_options(throughput, max_throughput) cassandra_table_create_update_resource = CassandraTableCreateUpdateParameters( resource=cassandra_table_resource, options=options) return client.begin_create_update_cassandra_table(resource_group_name, account_name, keyspace_name, table_name, cassandra_table_create_update_resource)
Create an Azure Cosmos DB Cassandra table
cli_cosmosdb_cassandra_table_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_table_update(client, resource_group_name, account_name, keyspace_name, table_name, default_ttl=None, schema=None, analytical_storage_ttl=None): """Update an Azure Cosmos DB Cassandra table""" logger.debug('reading Cassandra table') cassandra_table = client.get_cassandra_table(resource_group_name, account_name, keyspace_name, table_name) cassandra_table_resource = CassandraTableResource(id=table_name) cassandra_table_resource.default_ttl = cassandra_table.resource.default_ttl cassandra_table_resource.schema = cassandra_table.resource.schema cassandra_table_resource.analytical_storage_ttl = cassandra_table.resource.analytical_storage_ttl if _populate_cassandra_table_definition(cassandra_table_resource, default_ttl, schema, analytical_storage_ttl): logger.debug('replacing Cassandra table') cassandra_table_create_update_resource = CassandraTableCreateUpdateParameters( resource=cassandra_table_resource, options={}) return client.begin_create_update_cassandra_table(resource_group_name, account_name, keyspace_name, table_name, cassandra_table_create_update_resource)
Update an Azure Cosmos DB Cassandra table
cli_cosmosdb_cassandra_table_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_table_exists(client, resource_group_name, account_name, keyspace_name, table_name): """Checks if an Azure Cosmos DB Cassandra table exists""" try: client.get_cassandra_table(resource_group_name, account_name, keyspace_name, table_name) except HttpResponseError as ex: return _handle_exists_exception(ex) return True
Checks if an Azure Cosmos DB Cassandra table exists
cli_cosmosdb_cassandra_table_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_table_create(client, resource_group_name, account_name, table_name, throughput=None, max_throughput=None): """Create an Azure Cosmos DB table""" options = _get_options(throughput, max_throughput) table = TableCreateUpdateParameters( resource=TableResource(id=table_name), options=options) return client.begin_create_update_table(resource_group_name, account_name, table_name, table)
Create an Azure Cosmos DB table
cli_cosmosdb_table_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_table_exists(client, resource_group_name, account_name, table_name): """Checks if an Azure Cosmos DB table exists""" try: client.get_table(resource_group_name, account_name, table_name) except HttpResponseError as ex: return _handle_exists_exception(ex) return True
Checks if an Azure Cosmos DB table exists
cli_cosmosdb_table_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_database_throughput_update(client, resource_group_name, account_name, database_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB SQL database throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_sql_database_throughput(resource_group_name, account_name, database_name, throughput_update_resource)
Update an Azure Cosmos DB SQL database throughput
cli_cosmosdb_sql_database_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_container_throughput_update(client, resource_group_name, account_name, database_name, container_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB SQL container throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_sql_container_throughput(resource_group_name, account_name, database_name, container_name, throughput_update_resource)
Update an Azure Cosmos DB SQL container throughput
cli_cosmosdb_sql_container_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_container_throughput_migrate(client, resource_group_name, account_name, database_name, container_name, throughput_type): """Migrate an Azure Cosmos DB SQL container throughput""" if throughput_type == "autoscale": return client.begin_migrate_sql_container_to_autoscale(resource_group_name, account_name, database_name, container_name) return client.begin_migrate_sql_container_to_manual_throughput(resource_group_name, account_name, database_name, container_name)
Migrate an Azure Cosmos DB SQL container throughput
cli_cosmosdb_sql_container_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongodb_database_throughput_update(client, resource_group_name, account_name, database_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB MongoDB database throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_mongo_db_database_throughput(resource_group_name, account_name, database_name, throughput_update_resource)
Update an Azure Cosmos DB MongoDB database throughput
cli_cosmosdb_mongodb_database_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongodb_database_throughput_migrate(client, resource_group_name, account_name, database_name, throughput_type): """Migrate an Azure Cosmos DB MongoDB database throughput""" if throughput_type == "autoscale": return client.begin_migrate_mongo_db_database_to_autoscale(resource_group_name, account_name, database_name) return client.begin_migrate_mongo_db_database_to_manual_throughput(resource_group_name, account_name, database_name)
Migrate an Azure Cosmos DB MongoDB database throughput
cli_cosmosdb_mongodb_database_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongodb_collection_throughput_update(client, resource_group_name, account_name, database_name, collection_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB MongoDB collection throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_mongo_db_collection_throughput(resource_group_name, account_name, database_name, collection_name, throughput_update_resource)
Update an Azure Cosmos DB MongoDB collection throughput
cli_cosmosdb_mongodb_collection_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongodb_collection_throughput_migrate(client, resource_group_name, account_name, database_name, collection_name, throughput_type): """Migrate an Azure Cosmos DB MongoDB collection throughput""" if throughput_type == "autoscale": return client.begin_migrate_mongo_db_collection_to_autoscale(resource_group_name, account_name, database_name, collection_name) return client.begin_migrate_mongo_db_collection_to_manual_throughput(resource_group_name, account_name, database_name, collection_name)
Migrate an Azure Cosmos DB MongoDB collection throughput
cli_cosmosdb_mongodb_collection_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_keyspace_throughput_update(client, resource_group_name, account_name, keyspace_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB Cassandra keyspace throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_cassandra_keyspace_throughput(resource_group_name, account_name, keyspace_name, throughput_update_resource)
Update an Azure Cosmos DB Cassandra keyspace throughput
cli_cosmosdb_cassandra_keyspace_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_keyspace_throughput_migrate(client, resource_group_name, account_name, keyspace_name, throughput_type): """Migrate an Azure Cosmos DB Cassandra keyspace throughput""" if throughput_type == "autoscale": return client.begin_migrate_cassandra_keyspace_to_autoscale(resource_group_name, account_name, keyspace_name) return client.begin_migrate_cassandra_keyspace_to_manual_throughput(resource_group_name, account_name, keyspace_name)
Migrate an Azure Cosmos DB Cassandra keyspace throughput
cli_cosmosdb_cassandra_keyspace_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_table_throughput_update(client, resource_group_name, account_name, keyspace_name, table_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB Cassandra table throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_cassandra_table_throughput(resource_group_name, account_name, keyspace_name, table_name, throughput_update_resource)
Update an Azure Cosmos DB Cassandra table throughput
cli_cosmosdb_cassandra_table_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_cassandra_table_throughput_migrate(client, resource_group_name, account_name, keyspace_name, table_name, throughput_type): """Migrate an Azure Cosmos DB Cassandra table throughput""" if throughput_type == "autoscale": return client.begin_migrate_cassandra_table_to_autoscale(resource_group_name, account_name, keyspace_name, table_name) return client.begin_migrate_cassandra_table_to_manual_throughput(resource_group_name, account_name, keyspace_name, table_name)
Migrate an Azure Cosmos DB Cassandra table throughput
cli_cosmosdb_cassandra_table_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_gremlin_database_throughput_update(client, resource_group_name, account_name, database_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB Gremlin database throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_gremlin_database_throughput(resource_group_name, account_name, database_name, throughput_update_resource)
Update an Azure Cosmos DB Gremlin database throughput
cli_cosmosdb_gremlin_database_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_gremlin_database_throughput_migrate(client, resource_group_name, account_name, database_name, throughput_type): """Migrate an Azure Cosmos DB Gremlin database throughput""" if throughput_type == "autoscale": return client.begin_migrate_gremlin_database_to_autoscale(resource_group_name, account_name, database_name) return client.begin_migrate_gremlin_database_to_manual_throughput(resource_group_name, account_name, database_name)
Migrate an Azure Cosmos DB Gremlin database throughput
cli_cosmosdb_gremlin_database_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_gremlin_graph_throughput_update(client, resource_group_name, account_name, database_name, graph_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB Gremlin graph throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_gremlin_graph_throughput(resource_group_name, account_name, database_name, graph_name, throughput_update_resource)
Update an Azure Cosmos DB Gremlin graph throughput
cli_cosmosdb_gremlin_graph_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_gremlin_graph_throughput_migrate(client, resource_group_name, account_name, database_name, graph_name, throughput_type): """Migrate an Azure Cosmos DB Gremlin database throughput""" if throughput_type == "autoscale": return client.begin_migrate_gremlin_graph_to_autoscale(resource_group_name, account_name, database_name, graph_name) return client.begin_migrate_gremlin_graph_to_manual_throughput(resource_group_name, account_name, database_name, graph_name)
Migrate an Azure Cosmos DB Gremlin database throughput
cli_cosmosdb_gremlin_graph_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_table_throughput_update(client, resource_group_name, account_name, table_name, throughput=None, max_throughput=None): """Update an Azure Cosmos DB table throughput""" throughput_update_resource = _get_throughput_settings_update_parameters(throughput, max_throughput) return client.begin_update_table_throughput(resource_group_name, account_name, table_name, throughput_update_resource)
Update an Azure Cosmos DB table throughput
cli_cosmosdb_table_throughput_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_table_throughput_migrate(client, resource_group_name, account_name, table_name, throughput_type): """Migrate an Azure Cosmos DB table throughput""" if throughput_type == "autoscale": return client.begin_migrate_table_to_autoscale(resource_group_name, account_name, table_name) return client.begin_migrate_table_to_manual_throughput(resource_group_name, account_name, table_name)
Migrate an Azure Cosmos DB table throughput
cli_cosmosdb_table_throughput_migrate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_network_rule_list(client, resource_group_name, account_name): """ Lists the virtual network accounts associated with a Cosmos DB account """ cosmos_db_account = client.get(resource_group_name, account_name) return cosmos_db_account.virtual_network_rules
Lists the virtual network accounts associated with a Cosmos DB account
cli_cosmosdb_network_rule_list
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_identity_show(client, resource_group_name, account_name): """ Show the identity associated with a Cosmos DB account """ cosmos_db_account = client.get(resource_group_name, account_name) return cosmos_db_account.identity
Show the identity associated with a Cosmos DB account
cli_cosmosdb_identity_show
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_identity_assign(client, resource_group_name, account_name, identities=None): """ Update the identities associated with a Cosmos DB account """ existing = client.get(resource_group_name, account_name) SYSTEM_ID = '[system]' enable_system = identities is None or SYSTEM_ID in identities new_user_identities = [] if identities is not None: new_user_identities = [x for x in identities if x != SYSTEM_ID] only_enabling_system = enable_system and len(new_user_identities) == 0 system_already_added = existing.identity.type == ResourceIdentityType.system_assigned or existing.identity.type == ResourceIdentityType.system_assigned_user_assigned if only_enabling_system and system_already_added: return existing.identity if existing.identity and existing.identity.type == ResourceIdentityType.system_assigned_user_assigned: identity_type = ResourceIdentityType.system_assigned_user_assigned elif existing.identity and existing.identity.type == ResourceIdentityType.system_assigned and new_user_identities: identity_type = ResourceIdentityType.system_assigned_user_assigned elif existing.identity and existing.identity.type == ResourceIdentityType.user_assigned and enable_system: identity_type = ResourceIdentityType.system_assigned_user_assigned elif new_user_identities and enable_system: identity_type = ResourceIdentityType.system_assigned_user_assigned elif new_user_identities: identity_type = ResourceIdentityType.user_assigned else: identity_type = ResourceIdentityType.system_assigned if identity_type in [ResourceIdentityType.system_assigned, ResourceIdentityType.none]: new_identity = ManagedServiceIdentity(type=identity_type.value) else: new_assigned_identities = existing.identity.user_assigned_identities or {} for identity in new_user_identities: new_assigned_identities[identity] = ManagedServiceIdentityUserAssignedIdentity() new_identity = ManagedServiceIdentity(type=identity_type.value, user_assigned_identities=new_assigned_identities) params = DatabaseAccountUpdateParameters(identity=new_identity) async_cosmos_db_update = client.begin_update(resource_group_name, account_name, params) cosmos_db_account = async_cosmos_db_update.result() return cosmos_db_account.identity
Update the identities associated with a Cosmos DB account
cli_cosmosdb_identity_assign
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_identity_remove(client, resource_group_name, account_name, identities=None): """ Remove the identities associated with a Cosmos DB account """ existing = client.get(resource_group_name, account_name) SYSTEM_ID = '[system]' remove_system_assigned_identity = False if not identities: remove_system_assigned_identity = True elif SYSTEM_ID in identities: remove_system_assigned_identity = True identities.remove(SYSTEM_ID) if existing.identity is None: return ManagedServiceIdentity(type=ResourceIdentityType.none.value) if existing.identity.user_assigned_identities: existing_identities = existing.identity.user_assigned_identities.keys() else: existing_identities = [] if identities: identities_to_remove = identities else: identities_to_remove = [] non_existing = [x for x in identities_to_remove if x not in set(existing_identities)] if non_existing: raise CLIError("'{}' are not associated with '{}'".format(','.join(non_existing), account_name)) identities_remaining = [x for x in existing_identities if x not in set(identities_to_remove)] if remove_system_assigned_identity and ((not existing.identity) or (existing.identity and existing.identity.type in [ResourceIdentityType.none, ResourceIdentityType.user_assigned])): raise CLIError("System-assigned identity is not associated with '{}'".format(account_name)) if identities_remaining and not remove_system_assigned_identity and existing.identity.type == ResourceIdentityType.system_assigned_user_assigned: set_type = ResourceIdentityType.system_assigned_user_assigned elif identities_remaining and remove_system_assigned_identity and existing.identity.type == ResourceIdentityType.system_assigned_user_assigned: set_type = ResourceIdentityType.user_assigned elif identities_remaining and not remove_system_assigned_identity and existing.identity.type == ResourceIdentityType.user_assigned: set_type = ResourceIdentityType.user_assigned elif not identities_remaining and not remove_system_assigned_identity and existing.identity.type == ResourceIdentityType.system_assigned_user_assigned: set_type = ResourceIdentityType.system_assigned elif not identities_remaining and not remove_system_assigned_identity and existing.identity.type == ResourceIdentityType.system_assigned: set_type = ResourceIdentityType.system_assigned else: set_type = ResourceIdentityType.none new_user_identities = {} for identity in identities_remaining: new_user_identities[identity] = ManagedServiceIdentityUserAssignedIdentity() if set_type in [ResourceIdentityType.system_assigned_user_assigned, ResourceIdentityType.user_assigned]: for removed_identity in identities_to_remove: new_user_identities[removed_identity] = None if not new_user_identities: new_user_identities = None params = DatabaseAccountUpdateParameters(identity=ManagedServiceIdentity(type=set_type, user_assigned_identities=new_user_identities)) async_cosmos_db_update = client.begin_update(resource_group_name, account_name, params) cosmos_db_account = async_cosmos_db_update.result() return cosmos_db_account.identity
Remove the identities associated with a Cosmos DB account
cli_cosmosdb_identity_remove
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_network_rule_add(cmd, client, resource_group_name, account_name, subnet, virtual_network=None, ignore_missing_vnet_service_endpoint=False): """ Adds a virtual network rule to an existing Cosmos DB database account """ subnet = _get_virtual_network_id(cmd, resource_group_name, subnet, virtual_network) existing = client.get(resource_group_name, account_name) virtual_network_rules = [] rule_already_exists = False for rule in existing.virtual_network_rules: virtual_network_rules.append( VirtualNetworkRule(id=rule.id, ignore_missing_v_net_service_endpoint=rule.ignore_missing_v_net_service_endpoint)) if rule.id == subnet: rule_already_exists = True logger.warning("The rule exists and will be overwritten") if not rule_already_exists: virtual_network_rules.append( VirtualNetworkRule(id=subnet, ignore_missing_v_net_service_endpoint=ignore_missing_vnet_service_endpoint)) params = DatabaseAccountUpdateParameters(virtual_network_rules=virtual_network_rules) async_docdb_update = client.begin_update(resource_group_name, account_name, params) docdb_account = async_docdb_update.result() docdb_account = client.get(resource_group_name, account_name) # Workaround return docdb_account
Adds a virtual network rule to an existing Cosmos DB database account
cli_cosmosdb_network_rule_add
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_network_rule_remove(cmd, client, resource_group_name, account_name, subnet, virtual_network=None): """ Remove a virtual network rule from an existing Cosmos DB database account """ subnet = _get_virtual_network_id(cmd, resource_group_name, subnet, virtual_network) existing = client.get(resource_group_name, account_name) virtual_network_rules = [] rule_removed = False for rule in existing.virtual_network_rules: if rule.id.lower() != subnet.lower(): virtual_network_rules.append( VirtualNetworkRule(id=rule.id, ignore_missing_v_net_service_endpoint=rule.ignore_missing_v_net_service_endpoint)) else: rule_removed = True if not rule_removed: raise CLIError("This rule does not exist for the Cosmos DB account") params = DatabaseAccountUpdateParameters(virtual_network_rules=virtual_network_rules) async_docdb_update = client.begin_update(resource_group_name, account_name, params) docdb_account = async_docdb_update.result() docdb_account = client.get(resource_group_name, account_name) # Workaround return docdb_account
Remove a virtual network rule from an existing Cosmos DB database account
cli_cosmosdb_network_rule_remove
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def approve_private_endpoint_connection(client, resource_group_name, account_name, private_endpoint_connection_name, description=None): """Approve a private endpoint connection request for Azure Cosmos DB.""" return _update_private_endpoint_connection_status( client, resource_group_name, account_name, private_endpoint_connection_name, is_approved=True, description=description )
Approve a private endpoint connection request for Azure Cosmos DB.
approve_private_endpoint_connection
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def reject_private_endpoint_connection(client, resource_group_name, account_name, private_endpoint_connection_name, description=None): """Reject a private endpoint connection request for Azure Cosmos DB.""" return _update_private_endpoint_connection_status( client, resource_group_name, account_name, private_endpoint_connection_name, is_approved=False, description=description )
Reject a private endpoint connection request for Azure Cosmos DB.
reject_private_endpoint_connection
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_database_exists(client, database_id): """Returns a boolean indicating whether the database exists """ return len(list(client.QueryDatabases( {'query': 'SELECT * FROM root r WHERE r.id=@id', 'parameters': [{'name': '@id', 'value': database_id}]}))) > 0
Returns a boolean indicating whether the database exists
cli_cosmosdb_database_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_database_show(client, database_id): """Shows an Azure Cosmos DB database """ return client.ReadDatabase(_get_database_link(database_id))
Shows an Azure Cosmos DB database
cli_cosmosdb_database_show
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_database_list(client): """Lists all Azure Cosmos DB databases """ return list(client.ReadDatabases())
Lists all Azure Cosmos DB databases
cli_cosmosdb_database_list
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_database_create(client, database_id, throughput=None): """Creates an Azure Cosmos DB database """ return client.CreateDatabase({'id': database_id}, {'offerThroughput': throughput})
Creates an Azure Cosmos DB database
cli_cosmosdb_database_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_database_delete(client, database_id): """Deletes an Azure Cosmos DB database """ client.DeleteDatabase(_get_database_link(database_id))
Deletes an Azure Cosmos DB database
cli_cosmosdb_database_delete
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_collection_exists(client, database_id, collection_id): """Returns a boolean indicating whether the collection exists """ return len(list(client.QueryContainers( _get_database_link(database_id), {'query': 'SELECT * FROM root r WHERE r.id=@id', 'parameters': [{'name': '@id', 'value': collection_id}]}))) > 0
Returns a boolean indicating whether the collection exists
cli_cosmosdb_collection_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_collection_show(client, database_id, collection_id): """Shows an Azure Cosmos DB collection and its offer """ collection = client.ReadContainer(_get_collection_link(database_id, collection_id)) offer = _find_offer(client, collection['_self']) return {'collection': collection, 'offer': offer}
Shows an Azure Cosmos DB collection and its offer
cli_cosmosdb_collection_show
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_collection_list(client, database_id): """Lists all Azure Cosmos DB collections """ return list(client.ReadContainers(_get_database_link(database_id)))
Lists all Azure Cosmos DB collections
cli_cosmosdb_collection_list
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_collection_delete(client, database_id, collection_id): """Deletes an Azure Cosmos DB collection """ client.DeleteContainer(_get_collection_link(database_id, collection_id))
Deletes an Azure Cosmos DB collection
cli_cosmosdb_collection_delete
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_collection_create(client, database_id, collection_id, throughput=None, partition_key_path=None, default_ttl=None, indexing_policy=DEFAULT_INDEXING_POLICY, client_encryption_policy=None, vector_embedding_policy=None): """Creates an Azure Cosmos DB collection """ collection = {'id': collection_id} options = {} if throughput: options['offerThroughput'] = throughput _populate_collection_definition(collection, partition_key_path, default_ttl, indexing_policy, client_encryption_policy, vector_embedding_policy) created_collection = client.CreateContainer(_get_database_link(database_id), collection, options) offer = _find_offer(client, created_collection['_self']) return {'collection': created_collection, 'offer': offer}
Creates an Azure Cosmos DB collection
cli_cosmosdb_collection_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_collection_update(client, database_id, collection_id, throughput=None, default_ttl=None, indexing_policy=None): """Updates an Azure Cosmos DB collection """ logger.debug('reading collection') collection = client.ReadContainer(_get_collection_link(database_id, collection_id)) result = {} if (_populate_collection_definition(collection, None, default_ttl, indexing_policy)): logger.debug('replacing collection') result['collection'] = client.ReplaceContainer( _get_collection_link(database_id, collection_id), collection) if throughput: logger.debug('updating offer') offer = _find_offer(client, collection['_self']) if offer is None: raise CLIError("Cannot find offer for collection {}".format(collection_id)) if 'content' not in offer: offer['content'] = {} offer['content']['offerThroughput'] = throughput result['offer'] = client.ReplaceOffer(offer['_self'], offer) return result
Updates an Azure Cosmos DB collection
cli_cosmosdb_collection_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongo_role_definition_create(client, resource_group_name, account_name, mongo_role_definition_body): '''Creates an Azure Cosmos DB Mongo Role Definition ''' mongo_role_definition_create_resource = MongoRoleDefinitionCreateUpdateParameters( role_name=mongo_role_definition_body['RoleName'], type=mongo_role_definition_body['Type'], database_name=mongo_role_definition_body['DatabaseName'], 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)
Creates an Azure Cosmos DB Mongo Role Definition
cli_cosmosdb_mongo_role_definition_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongo_role_definition_update(client, resource_group_name, account_name, mongo_role_definition_body): '''Update an existing Azure Cosmos DB Mongo Role Definition''' logger.debug('reading Mongo role definition') mongo_role_definition = client.get_mongo_role_definition(mongo_role_definition_body['Id'], resource_group_name, account_name) if mongo_role_definition_body['RoleName'] != mongo_role_definition.role_name: raise CLIError('No Mongo Role Definition found with name [{}].'.format(mongo_role_definition_body['RoleName'])) mongo_role_definition_update_resource = MongoRoleDefinitionCreateUpdateParameters( role_name=mongo_role_definition.role_name, type=mongo_role_definition_body['Type'], database_name=mongo_role_definition_body['DatabaseName'], 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)
Update an existing Azure Cosmos DB Mongo Role Definition
cli_cosmosdb_mongo_role_definition_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongo_role_definition_exists(client, resource_group_name, account_name, mongo_role_definition_id): """Checks if an Azure Cosmos DB Mongo Role Definition exists""" try: client.get_mongo_role_definition(mongo_role_definition_id, resource_group_name, account_name) except ResourceNotFoundError: return False return True
Checks if an Azure Cosmos DB Mongo Role Definition exists
cli_cosmosdb_mongo_role_definition_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongo_user_definition_create(client, resource_group_name, account_name, mongo_user_definition_body): '''Creates an Azure Cosmos DB Mongo User Definition ''' mongo_user_definition_create_resource = MongoUserDefinitionCreateUpdateParameters( user_name=mongo_user_definition_body['UserName'], password=mongo_user_definition_body['Password'], database_name=mongo_user_definition_body['DatabaseName'], custom_data=mongo_user_definition_body['CustomData'], mechanisms=mongo_user_definition_body['Mechanisms'], 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)
Creates an Azure Cosmos DB Mongo User Definition
cli_cosmosdb_mongo_user_definition_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongo_user_definition_update(client, resource_group_name, account_name, mongo_user_definition_body, no_wait=False): '''Update an existing Azure Cosmos DB Mongo User Definition''' logger.debug('reading Mongo user definition') mongo_user_definition = client.get_mongo_user_definition(mongo_user_definition_body['Id'], resource_group_name, account_name) mongo_user_definition_update_resource = MongoUserDefinitionCreateUpdateParameters( user_name=mongo_user_definition.user_name, password=mongo_user_definition_body['Password'], database_name=mongo_user_definition_body['DatabaseName'], custom_data=mongo_user_definition_body['CustomData'], mechanisms=mongo_user_definition_body['Mechanisms'], 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)
Update an existing Azure Cosmos DB Mongo User Definition
cli_cosmosdb_mongo_user_definition_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_mongo_user_definition_exists(client, resource_group_name, account_name, mongo_user_definition_id): """Checks if an Azure Cosmos DB Mongo User Definition exists""" try: client.get_mongo_user_definition(mongo_user_definition_id, resource_group_name, account_name) except ResourceNotFoundError: return False return True
Checks if an Azure Cosmos DB Mongo User Definition exists
cli_cosmosdb_mongo_user_definition_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_role_definition_create(client, resource_group_name, account_name, role_definition_body, no_wait=False): '''Creates an Azure Cosmos DB SQL Role Definition ''' role_definition_create_resource = SqlRoleDefinitionCreateUpdateParameters( role_name=role_definition_body['RoleName'], type=role_definition_body['Type'], assignable_scopes=role_definition_body['AssignableScopes'], permissions=role_definition_body['Permissions']) return sdk_no_wait(no_wait, client.begin_create_update_sql_role_definition, role_definition_body['Id'], resource_group_name, account_name, role_definition_create_resource)
Creates an Azure Cosmos DB SQL Role Definition
cli_cosmosdb_sql_role_definition_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_role_definition_update(client, resource_group_name, account_name, role_definition_body, no_wait=False): '''Update an existing Azure Cosmos DB Sql Role Definition''' logger.debug('reading SQL role definition') role_definition = client.get_sql_role_definition(role_definition_body['Id'], resource_group_name, account_name) if role_definition_body['RoleName'] is not None: role_definition.role_name = role_definition_body['RoleName'] if role_definition_body['AssignableScopes'] is not None: role_definition.assignable_scopes = role_definition_body['AssignableScopes'] if role_definition_body['Permissions'] is not None: role_definition.permissions = role_definition_body['Permissions'] role_definition_update_resource = SqlRoleDefinitionCreateUpdateParameters( role_name=role_definition.role_name, type=role_definition_body['Type'], assignable_scopes=role_definition.assignable_scopes, permissions=role_definition.permissions) return sdk_no_wait(no_wait, client.begin_create_update_sql_role_definition, role_definition_body['Id'], resource_group_name, account_name, role_definition_update_resource)
Update an existing Azure Cosmos DB Sql Role Definition
cli_cosmosdb_sql_role_definition_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_role_definition_exists(client, resource_group_name, account_name, role_definition_id): """Checks if an Azure Cosmos DB Sql Role Definition exists""" try: client.get_sql_role_definition(role_definition_id, resource_group_name, account_name) except ResourceNotFoundError: return False return True
Checks if an Azure Cosmos DB Sql Role Definition exists
cli_cosmosdb_sql_role_definition_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_role_assignment_create(client, resource_group_name, account_name, scope, principal_id, role_assignment_id=None, role_definition_name=None, role_definition_id=None, no_wait=False): """Creates an Azure Cosmos DB Sql Role Assignment""" if role_definition_id is not None and role_definition_name is not None: raise CLIError('Can only provide one out of role_definition_id and role_definition_name.') if role_definition_id is None and role_definition_name is None: raise CLIError('Providing one out of role_definition_id and role_definition_name is required.') if role_definition_name is not None: role_definition_id = get_associated_role_definition_id(client, resource_group_name, account_name, role_definition_name) sql_role_assignment_create_update_parameters = SqlRoleAssignmentCreateUpdateParameters( role_definition_id=role_definition_id, scope=scope, principal_id=principal_id) return sdk_no_wait(no_wait, client.begin_create_update_sql_role_assignment, role_assignment_id, resource_group_name, account_name, sql_role_assignment_create_update_parameters)
Creates an Azure Cosmos DB Sql Role Assignment
cli_cosmosdb_sql_role_assignment_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_role_assignment_update(client, resource_group_name, account_name, role_assignment_id, scope=None, principal_id=None, role_definition_name=None, role_definition_id=None, no_wait=False): """Updates an Azure Cosmos DB Sql Role Assignment""" if role_definition_id is not None and role_definition_name is not None: raise CLIError('Can only provide one out of role_definition_id and role_definition_name.') logger.debug('reading Sql Role Assignment') role_assignment = client.get_sql_role_assignment(role_assignment_id, resource_group_name, account_name) logger.debug('replacing Sql Role Assignment') if role_definition_name is not None: role_definition_id = get_associated_role_definition_id(client, resource_group_name, account_name, role_definition_name) sql_role_assignment_create_update_parameters = SqlRoleAssignmentCreateUpdateParameters( role_definition_id=role_definition_id if role_definition_id is not None else role_assignment.role_definition_id, scope=scope if scope is not None else role_assignment.scope, principal_id=principal_id if principal_id is not None else role_assignment.principal_id) return sdk_no_wait(no_wait, client.begin_create_update_sql_role_assignment, role_assignment_id, resource_group_name, account_name, sql_role_assignment_create_update_parameters)
Updates an Azure Cosmos DB Sql Role Assignment
cli_cosmosdb_sql_role_assignment_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_sql_role_assignment_exists(client, resource_group_name, account_name, role_assignment_id): """Checks if an Azure Cosmos DB Sql Role Assignment exists""" try: client.get_sql_role_assignment(role_assignment_id, resource_group_name, account_name) except ResourceNotFoundError: return False return True
Checks if an Azure Cosmos DB Sql Role Assignment exists
cli_cosmosdb_sql_role_assignment_exists
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_cluster_create(client, resource_group_name, cluster_name, location, delegated_management_subnet_id, tags=None, identity_type='None', cluster_name_override=None, initial_cassandra_admin_password=None, client_certificates=None, external_gossip_certificates=None, external_seed_nodes=None, restore_from_backup_id=None, cassandra_version=None, authentication_method=None, hours_between_backups=None, repair_enabled=None): """Creates an Azure Managed Cassandra Cluster""" if authentication_method != 'None' and initial_cassandra_admin_password is None and external_gossip_certificates is None: raise CLIError('At least one out of the Initial Cassandra Admin Password or External Gossip Certificates is required.') if initial_cassandra_admin_password is not None and external_gossip_certificates is not None: raise CLIError('Only one out of the Initial Cassandra Admin Password or External Gossip Certificates has to be specified.') cluster_properties = ClusterResourceProperties( delegated_management_subnet_id=delegated_management_subnet_id, cluster_name_override=cluster_name_override, initial_cassandra_admin_password=initial_cassandra_admin_password, client_certificates=client_certificates, external_gossip_certificates=external_gossip_certificates, external_seed_nodes=external_seed_nodes, restore_from_backup_id=restore_from_backup_id, cassandra_version=cassandra_version, authentication_method=authentication_method, hours_between_backups=hours_between_backups, repair_enabled=repair_enabled) managed_service_identity_parameter = ManagedCassandraManagedServiceIdentity( type=identity_type ) cluster_resource_create_update_parameters = ClusterResource( location=location, tags=tags, identity=managed_service_identity_parameter, properties=cluster_properties) return client.begin_create_update(resource_group_name, cluster_name, cluster_resource_create_update_parameters)
Creates an Azure Managed Cassandra Cluster
cli_cosmosdb_managed_cassandra_cluster_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_cluster_update(client, resource_group_name, cluster_name, tags=None, identity_type=None, client_certificates=None, external_gossip_certificates=None, external_seed_nodes=None, cassandra_version=None, authentication_method=None, hours_between_backups=None, repair_enabled=None): """Updates an Azure Managed Cassandra Cluster""" cluster_resource = client.get(resource_group_name, cluster_name) if client_certificates is None: client_certificates = cluster_resource.properties.client_certificates if external_gossip_certificates is None: external_gossip_certificates = cluster_resource.properties.external_gossip_certificates if external_seed_nodes is None: external_seed_nodes = cluster_resource.properties.external_seed_nodes if cassandra_version is None: cassandra_version = cluster_resource.properties.cassandra_version if authentication_method is None: authentication_method = cluster_resource.properties.authentication_method if hours_between_backups is None: hours_between_backups = cluster_resource.properties.hours_between_backups if repair_enabled is None: repair_enabled = cluster_resource.properties.repair_enabled if tags is None: tags = cluster_resource.tags identity = cluster_resource.identity if identity_type is not None: identity = ManagedCassandraManagedServiceIdentity(type=identity_type) cluster_properties = ClusterResourceProperties( provisioning_state=cluster_resource.properties.provisioning_state, restore_from_backup_id=cluster_resource.properties.restore_from_backup_id, delegated_management_subnet_id=cluster_resource.properties.delegated_management_subnet_id, cassandra_version=cassandra_version, cluster_name_override=cluster_resource.properties.cluster_name_override, authentication_method=authentication_method, initial_cassandra_admin_password=cluster_resource.properties.initial_cassandra_admin_password, hours_between_backups=hours_between_backups, repair_enabled=repair_enabled, client_certificates=client_certificates, external_gossip_certificates=external_gossip_certificates, gossip_certificates=cluster_resource.properties.gossip_certificates, external_seed_nodes=external_seed_nodes, seed_nodes=cluster_resource.properties.seed_nodes ) cluster_resource_create_update_parameters = ClusterResource( location=cluster_resource.location, tags=tags, identity=identity, properties=cluster_properties) return client.begin_create_update(resource_group_name, cluster_name, cluster_resource_create_update_parameters)
Updates an Azure Managed Cassandra Cluster
cli_cosmosdb_managed_cassandra_cluster_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_cluster_list(client, resource_group_name=None): """List Azure Managed Cassandra Clusters by resource group and subscription.""" if resource_group_name is None: return client.list_by_subscription() return client.list_by_resource_group(resource_group_name)
List Azure Managed Cassandra Clusters by resource group and subscription.
cli_cosmosdb_managed_cassandra_cluster_list
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_cluster_invoke_command(client, resource_group_name, cluster_name, command_name, host, arguments=None, cassandra_stop_start=None, readwrite=None): """Invokes a command in Azure Managed Cassandra Cluster host""" cluster_invoke_command = CommandPostBody( command=command_name, host=host, arguments=arguments, cassandra_stop_start=cassandra_stop_start, readwrite=readwrite ) return client.begin_invoke_command(resource_group_name, cluster_name, cluster_invoke_command)
Invokes a command in Azure Managed Cassandra Cluster host
cli_cosmosdb_managed_cassandra_cluster_invoke_command
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_cluster_status(client, resource_group_name, cluster_name): """Get Azure Managed Cassandra Cluster Node Status""" return client.status(resource_group_name, cluster_name)
Get Azure Managed Cassandra Cluster Node Status
cli_cosmosdb_managed_cassandra_cluster_status
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_cluster_deallocate(client, resource_group_name, cluster_name): """Deallocate Azure Managed Cassandra Cluster""" return client.begin_deallocate(resource_group_name, cluster_name)
Deallocate Azure Managed Cassandra Cluster
cli_cosmosdb_managed_cassandra_cluster_deallocate
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_cluster_start(client, resource_group_name, cluster_name): """Start Azure Managed Cassandra Cluster""" return client.begin_start(resource_group_name, cluster_name)
Start Azure Managed Cassandra Cluster
cli_cosmosdb_managed_cassandra_cluster_start
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_datacenter_create(client, resource_group_name, cluster_name, data_center_name, data_center_location, delegated_subnet_id, node_count, base64_encoded_cassandra_yaml_fragment=None, managed_disk_customer_key_uri=None, backup_storage_customer_key_uri=None, sku=None, disk_sku=None, disk_capacity=None, availability_zone=None): """Creates an Azure Managed Cassandra DataCenter""" data_center_properties = DataCenterResourceProperties( data_center_location=data_center_location, delegated_subnet_id=delegated_subnet_id, node_count=node_count, base64_encoded_cassandra_yaml_fragment=base64_encoded_cassandra_yaml_fragment, sku=sku, disk_sku=disk_sku, disk_capacity=disk_capacity, availability_zone=availability_zone, managed_disk_customer_key_uri=managed_disk_customer_key_uri, backup_storage_customer_key_uri=backup_storage_customer_key_uri ) data_center_resource = DataCenterResource( properties=data_center_properties ) return client.begin_create_update(resource_group_name, cluster_name, data_center_name, data_center_resource)
Creates an Azure Managed Cassandra DataCenter
cli_cosmosdb_managed_cassandra_datacenter_create
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def cli_cosmosdb_managed_cassandra_datacenter_update(client, resource_group_name, cluster_name, data_center_name, node_count=None, sku=None, base64_encoded_cassandra_yaml_fragment=None, managed_disk_customer_key_uri=None, backup_storage_customer_key_uri=None): """Updates an Azure Managed Cassandra DataCenter""" data_center_resource = client.get(resource_group_name, cluster_name, data_center_name) if node_count is None: node_count = data_center_resource.properties.node_count if sku is None: sku = data_center_resource.properties.sku if base64_encoded_cassandra_yaml_fragment is None: base64_encoded_cassandra_yaml_fragment = data_center_resource.properties.base64_encoded_cassandra_yaml_fragment if managed_disk_customer_key_uri is None: managed_disk_customer_key_uri = data_center_resource.properties.managed_disk_customer_key_uri if backup_storage_customer_key_uri is None: backup_storage_customer_key_uri = data_center_resource.properties.backup_storage_customer_key_uri data_center_properties = DataCenterResourceProperties( data_center_location=data_center_resource.properties.data_center_location, delegated_subnet_id=data_center_resource.properties.delegated_subnet_id, node_count=node_count, sku=sku, seed_nodes=data_center_resource.properties.seed_nodes, base64_encoded_cassandra_yaml_fragment=base64_encoded_cassandra_yaml_fragment, managed_disk_customer_key_uri=managed_disk_customer_key_uri, backup_storage_customer_key_uri=backup_storage_customer_key_uri ) data_center_resource = DataCenterResource( properties=data_center_properties ) return client.begin_create_update(resource_group_name, cluster_name, data_center_name, data_center_resource)
Updates an Azure Managed Cassandra DataCenter
cli_cosmosdb_managed_cassandra_datacenter_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
MIT
def _create_cosmosdb_command(self, name, method_name=None, command_type_name=None, **kwargs): """Registers an Azure CLI Cosmos DB Data Plane command. These commands always include the parameters which can be used to obtain a cosmosdb client.""" merged_kwargs = self._flatten_kwargs(kwargs, command_type_name) if 'exception_handler' not in merged_kwargs: from ._exception_handler import generic_exception_handler merged_kwargs['exception_handler'] = generic_exception_handler if command_type_name == 'command_type': command_name = self.command(name, method_name, **merged_kwargs) else: command_name = self.custom_command(name, method_name, **merged_kwargs) command = self.command_loader.command_table[command_name] # add parameters required to create a cosmosdb client group_name = 'Cosmos DB Account' command.add_argument('db_resource_group_name', '--resource-group-name', '-g', arg_group=group_name, help='name of the resource group. Must be used in conjunction with ' 'cosmosdb account name.') command.add_argument('db_account_name', '--name', '-n', arg_group=group_name, help='Cosmos DB account name. Must be used in conjunction with ' 'either name of the resource group or cosmosdb account key.') command.add_argument('db_account_key', '--key', required=False, default=None, arg_group=group_name, help='Cosmos DB account key. Must be used in conjunction with cosmosdb ' 'account name or url-connection.') command.add_argument('db_url_connection', '--url-connection', required=False, default=None, arg_group=group_name, help='Cosmos DB account url connection. Must be used in conjunction with ' 'cosmosdb account key.')
Registers an Azure CLI Cosmos DB Data Plane command. These commands always include the parameters which can be used to obtain a cosmosdb client.
_create_cosmosdb_command
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/cosmosdb/_command_type.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/cosmosdb/_command_type.py
MIT
def _test_PrivateDnsZone(self, zone_name, filename): """ This tests that a zone file can be imported, exported, and re-imported without any changes to the record sets. It does not test that the imported files meet any specific requirements. For that, run additional checks in the individual zone file tests. """ self.kwargs.update({ 'zone': zone_name, 'path': os.path.join(TEST_DIR, 'zone_files', filename), 'export': os.path.join(TEST_DIR, 'zone_files', filename + '_export.txt') }) # Import from zone file self.cmd('network private-dns zone import -n {zone} -g {rg} --file-name "{path}"') records1 = self.cmd('network private-dns record-set list -g {rg} -z {zone}').get_output_in_json() # Export zone file and delete the zone self.cmd('network private-dns zone export -g {rg} -n {zone} --file-name "{export}"') self.cmd('network private-dns zone delete -g {rg} -n {zone} -y') time.sleep(10) for i in range(5): try: # Reimport zone file and verify both record sets are equivalent self.cmd('network private-dns zone import -n {zone} -g {rg} --file-name "{export}"') break except: if i == 4: raise time.sleep(10) records2 = self.cmd('network private-dns record-set list -g {rg} -z {zone}').get_output_in_json() # verify that each record in the original import is unchanged after export/re-import self._check_records(records1, records2)
This tests that a zone file can be imported, exported, and re-imported without any changes to the record sets. It does not test that the imported files meet any specific requirements. For that, run additional checks in the individual zone file tests.
_test_PrivateDnsZone
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/privatedns/tests/latest/test_privatedns_commands.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/privatedns/tests/latest/test_privatedns_commands.py
MIT
def _get_resource_group_from_server_name(cli_ctx, server_name): """ Fetch resource group from server name :param str server_name: name of the server :return: resource group name or None :rtype: str """ client = get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RDBMS).servers for server in client.list(): id_comps = parse_resource_id(server.id) if id_comps['name'] == server_name: return id_comps['resource_group'] return None
Fetch resource group from server name :param str server_name: name of the server :return: resource group name or None :rtype: str
_get_resource_group_from_server_name
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/mysql/_validators.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/mysql/_validators.py
MIT
def _validate_ip(ips): """ # Regex not working for re.(regex, '255.255.255.255'). Hence commenting it out for now regex = r'^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$' """ parsed_input = ips.split('-') if len(parsed_input) == 1: return _validate_ranges_in_ip(parsed_input[0]) if len(parsed_input) == 2: return _validate_ranges_in_ip(parsed_input[0]) and _validate_ranges_in_ip(parsed_input[1]) return False
# Regex not working for re.(regex, '255.255.255.255'). Hence commenting it out for now regex = r'^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?).( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'
_validate_ip
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/mysql/_validators.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/mysql/_validators.py
MIT
def flexible_server_advanced_threat_protection_update(cmd, client, resource_group_name, server_name, state): ''' Updates an advanced threat protection setting. Custom update function to apply parameters to instance. ''' parameters = { 'state': state } return client.begin_update(resource_group_name, server_name, models.AdvancedThreatProtectionName.DEFAULT.value, parameters)
Updates an advanced threat protection setting. Custom update function to apply parameters to instance.
flexible_server_advanced_threat_protection_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/mysql/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/mysql/custom.py
MIT
def flexible_server_advanced_threat_protection_show(cmd, client, resource_group_name, server_name): ''' Gets an advanced threat protection setting. ''' return client.get(resource_group_name, server_name, models.AdvancedThreatProtectionName.DEFAULT.value)
Gets an advanced threat protection setting.
flexible_server_advanced_threat_protection_show
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/mysql/custom.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/mysql/custom.py
MIT
def get_account_info(self, group, name): """Returns the storage account name and key in a tuple""" return name, self.get_account_key(group, name)
Returns the storage account name and key in a tuple
get_account_info
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/mysql/tests/latest/test_mysql_scenario.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/mysql/tests/latest/test_mysql_scenario.py
MIT
def _arm_get_resource_by_name(cli_ctx, resource_name, resource_type): """Returns the ARM resource in the current subscription with resource_name. :param str resource_name: The name of resource :param str resource_type: The type of resource """ result = get_resources_in_subscription(cli_ctx, resource_type) elements = [item for item in result if item.name.lower() == resource_name.lower()] if not elements: from azure.cli.core._profile import Profile profile = Profile(cli_ctx=cli_ctx) message = "The resource with name '{}' and type '{}' could not be found".format( resource_name, resource_type) try: subscription = profile.get_subscription( cli_ctx.data['subscription_id']) raise ResourceNotFound( "{} in subscription '{} ({})'.".format(message, subscription['name'], subscription['id'])) except (KeyError, TypeError) as e: logger.debug( "Could not get the current subscription. Exception: %s", str(e)) raise ResourceNotFound( "{} in the current subscription.".format(message)) elif len(elements) == 1: return elements[0] else: raise CLIError( "More than one resources with type '{}' are found with name '{}'.".format( resource_type, resource_name))
Returns the ARM resource in the current subscription with resource_name. :param str resource_name: The name of resource :param str resource_type: The type of resource
_arm_get_resource_by_name
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def _get_resource_group_name_by_resource_id(resource_id): """Returns the resource group name from parsing the resource id. :param str resource_id: The resource id """ resource_id = resource_id.lower() resource_group_keyword = '/resourcegroups/' return resource_id[resource_id.index(resource_group_keyword) + len( resource_group_keyword): resource_id.index('/providers/')]
Returns the resource group name from parsing the resource id. :param str resource_id: The resource id
_get_resource_group_name_by_resource_id
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_resource_group_name_by_registry_name(cli_ctx, registry_name, resource_group_name=None): """Returns the resource group name for the container registry. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group """ if not resource_group_name: arm_resource = _arm_get_resource_by_name( cli_ctx, registry_name, REGISTRY_RESOURCE_TYPE) resource_group_name = _get_resource_group_name_by_resource_id( arm_resource.id) return resource_group_name
Returns the resource group name for the container registry. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group
get_resource_group_name_by_registry_name
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_resource_id_by_registry_name(cli_ctx, registry_name): """Returns the resource id for the container registry. :param str storage_account_name: The name of container registry """ arm_resource = _arm_get_resource_by_name( cli_ctx, registry_name, REGISTRY_RESOURCE_TYPE) return arm_resource.id
Returns the resource id for the container registry. :param str storage_account_name: The name of container registry
get_resource_id_by_registry_name
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_registry_by_name(cli_ctx, registry_name, resource_group_name=None): """Returns a tuple of Registry object and resource group name. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group """ resource_group_name = get_resource_group_name_by_registry_name( cli_ctx, registry_name, resource_group_name) client = cf_acr_registries(cli_ctx) return client.get(resource_group_name, registry_name), resource_group_name
Returns a tuple of Registry object and resource group name. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group
get_registry_by_name
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_registry_from_name_or_login_server(cli_ctx, login_server, registry_name=None): """Returns a Registry object for the specified name. :param str name: either the registry name or the login server of the registry. """ client = cf_acr_registries(cli_ctx) registry_list = client.list() if registry_name: elements = [item for item in registry_list if item.login_server.lower() == login_server.lower() or item.name.lower() == registry_name.lower()] else: elements = [item for item in registry_list if item.login_server.lower() == login_server.lower()] if len(elements) == 1: return elements[0] if len(elements) > 1: logger.warning( "More than one registries were found by %s.", login_server) return None
Returns a Registry object for the specified name. :param str name: either the registry name or the login server of the registry.
get_registry_from_name_or_login_server
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def validate_managed_registry(cmd, registry_name, resource_group_name=None, message=None): """Raise CLIError if the registry in not in Managed SKU. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group """ registry, resource_group_name = get_registry_by_name( cmd.cli_ctx, registry_name, resource_group_name) if not registry.sku or registry.sku.name not in get_managed_sku(cmd): raise CLIError( message or "This operation is only supported for managed registries.") return registry, resource_group_name
Raise CLIError if the registry in not in Managed SKU. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group
validate_managed_registry
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def validate_premium_registry(cmd, registry_name, resource_group_name=None, message=None): """Raise CLIError if the registry in not in Premium SKU. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group """ registry, resource_group_name = get_registry_by_name( cmd.cli_ctx, registry_name, resource_group_name) if not registry.sku or registry.sku.name not in get_premium_sku(cmd): raise CLIError( message or "This operation is only supported for managed registries in Premium SKU.") return registry, resource_group_name
Raise CLIError if the registry in not in Premium SKU. :param str registry_name: The name of container registry :param str resource_group_name: The name of resource group
validate_premium_registry
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def validate_sku_update(cmd, current_sku, sku_parameter): """Validates a registry SKU update parameter. :param object sku_parameter: The registry SKU update parameter """ if sku_parameter is None: return Sku = cmd.get_models('Sku') if isinstance(sku_parameter, dict): if 'name' not in sku_parameter: _invalid_sku_update(cmd) if sku_parameter['name'] not in get_classic_sku(cmd) and sku_parameter['name'] not in get_managed_sku(cmd): _invalid_sku_update(cmd) if current_sku in get_managed_sku(cmd) and sku_parameter['name'] in get_classic_sku(cmd): _invalid_sku_downgrade() elif isinstance(sku_parameter, Sku): if current_sku in get_managed_sku(cmd) and sku_parameter.name in get_classic_sku(cmd): _invalid_sku_downgrade() else: _invalid_sku_update(cmd)
Validates a registry SKU update parameter. :param object sku_parameter: The registry SKU update parameter
validate_sku_update
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_validate_platform(cmd, platform): """Gets and validates the Platform from both flags :param str platform: The name of Platform passed by user in --platform flag """ OS, Architecture = cmd.get_models('OS', 'Architecture', operation_group='runs') # Defaults platform_os = OS.linux.value platform_arch = Architecture.amd64.value platform_variant = None if platform: platform_split = platform.split('/') platform_os = platform_split[0] platform_arch = platform_split[1] if len(platform_split) > 1 else Architecture.amd64.value platform_variant = platform_split[2] if len(platform_split) > 2 else None platform_os = platform_os.lower() platform_arch = platform_arch.lower() valid_os = get_valid_os(cmd) valid_arch = get_valid_architecture(cmd) valid_variant = get_valid_variant(cmd) if platform_os not in valid_os: raise CLIError( "'{0}' is not a valid value for OS specified in --platform. " "Valid options are {1}.".format(platform_os, ','.join(valid_os)) ) if platform_arch not in valid_arch: raise CLIError( "'{0}' is not a valid value for Architecture specified in --platform. " "Valid options are {1}.".format( platform_arch, ','.join(valid_arch)) ) if platform_variant and (platform_variant not in valid_variant): raise CLIError( "'{0}' is not a valid value for Variant specified in --platform. " "Valid options are {1}.".format( platform_variant, ','.join(valid_variant)) ) return platform_os, platform_arch, platform_variant
Gets and validates the Platform from both flags :param str platform: The name of Platform passed by user in --platform flag
get_validate_platform
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_yaml_template(cmd_value, timeout, file): """Generates yaml template :param str cmd_value: The command to execute in each step. Task version defaults to v1.1.0 :param str timeout: The timeout for each step :param str file: The task definition """ yaml_template = "version: v1.1.0\n" if cmd_value: yaml_template += "steps: \n - cmd: {0}\n disableWorkingDirectoryOverride: true\n".format(cmd_value) if timeout: yaml_template += " timeout: {0}\n".format(timeout) else: if not file: file = ACR_TASK_YAML_DEFAULT_NAME if file == "-": import sys for s in sys.stdin.readlines(): yaml_template += s else: if os.path.exists(file): f = open(file, 'r') for line in f: yaml_template += line else: raise CLIError("{0} does not exist.".format(file)) if not yaml_template: raise CLIError("Failed to initialize yaml template.") return yaml_template
Generates yaml template :param str cmd_value: The command to execute in each step. Task version defaults to v1.1.0 :param str timeout: The timeout for each step :param str file: The task definition
get_yaml_template
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_custom_registry_credentials(cmd, auth_mode=None, login_server=None, username=None, password=None, identity=None, is_remove=False): """Get the credential object from the input :param str auth_mode: The login mode for the source registry :param str login_server: The login server of custom registry :param str username: The username for custom registry (plain text or a key vault secret URI) :param str password: The password for custom registry (plain text or a key vault secret URI) :param str identity: The task managed identity used for the credential """ Credentials, CustomRegistryCredentials, SourceRegistryCredentials, SecretObject, \ SecretObjectType = cmd.get_models( 'Credentials', 'CustomRegistryCredentials', 'SourceRegistryCredentials', 'SecretObject', 'SecretObjectType', operation_group='tasks') source_registry_credentials = None if auth_mode: source_registry_credentials = SourceRegistryCredentials( login_mode=auth_mode) custom_registries = None if login_server: # if null username and password (or identity), then remove the credential custom_reg_credential = None is_identity_credential = False if not username and not password: is_identity_credential = identity is not None if not is_remove: if is_identity_credential: custom_reg_credential = CustomRegistryCredentials( identity=identity ) else: custom_reg_credential = CustomRegistryCredentials( user_name=SecretObject( type=SecretObjectType.vaultsecret if is_vault_secret( cmd, username)else SecretObjectType.opaque, value=username ), password=SecretObject( type=SecretObjectType.vaultsecret if is_vault_secret( cmd, password) else SecretObjectType.opaque, value=password ), identity=identity ) custom_registries = {login_server: custom_reg_credential} return Credentials( source_registry=source_registry_credentials, custom_registries=custom_registries )
Get the credential object from the input :param str auth_mode: The login mode for the source registry :param str login_server: The login server of custom registry :param str username: The username for custom registry (plain text or a key vault secret URI) :param str password: The password for custom registry (plain text or a key vault secret URI) :param str identity: The task managed identity used for the credential
get_custom_registry_credentials
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def remove_timer_trigger(task_name, timer_name, timer_triggers): """Remove the timer trigger from the list of existing timer triggers for a task. :param str task_name: The name of the task :param str timer_name: The name of the timer trigger to be removed :param str timer_triggers: The list of existing timer_triggers for a task """ if not timer_triggers: raise CLIError("No timer triggers exist for the task '{}'.".format(task_name)) # Check that the timer trigger exists in the list and if not exit if any(timer.name == timer_name for timer in timer_triggers): for timer in timer_triggers: if timer.name == timer_name: timer_triggers.remove(timer) else: raise CLIError("The timer '{}' does not exist for the task '{}'.".format(timer_name, task_name)) return timer_triggers
Remove the timer trigger from the list of existing timer triggers for a task. :param str task_name: The name of the task :param str timer_name: The name of the timer trigger to be removed :param str timer_triggers: The list of existing timer_triggers for a task
remove_timer_trigger
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def get_task_details_by_name(cli_ctx, resource_group_name, registry_name, task_name): """Returns the task details. :param str resource_group_name: The name of resource group :param str registry_name: The name of container registry :param str task_name: The name of task """ from ._client_factory import cf_acr_tasks client = cf_acr_tasks(cli_ctx) return client.get_details(resource_group_name, registry_name, task_name)
Returns the task details. :param str resource_group_name: The name of resource group :param str registry_name: The name of container registry :param str task_name: The name of task
get_task_details_by_name
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_utils.py
MIT
def __init__( self, *, virtual_network_resource_id: str, action: Optional[Union[str, "Action"]] = None, # noqa: F821 **kwargs ): """ :keyword action: The action of virtual network rule. Possible values include: "Allow". :paramtype action: str or ~azure.mgmt.containerregistry.v2021_08_01_preview.models.Action :keyword virtual_network_resource_id: Required. Resource ID of a subnet, for example: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/ providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName}.' :paramtype virtual_network_resource_id: str """ super().__init__(**kwargs) self.action = action self.virtual_network_resource_id = virtual_network_resource_id
:keyword action: The action of virtual network rule. Possible values include: "Allow". :paramtype action: str or ~azure.mgmt.containerregistry.v2021_08_01_preview.models.Action :keyword virtual_network_resource_id: Required. Resource ID of a subnet, for example: '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/ providers/Microsoft.Network/virtualNetworks/{vnetName}/subnets/{subnetName}.' :paramtype virtual_network_resource_id: str
__init__
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/network_rule.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/network_rule.py
MIT
def acr_cache_update_get(cmd): """Returns an empty CacheRuleUpdateParameters object. """ CacheRuleUpdateParameters = cmd.get_models('CacheRuleUpdateParameters', operation_group='cache_rules') return CacheRuleUpdateParameters()
Returns an empty CacheRuleUpdateParameters object.
acr_cache_update_get
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/cache.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/cache.py
MIT
def validate_headers(namespace): """Extracts multiple space-separated headers in key[=value] format. """ if isinstance(namespace.headers, list): headers_dict = {} for item in namespace.headers: headers_dict.update(validate_header(item)) namespace.headers = headers_dict
Extracts multiple space-separated headers in key[=value] format.
validate_headers
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_validators.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_validators.py
MIT
def validate_header(string): """Extracts a single header in key[=value] format. """ result = {} if string: comps = string.split('=', 1) result = {comps[0]: comps[1]} if len(comps) > 1 else {string: ''} return result
Extracts a single header in key[=value] format.
validate_header
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_validators.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_validators.py
MIT
def validate_task_value(string, is_secret): """Extracts a single SetValue in key[=value] format. """ if string: comps = string.split('=', 1) if len(comps) > 1: return {'type': 'SetValue', 'name': comps[0], 'value': comps[1], 'isSecret': is_secret} return {'type': 'SetValue', 'name': comps[0], 'value': '', 'isSecret': is_secret} return None
Extracts a single SetValue in key[=value] format.
validate_task_value
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_validators.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_validators.py
MIT
def validate_task_argument(string, is_secret): """Extracts a single argument in key[=value] format. """ if string: comps = string.split('=', 1) if len(comps) > 1: return {'type': 'Argument', 'name': comps[0], 'value': comps[1], 'isSecret': is_secret} # If no value, check if the argument exists as an environment variable local_value = os.environ.get(comps[0]) if local_value is not None: return {'type': 'Argument', 'name': comps[0], 'value': local_value, 'isSecret': is_secret} return {'type': 'Argument', 'name': comps[0], 'value': '', 'isSecret': is_secret} return None
Extracts a single argument in key[=value] format.
validate_task_argument
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_validators.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_validators.py
MIT
def validate_registry_name(cmd, namespace): """Omit login server endpoint suffix.""" registry = namespace.registry_name if registry is None: return suffixes = cmd.cli_ctx.cloud.suffixes # Some clouds do not define 'acr_login_server_endpoint' (e.g. AzureGermanCloud) if registry and hasattr(suffixes, 'acr_login_server_endpoint'): acr_suffix = suffixes.acr_login_server_endpoint pos = registry.find(acr_suffix) if pos > 0: logger.warning("The login server endpoint suffix '%s' is automatically omitted.", acr_suffix) namespace.registry_name = registry[:pos] registry = registry[:pos] # If registry contains '-' due to Domain Name Label Scope, # ex: "myregistry-dnlhash123.azurecr.io", strip "-dnlhash123" dnl_hash = registry.find("-") if registry and dnl_hash > 0: logger.warning( "The domain name label suffix '%s' is automatically omitted. Registry name is %s.", registry[dnl_hash:], registry[:dnl_hash]) namespace.registry_name = registry[:dnl_hash] registry = namespace.registry_name if not re.match(ACR_NAME_VALIDATION_REGEX, registry): raise InvalidArgumentValueError(BAD_REGISTRY_NAME)
Omit login server endpoint suffix.
validate_registry_name
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_validators.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_validators.py
MIT
def _get_repository_path(repository=None): """Return the path for a repository, or list of repositories if repository is empty. """ if repository: return '/acr/v1/{}'.format(repository) return '/acr/v1/_catalog'
Return the path for a repository, or list of repositories if repository is empty.
_get_repository_path
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/repository.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/repository.py
MIT
def _get_tag_path(repository, tag=None): """Return the path for a tag, or list of tags if tag is empty. """ if tag: return '/acr/v1/{}/_tags/{}'.format(repository, tag) return '/acr/v1/{}/_tags'.format(repository)
Return the path for a tag, or list of tags if tag is empty.
_get_tag_path
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/repository.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/repository.py
MIT
def _get_manifest_path(repository, manifest=None): """Return the path for a manifest, or list of manifests if manifest is empty. """ if manifest: return '/acr/v1/{}/_manifests/{}'.format(repository, manifest) return '/acr/v1/{}/_manifests'.format(repository)
Return the path for a manifest, or list of manifests if manifest is empty.
_get_manifest_path
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/repository.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/repository.py
MIT
def _get_aad_token(cli_ctx, login_server, only_refresh_token, repository=None, artifact_repository=None, permission=None, is_diagnostics_context=False, use_acr_audience=False): """Obtains refresh and access tokens for an AAD-enabled registry. :param str login_server: The registry login server URL to log in to :param bool only_refresh_token: Whether to ask for only refresh token, or for both refresh and access tokens :param str repository: Repository for which the access token is requested :param str artifact_repository: Artifact repository for which the access token is requested :param str permission: The requested permission on the repository, '*' or 'pull' """ token_params = _handle_challenge_phase( login_server, repository, artifact_repository, permission, True, is_diagnostics_context ) from ._errors import ErrorClass if isinstance(token_params, ErrorClass): if is_diagnostics_context: return token_params raise CLIError(token_params.get_error_message()) return _get_aad_token_after_challenge(cli_ctx, token_params, login_server, only_refresh_token, repository, artifact_repository, permission, is_diagnostics_context, use_acr_audience)
Obtains refresh and access tokens for an AAD-enabled registry. :param str login_server: The registry login server URL to log in to :param bool only_refresh_token: Whether to ask for only refresh token, or for both refresh and access tokens :param str repository: Repository for which the access token is requested :param str artifact_repository: Artifact repository for which the access token is requested :param str permission: The requested permission on the repository, '*' or 'pull'
_get_aad_token
python
Azure/azure-cli
src/azure-cli/azure/cli/command_modules/acr/_docker_utils.py
https://github.com/Azure/azure-cli/blob/master/src/azure-cli/azure/cli/command_modules/acr/_docker_utils.py
MIT