Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cosmos DB] Add Sql stored procedure, udf and trigger cmdlets #11999

Merged
merged 9 commits into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,98 @@
short-summary: Manage SQL resources of Azure Cosmos DB account.
"""

helps['cosmosdb sql stored-procedure'] = """
type: group
short-summary: Manage Azure Cosmos DB SQL stored procedures.
"""

helps['cosmosdb sql stored-procedure create'] = """
type: command
short-summary: Create an SQL stored procedure under an Azure Cosmos DB SQL container.
examples:
- name: Create an Azure Cosmos DB SQL stored procedure.
text: az cosmosdb sql stored-procedure create -g MyResourceGroup -a MyAccount -d MyDatabase -c MyContainer -n MyStoredProcedure -b StoredProcedureBody
crafted: true
"""

helps['cosmosdb sql stored-procedure delete'] = """
type: command
short-summary: Delete the SQL stored procedure under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql stored-procedure list'] = """
type: command
short-summary: List the SQL stored procedures under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql stored-procedure show'] = """
type: command
short-summary: Show the details of a SQL stored procedure under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql'] = """
type: group
short-summary: Manage SQL resources of Azure Cosmos DB account.
"""

helps['cosmosdb sql trigger'] = """
type: group
short-summary: Manage Azure Cosmos DB SQL triggers.
"""

helps['cosmosdb sql trigger create'] = """
type: command
short-summary: Create an SQL trigger under an Azure Cosmos DB SQL container.
examples:
- name: Create an Azure Cosmos DB SQL trigger.
text: az cosmosdb sql trigger create -g MyResourceGroup -a MyAccount -d MyDatabase -c MyContainer -n MyTrigger -b TriggerBody
crafted: true
"""

helps['cosmosdb sql trigger delete'] = """
type: command
short-summary: Delete the SQL trigger under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql trigger list'] = """
type: command
short-summary: List the SQL triggers under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql trigger show'] = """
type: command
short-summary: Show the details of a SQL trigger under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql user-defined-function'] = """
type: group
short-summary: Manage Azure Cosmos DB SQL user defined functions.
"""

helps['cosmosdb sql user-defined-function create'] = """
type: command
short-summary: Create an SQL user defined function under an Azure Cosmos DB SQL container.
examples:
- name: Create an Azure Cosmos DB SQL user defined function.
text: az cosmosdb sql user-defined-function create -g MyResourceGroup -a MyAccount -d MyDatabase -c MyContainer -n MyUserDefinedFunction -b UserDefinedFunctionBody
crafted: true
"""

helps['cosmosdb sql user-defined-function delete'] = """
type: command
short-summary: Delete the SQL user defined function under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql user-defined-function list'] = """
type: command
short-summary: List the SQL user defined functions under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql user-defined-function show'] = """
type: command
short-summary: Show the details of a SQL user defined function under an Azure Cosmos DB SQL container.
"""

helps['cosmosdb sql container'] = """
type: group
short-summary: Manage Azure Cosmos DB SQL containers.
Expand Down
82 changes: 56 additions & 26 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@


def load_arguments(self, _):

from azure.mgmt.cosmosdb.models import KeyKind, DefaultConsistencyLevel, DatabaseAccountKind
from knack.arguments import CLIArgumentType
from azure.mgmt.cosmosdb.models import KeyKind, DefaultConsistencyLevel, DatabaseAccountKind, TriggerType, TriggerOperation

with self.argument_context('cosmosdb') as c:
c.argument('account_name', arg_type=name_type, help='Name of the Cosmos DB database account', completer=get_resource_name_completion_list('Microsoft.DocumentDb/databaseAccounts'), id_part='name')
Expand Down Expand Up @@ -97,16 +97,20 @@ def load_arguments(self, _):
with self.argument_context('cosmosdb database') as c:
c.argument('throughput', type=int, help='Offer Throughput (RU/s)')

account_name_type = CLIArgumentType(options_list=['--account-name', '-a'], help="Cosmosdb account name.")
database_name_type = CLIArgumentType(options_list=['--database-name', '-d'], help='Database name.')
container_name_type = CLIArgumentType(options_list=['--container-name', '-c'], help='Container name.')

# SQL database
with self.argument_context('cosmosdb sql database') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', help='The throughput of SQL database (RU/s). Default value is 400')

# SQL container
with self.argument_context('cosmosdb sql container') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('container_name', options_list=['--name', '-n'], help="Container name")
c.argument('partition_key_path', options_list=['--partition-key-path', '-p'], help='Partition Key Path, e.g., \'/address/zipcode\'')
c.argument('default_ttl', options_list=['--ttl'], type=int, help='Default TTL. If the value is missing or set to "-1", items don’t expire. If the value is set to "n", items will expire "n" seconds after last modified time.')
Expand All @@ -115,28 +119,54 @@ def load_arguments(self, _):
c.argument('conflict_resolution_policy', options_list=['--conflict-resolution-policy', '-c'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Conflict Resolution Policy, you can enter it as a string or as a file, e.g., --conflict-resolution-policy @policy-file.json or ' + SQL_GREMLIN_CONFLICT_RESOLUTION_POLICY_EXAMPLE)
c.argument('throughput', help='The throughput of SQL container (RU/s). Default value is 400')

# SQL stored procedure
with self.argument_context('cosmosdb sql stored-procedure') as c:
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('container_name', container_name_type)
c.argument('stored_procedure_name', options_list=['--name', '-n'], help="StoredProcedure name")
c.argument('stored_procedure_body', options_list=['--body', '-b'], completer=FilesCompleter(), help="StoredProcedure body, you can enter it as a string or as a file, e.g., --body @sprocbody-file.json")

# SQL trigger
with self.argument_context('cosmosdb sql trigger') as c:
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('container_name', container_name_type)
c.argument('trigger_name', options_list=['--name', '-n'], help="Trigger name")
c.argument('trigger_body', options_list=['--body', '-b'], completer=FilesCompleter(), help="Trigger body, you can enter it as a string or as a file, e.g., --body @triggerbody-file.json")
c.argument('trigger_type', options_list=['--type', '-t'], arg_type=get_enum_type(TriggerType), help="Trigger type, values can be: Pre or Post")
MehaKaushik marked this conversation as resolved.
Show resolved Hide resolved
c.argument('trigger_operation', options_list=['--operation'], arg_type=get_enum_type(TriggerOperation), help="The operation of the trigger. Values can be: All, Create, Update, Delete, Replace")
MehaKaushik marked this conversation as resolved.
Show resolved Hide resolved

# SQL user defined function
with self.argument_context('cosmosdb sql user-defined-function') as c:
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('container_name', container_name_type)
c.argument('user_defined_function_name', options_list=['--name', '-n'], help="UserDefinedFunction name")
c.argument('user_defined_function_body', options_list=['--body', '-b'], completer=FilesCompleter(), help="UserDefinedFunction body, you can enter it as a string or as a file, e.g., --body @udfbody-file.json")

# MongoDB
with self.argument_context('cosmosdb mongodb database') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', help='The throughput of MongoDB database (RU/s). Default value is 400')

with self.argument_context('cosmosdb mongodb collection') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('collection_name', options_list=['--name', '-n'], help="Collection name")
c.argument('shard_key_path', options_list=['--shard'], help="Sharding key path.")
c.argument('indexes', options_list=['--idx'], type=shell_safe_json_parse, completer=FilesCompleter(), help='Indexes, you can enter it as a string or as a file, e.g., --idx @indexes-file.json or ' + MONGODB_INDEXES_EXAMPLE)
c.argument('throughput', help='The throughput of MongoDB collection (RU/s). Default value is 400')

# Cassandra
with self.argument_context('cosmosdb cassandra keyspace') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('keyspace_name', options_list=['--name', '-n'], help="Keyspace name")
c.argument('throughput', help='The throughput of Cassandra keyspace (RU/s). Default value is 400')

with self.argument_context('cosmosdb cassandra table') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('keyspace_name', options_list=['--keyspace-name', '-k'], help="Keyspace name")
c.argument('table_name', options_list=['--name', '-n'], help="Table name")
c.argument('default_ttl', options_list=['--ttl'], type=int, help='Default TTL. If the value is missing or set to "-1", items don’t expire. If the value is set to "n", items will expire "n" seconds after last modified time.')
Expand All @@ -145,13 +175,13 @@ def load_arguments(self, _):

# Gremlin
with self.argument_context('cosmosdb gremlin database') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', help='The throughput Gremlin database (RU/s). Default value is 400')

with self.argument_context('cosmosdb gremlin graph') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('graph_name', options_list=['--name', '-n'], help="Graph name")
c.argument('partition_key_path', options_list=['--partition-key-path', '-p'], help='Partition Key Path, e.g., \'/address/zipcode\'')
c.argument('default_ttl', options_list=['--ttl'], type=int, help='Default TTL. If the value is missing or set to "-1", items don’t expire. If the value is set to "n", items will expire "n" seconds after last modified time.')
Expand All @@ -161,56 +191,56 @@ def load_arguments(self, _):

# Table
with self.argument_context('cosmosdb table') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('table_name', options_list=['--name', '-n'], help="Table name")
c.argument('throughput', help='The throughput of Table (RU/s). Default value is 400')

# Throughput
with self.argument_context('cosmosdb sql database throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', type=int, help='The throughput of SQL database (RU/s).')

with self.argument_context('cosmosdb sql container throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('container_name', options_list=['--name', '-n'], help="Container name")
c.argument('throughput', type=int, help='The throughput of SQL container (RU/s).')

with self.argument_context('cosmosdb mongodb database throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', type=int, help='The throughput of MongoDB database (RU/s).')

with self.argument_context('cosmosdb mongodb collection throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('collection_name', options_list=['--name', '-n'], help="Collection name")
c.argument('throughput', type=int, help='The throughput of MongoDB collection (RU/s).')

with self.argument_context('cosmosdb cassandra keyspace throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('keyspace_name', options_list=['--name', '-n'], help="Keyspace name")
c.argument('throughput', type=int, help='The throughput of Cassandra keyspace (RU/s).')

with self.argument_context('cosmosdb cassandra table throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('keyspace_name', options_list=['--keyspace-name', '-k'], help="Keyspace name")
c.argument('table_name', options_list=['--name', '-n'], help="Table name")
c.argument('throughput', type=int, help='The throughput of Cassandra table (RU/s).')

with self.argument_context('cosmosdb gremlin database throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', options_list=['--name', '-n'], help="Database name")
c.argument('throughput', type=int, help='The throughput of Gremlin database (RU/s).')

with self.argument_context('cosmosdb gremlin graph throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('database_name', options_list=['--database-name', '-d'], help="Database name")
c.argument('account_name', account_name_type, id_part=None)
c.argument('database_name', database_name_type)
c.argument('graph_name', options_list=['--name', '-n'], help="Grapth name")
c.argument('throughput', type=int, help='The throughput Gremlin graph (RU/s).')

with self.argument_context('cosmosdb table throughput') as c:
c.argument('account_name', options_list=['--account-name', '-a'], help="Cosmosdb account name", id_part=None)
c.argument('account_name', account_name_type, id_part=None)
c.argument('table_name', options_list=['--name', '-n'], help="Table name")
c.argument('throughput', type=int, help='The throughput of Table (RU/s).')
Loading