diff --git a/src/azure/cli/_azure_env.py b/src/azure/cli/_azure_env.py index 2d3be9438a7..c9333fff732 100644 --- a/src/azure/cli/_azure_env.py +++ b/src/azure/cli/_azure_env.py @@ -15,6 +15,7 @@ class ENDPOINT_URLS: #pylint: disable=too-few-public-methods,old-style-class,no- ACTIVE_DIRECTORY_AUTHORITY = 'active_directory_authority' ACTIVE_DIRECTORY_GRAPH_RESOURCE_ID = 'active_directory_graph_resource_id' RESOURCE_MANAGER = 'resource_manager' + STORAGE_END_POINT_SUFFIX = 'storage end point suffix' _environments = { ENV_DEFAULT: { @@ -22,6 +23,7 @@ class ENDPOINT_URLS: #pylint: disable=too-few-public-methods,old-style-class,no- ENDPOINT_URLS.ACTIVE_DIRECTORY_AUTHORITY : 'https://login.windows-ppe.net', ENDPOINT_URLS.ACTIVE_DIRECTORY_GRAPH_RESOURCE_ID: 'https://graph.ppe.windows.net/', ENDPOINT_URLS.RESOURCE_MANAGER: 'https://api-dogfood.resources.windows-int.net/', + ENDPOINT_URLS.STORAGE_END_POINT_SUFFIX: 'blob.core.test-cint.azure-test.net/' } } diff --git a/src/azure/cli/commands/client_factory.py b/src/azure/cli/commands/client_factory.py index a1f6242e44c..c54504c2e58 100644 --- a/src/azure/cli/commands/client_factory.py +++ b/src/azure/cli/commands/client_factory.py @@ -9,6 +9,11 @@ import azure.cli._logging as _logging from azure.cli.application import APPLICATION +from azure.cli._azure_env import ( + get_env, + ENDPOINT_URLS +) + logger = _logging.get_az_logger(__name__) def get_mgmt_service_client(client_type): @@ -40,7 +45,7 @@ def _get_mgmt_service_client(client_type, subscription_bound=True): profile = Profile() cred, subscription_id, _ = profile.get_login_credentials() if subscription_bound: - client = client_type(cred, subscription_id) + client = client_type(cred, subscription_id, base_url=get_env()[ENDPOINT_URLS.RESOURCE_MANAGER]) else: client = client_type(cred) diff --git a/src/command_modules/azure-cli-registry/README.md b/src/command_modules/azure-cli-registry/README.md new file mode 100644 index 00000000000..3310151c9fd --- /dev/null +++ b/src/command_modules/azure-cli-registry/README.md @@ -0,0 +1,194 @@ +# Microsoft Azure CLI 'registry' Command Module + +## Commands to manage Azure container registries +``` +Group + az registry: Commands to manage Azure container registries. + +Commands: + catalog: The catalog of repositories in the specified registry. + create : Create a container registry. + delete : Delete a container registry. + list : List container registries. + show : Get a container registry. + tags : The list of tags for a given repository in the specified registry. + update : Update a container registry. +``` + +## List container registries +``` +Command + az registry list: List container registries. + +Arguments + --resource-group -g: Name of resource group. + +Global Arguments + --debug : Increase logging verbosity to show all debug logs. + --help -h : Show this help message and exit. + --output -o : Output format. Allowed values: json, tsv, list, table, jsonc. Default: + json. + --query : JMESPath query string. See http://jmespath.org/ for more information and + examples. + --verbose : Increase logging verbosity. Use --debug for full debug logs. + +Examples + List container registries and show result in a table + az registry list -o table + List container registries in a resource group and show result in a table + az registry list -g -o table +``` + +## Create a container registry +``` +Command + az registry create: Create a container registry. + +Arguments + --location -l [Required]: Location. + --name -n [Required]: The primary resource name. + --resource-group -g [Required]: Name of resource group. + --storage-account-key : Key of storage account. + --storage-account-name : Name of storage account. + +Global Arguments + --debug : Increase logging verbosity to show all debug logs. + --help -h : Show this help message and exit. + --output -o : Output format. Allowed values: json, tsv, list, table, jsonc. + Default: json. + --query : JMESPath query string. See http://jmespath.org/ for more + information and examples. + --verbose : Increase logging verbosity. Use --debug for full debug logs. + +Examples + Create a container registry with managed storage account + az registry create -n -g -l + Create a container registry with dedicated storage account (new or existing) + az registry create -n -g -l --storage-account- + name + Create a container registry with your own storage account + az registry create -n -g -l --storage-account- + name --storage-account-key +``` + +## Delete a container registry +``` +Command + az registry delete: Delete a container registry. + +Arguments + --name -n [Required]: The primary resource name. + +Global Arguments + --debug : Increase logging verbosity to show all debug logs. + --help -h : Show this help message and exit. + --output -o : Output format. Allowed values: json, tsv, list, table, jsonc. Default: + json. + --query : JMESPath query string. See http://jmespath.org/ for more information and + examples. + --verbose : Increase logging verbosity. Use --debug for full debug logs. + +Examples + Delete a container registry + az registry delete -n +``` + +## Get a container registry +``` +Command + az registry show: Get a container registry. + +Arguments + --name -n [Required]: The primary resource name. + +Global Arguments + --debug : Increase logging verbosity to show all debug logs. + --help -h : Show this help message and exit. + --output -o : Output format. Allowed values: json, tsv, list, table, jsonc. Default: + json. + --query : JMESPath query string. See http://jmespath.org/ for more information and + examples. + --verbose : Increase logging verbosity. Use --debug for full debug logs. + +Examples + Get a container registry and show result in a table + az registry show -n -o table +``` + +## Update a container registry +``` +Command + az registry update: Update a container registry. + +Arguments + --name -n [Required]: The primary resource name. + --tags : Multiple semicolon separated tags in 'key[=value]' format. Use "" to + clear existing tags. + +Global Arguments + --debug : Increase logging verbosity to show all debug logs. + --help -h : Show this help message and exit. + --output -o : Output format. Allowed values: json, tsv, list, table, jsonc. Default: + json. + --query : JMESPath query string. See http://jmespath.org/ for more information and + examples. + --verbose : Increase logging verbosity. Use --debug for full debug logs. + +Examples + Update tags of a container registry and show result in a table + az registry update -n --tags key1=value1;key2=value2 -o table +``` + +## The catalog of repositories in the specified registry +``` +Command + az registry catalog: The catalog of repositories in the specified registry. + +Arguments + --name -n [Required]: The primary resource name. + --password : The password used to log into the container registry. + --username : The username used to log into the container registry. + +Global Arguments + --debug : Increase logging verbosity to show all debug logs. + --help -h : Show this help message and exit. + --output -o : Output format. Allowed values: json, tsv, list, table, jsonc. Default: + json. + --query : JMESPath query string. See http://jmespath.org/ for more information and + examples. + --verbose : Increase logging verbosity. Use --debug for full debug logs. + +Examples + The catalog of repositories in a registry under the current subscription + az registry catalog -n + The catalog of repositories in any registry with credentials + az registry catalog -n --username --password +``` + +## The list of tags for a given repository in the specified registry +``` +Command + az registry tags: The list of tags for a given repository in the specified registry. + +Arguments + --name -n [Required]: The primary resource name. + --repository [Required]: The repository to obtain tags from. + --password : The password used to log into the container registry. + --username : The username used to log into the container registry. + +Global Arguments + --debug : Increase logging verbosity to show all debug logs. + --help -h : Show this help message and exit. + --output -o : Output format. Allowed values: json, tsv, list, table, jsonc. + Default: json. + --query : JMESPath query string. See http://jmespath.org/ for more information + and examples. + --verbose : Increase logging verbosity. Use --debug for full debug logs. + +Examples + The list of tags for a given repository in a registry under the current subscription + az registry tags -n --repository + The list of tags for a given repository in any registry with credentials + az registry tags -n --repository --username + --password +``` \ No newline at end of file diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/__init__.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/__init__.py index 26d4c1e7a79..8c9de016d40 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/__init__.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/__init__.py @@ -8,4 +8,4 @@ import azure.cli.command_modules.registry._help import azure.cli.command_modules.registry._params import azure.cli.command_modules.registry.custom -import azure.cli.command_modules.registry.container +import azure.cli.command_modules.registry.repository diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_arm_utils.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_arm_utils.py index 2d7d131921c..a42adc70a05 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_arm_utils.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_arm_utils.py @@ -5,7 +5,12 @@ from azure.cli.command_modules.registry.mgmt_cr.models import RegistryParameters -from ._factory import get_arm_service_client +from ._factory import ( + get_arm_service_client, + get_storage_end_point_url +) + +from azure.cli.command_modules.registry.mgmt_cr import VERSION resource_type = 'Microsoft.Krater/registries' @@ -42,37 +47,80 @@ def arm_get_registry_by_name(registry_name): else: raise ValueError('More than one container registries are found with name: ' + registry_name) -def arm_deploy_template(resource_group, registry_name, location, storage_account_name, - deployment_name, mode='incremental'): - '''Deploys ARM template to create a container registry. +def arm_deploy_template_dedicated(resource_group, registry_name, location, + storage_account_name, deployment_name): + '''Deploys ARM template to create a container registry using the storage account in the current subscription. :param str resource_group: The name of resource group :param str registry_name: The name of container registry :param str location: The name of location :param str storage_account_name: The name of storage account + :param str deployment_name: The name of deployment + ''' + parameters = _parameters_dedicated(registry_name, location, storage_account_name) + return _arm_deploy_template(resource_group, deployment_name, 'template.dedicated.json', parameters) + +def arm_deploy_template_byos(resource_group, registry_name, location, + storage_account_name, storage_account_key, deployment_name): + '''Deploys ARM template to create a container registry using the user's own storage account. + :param str resource_group: The name of resource group + :param str registry_name: The name of container registry + :param str location: The name of location + :param str storage_account_name: The name of storage account + :param str storage_account_key: The key of storage account + :param str deployment_name: The name of deployment + ''' + parameters = _parameters_byos(registry_name, location, storage_account_name, storage_account_key) + return _arm_deploy_template(resource_group, deployment_name, 'template.byos.json', parameters) + +def _arm_deploy_template(resource_group, deployment_name, template_path, parameters, mode='incremental'): + '''Deploys ARM template to create a container registry. + :param str resource_group: The name of resource group + :param str deployment_name: The name of deployment + :param str template_path: The template file path + :param dict parameters: The parameters for this deployment + :param str mode: The mode of deployment ''' from azure.mgmt.resource.resources.models import DeploymentProperties from azure.cli._util import get_file_json import os - file_path = os.path.join(os.path.dirname(__file__), 'template.json') + file_path = os.path.join(os.path.dirname(__file__), template_path) template = get_file_json(file_path) - - parameters = _parameters(registry_name, location, storage_account_name) properties = DeploymentProperties(template=template, parameters=parameters, mode=mode) - + client = get_arm_service_client() return client.deployments.create_or_update(resource_group, deployment_name, properties) -def _parameters(registry_name, location, storage_account_name): +def _parameters_dedicated(registry_name, location, storage_account_name): + '''Returns a dict of deployment parameters + :param str registry_name: The name of container registry + :param str location: The name of location + :param str storage_account_name: The name of storage account + ''' + parameters = { + 'registryName': {'value': registry_name}, + 'registryLocation': {'value': location}, + 'registryApiVersion': {'value': VERSION}, + 'storageAccountName': {'value': storage_account_name}, + 'storageAccountLocation': {'value': 'westus'}, + 'storageAccountApiVersion': {'value': '2015-05-01-preview'} + } + return parameters + +def _parameters_byos(registry_name, location, storage_account_name, storage_account_key): '''Returns a dict of deployment parameters :param str registry_name: The name of container registry :param str location: The name of location :param str storage_account_name: The name of storage account + :param str storage_account_key: The key of storage account ''' parameters = { 'registryName': {'value': registry_name}, - 'location': {'value': location}, - 'storageAccountName': {'value': storage_account_name} + 'registryLocation': {'value': location}, + 'registryApiVersion': {'value': VERSION}, + 'storageAccountName': {'value': storage_account_name}, + 'storageAccountKey': {'value': storage_account_key}, + 'storageEndPointUrl': {'value': get_storage_end_point_url(storage_account_name)} } return parameters diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_factory.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_factory.py index 9a5f856c90e..71529095c5a 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_factory.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_factory.py @@ -4,7 +4,10 @@ #--------------------------------------------------------------------------------------------- from azure.cli._profile import Profile -from azure.cli.commands.client_factory import configure_common_settings +from azure.cli.commands.client_factory import ( + configure_common_settings, + get_mgmt_service_client +) from azure.cli._azure_env import ( get_env, @@ -20,18 +23,11 @@ from azure.mgmt.resource.resources import ResourceManagementClient def get_arm_service_client(): - '''Returns the client for managing resource. + '''Returns the client for managing ARM resources. ''' - profile = Profile() - cred, subscription_id, _ = profile.get_login_credentials() + return get_mgmt_service_client(ResourceManagementClient) - client = ResourceManagementClient(cred, subscription_id, base_url=get_env()[ENDPOINT_URLS.RESOURCE_MANAGER]) - - configure_common_settings(client) - - return client - -def get_mgmt_service_client(): +def get_registry_service_client(): '''Returns the client for managing container registries. ''' profile = Profile() @@ -43,3 +39,9 @@ def get_mgmt_service_client(): configure_common_settings(client) return client.registries + +def get_storage_end_point_url(storage_account_name): + '''Returns the end point url for the storage account name + :param str storage_account_name: The name of storage account + ''' + return 'https://' + storage_account_name + '.' + get_env()[ENDPOINT_URLS.STORAGE_END_POINT_SUFFIX] diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_help.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_help.py index dafce6a8299..6663b82635d 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_help.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_help.py @@ -7,40 +7,85 @@ #pylint: disable=line-too-long +helps['registry'] = """ + type: group + short-summary: Commands to manage Azure container registries. + """ + helps['registry list'] = """ type: command short-summary: List container registries. + examples: + - name: List container registries and show result in a table + text: + az registry list -o table + - name: List container registries in a resource group and show result in a table + text: + az registry list -g -o table """ helps['registry create'] = """ type: command short-summary: Create a container registry. - long-summary: Create a container registry. See examples. examples: - - name: Create a container registry + - name: Create a container registry with managed storage account text: az registry create -n -g -l - - name: Create a container registry with new/existing storage account + - name: Create a container registry with dedicated storage account (new or existing) + text: + az registry create -n -g -l --storage-account-name + - name: Create a container registry with your own storage account text: - az registry create -n -g -l -s + az registry create -n -g -l --storage-account-name --storage-account-key """ helps['registry delete'] = """ type: command short-summary: Delete a container registry. + examples: + - name: Delete a container registry + text: + az registry delete -n """ helps['registry show'] = """ type: command short-summary: Get a container registry. + examples: + - name: Get a container registry and show result in a table + text: + az registry show -n -o table """ helps['registry update'] = """ type: command short-summary: Update a container registry. - long-summary: Update a container registry. See examples. examples: - - name: Update tags of a container registry. + - name: Update tags of a container registry and show result in a table + text: + az registry update -n --tags key1=value1;key2=value2 -o table + """ + +helps['registry catalog'] = """ + type: command + short-summary: The catalog of repositories in the specified registry. + examples: + - name: The catalog of repositories in a registry under the current subscription + text: + az registry catalog -n + - name: The catalog of repositories in any registry with credentials + text: + az registry catalog -n --username --password + """ + +helps['registry tags'] = """ + type: command + short-summary: The list of tags for a given repository in the specified registry. + examples: + - name: The list of tags for a given repository in a registry under the current subscription + text: + az registry tags -n --repository + - name: The list of tags for a given repository in any registry with credentials text: - az registry update -n --tags key1=value1;key2=value2 + az registry tags -n --repository --username --password """ diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_params.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_params.py index be35f4b39f4..f7f848bd674 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_params.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_params.py @@ -15,19 +15,17 @@ tags_type ) -storage_account_type = CliArgumentType( - options_list=('--storage-account-name', '-s'), +storage_account_name_type = CliArgumentType( help='Name of storage account.' ) -deployment_name_type = CliArgumentType( - options_list=('--deployment-name', '-d'), - help='Name of deployment.' +storage_account_key_type = CliArgumentType( + help='Key of storage account.' ) register_cli_argument('registry', 'registry_name', arg_type=name_type) register_cli_argument('registry', 'resource_group', arg_type=resource_group_name_type) register_cli_argument('registry', 'location', arg_type=location_type) register_cli_argument('registry', 'tags', arg_type=tags_type) -register_cli_argument('registry', 'storage_account_name', arg_type=storage_account_type) -register_cli_argument('registry', 'deployment_name', arg_type=deployment_name_type) +register_cli_argument('registry', 'storage_account_name', arg_type=storage_account_name_type) +register_cli_argument('registry', 'storage_account_key', arg_type=storage_account_key_type) diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_utils.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_utils.py index 12aaf399558..e173d17f18d 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_utils.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/_utils.py @@ -3,20 +3,25 @@ # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- +import re + from azure.cli.command_modules.registry.mgmt_cr.models import RegistryParameters -from ._factory import get_mgmt_service_client +from ._factory import get_registry_service_client + +import azure.cli._logging as _logging +logger = _logging.get_az_logger(__name__) def _get_registries_in_subscription(): '''Returns the list of container registries in the current subscription. ''' - return get_mgmt_service_client().list().value # pylint: disable=E1101 + return get_registry_service_client().list().value # pylint: disable=E1101 def _get_registries_in_resource_group(resource_group): '''Returns the list of container registries in the resource group. :param str resource_group: The name of resource group ''' - return get_mgmt_service_client().list_by_resource_group(resource_group).value # pylint: disable=E1101 + return get_registry_service_client().list_by_resource_group(resource_group).value # pylint: disable=E1101 def get_registry_by_name(registry_name): '''Returns the container registry that matches the registry name. @@ -69,3 +74,17 @@ def _get_resource_group_keyword(resource_id): return '/resourceGroups/' else: raise ValueError('Invalid resource id: ' + resource_id) + +def validate_registry_name(registry_name): + '''Returns if the registry name is allowed. + :param str registry_name: The name of container registry + ''' + if len(registry_name) < 5 or len(registry_name) > 60: + logger.error('The registry name must be between 5 and 60 characters.') + raise SystemExit(1) + + p = re.compile('^([A-Za-z0-9]+)$') + + if not p.match(registry_name): + logger.error('The registry name can contain only letters and numbers.') + raise SystemExit(1) diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/custom.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/custom.py index 69270f75077..60df868f633 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/custom.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/custom.py @@ -7,18 +7,20 @@ from azure.cli.command_modules.registry.mgmt_cr.models import RegistryParameters -from ._factory import get_mgmt_service_client +from ._factory import get_registry_service_client from ._arm_utils import ( arm_get_registries_in_subscription, arm_get_registries_in_resource_group, arm_get_registry_by_name, - arm_deploy_template + arm_deploy_template_dedicated, + arm_deploy_template_byos ) from ._utils import ( get_registry_by_name, - get_resource_group_by_registry + get_resource_group_by_registry, + validate_registry_name ) from ._format import output_format @@ -35,47 +37,55 @@ def cr_list(resource_group=None): else: return arm_get_registries_in_subscription() -def cr_create(resource_group, registry_name, location, storage_account_name=None, deployment_name="Microsoft.Krater"): +def cr_create(resource_group, registry_name, location, storage_account_name=None, storage_account_key=None, deployment_name="Microsoft.ContainerRegistry"): '''Returns the created container registry. :param str resource_group: The name of resource group :param str registry_name: The name of container registry :param str location: The name of location :param str storage_account_name: The name of storage account - :param str deployment_name: The name of deployment + :param str storage_account_key: The key of storage account + :param str deployment_name: The name of deployment ''' + validate_registry_name(registry_name) if storage_account_name: - return arm_deploy_template(resource_group, registry_name, location, storage_account_name, deployment_name) + if storage_account_key: + return arm_deploy_template_byos(resource_group, registry_name, location, storage_account_name, storage_account_key, deployment_name) + else: + return arm_deploy_template_dedicated(resource_group, registry_name, location, storage_account_name, deployment_name) else: - return get_mgmt_service_client().create(resource_group, registry_name, RegistryParameters(location=location)) + return get_registry_service_client().create(resource_group, registry_name, RegistryParameters(location=location)) def cr_delete(registry_name): '''Deletes the container registry that matches the registry name :param str registry_name: The name of container registry ''' + validate_registry_name(registry_name) registry = arm_get_registry_by_name(registry_name) if registry is None: logger.error('No container registry can be found with name: ' + registry_name) raise SystemExit(1) resource_group = get_resource_group_by_registry(registry) - return get_mgmt_service_client().delete(resource_group, registry_name) + return get_registry_service_client().delete(resource_group, registry_name) def cr_show(registry_name): '''Returns the container registry that matches the registry name. :param str registry_name: The name of container registry ''' + validate_registry_name(registry_name) registry = arm_get_registry_by_name(registry_name) if registry is None: logger.error('No container registry can be found with name: ' + registry_name) raise SystemExit(1) resource_group = get_resource_group_by_registry(registry) - return get_mgmt_service_client().get_properties(resource_group, registry_name) + return get_registry_service_client().get_properties(resource_group, registry_name) def cr_update(registry_name, tags=None): '''Returns the updated container registry that matches the registry name. :param str registry_name: The name of container registry ''' + validate_registry_name(registry_name) registry = get_registry_by_name(registry_name) if registry is None: logger.error('No container registry can be found with name: ' + registry_name) @@ -95,7 +105,7 @@ def cr_update(registry_name, tags=None): else: newTags = {} - return get_mgmt_service_client().update(resource_group, registry_name, RegistryParameters(location=registry.location, tags=newTags)) + return get_registry_service_client().update(resource_group, registry_name, RegistryParameters(location=registry.location, tags=newTags)) cli_command('registry list', cr_list, simple_output_query=output_format) cli_command('registry create', cr_create, simple_output_query=output_format) diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/container.py b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/repository.py similarity index 82% rename from src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/container.py rename to src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/repository.py index 313970623d5..639469f6286 100644 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/container.py +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/repository.py @@ -2,13 +2,15 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. See License.txt in the project root for license information. #--------------------------------------------------------------------------------------------- -# Add command module logic to this package. import requests from azure.cli.commands import cli_command -from ._utils import get_registry_by_name +from ._utils import ( + get_registry_by_name, + validate_registry_name +) import azure.cli._logging as _logging logger = _logging.get_az_logger(__name__) @@ -56,22 +58,24 @@ def _validate_user_credentials(registry_name, path, resultIndex, username=None, raise SystemExit(1) def cr_catalog(registry_name, username=None, password=None): - '''Returns the catalog of containers in the specified registry. + '''Returns the catalog of repositories in the specified registry. :param str registry_name: The name of your Azure container registry - :param str username: The user name used to log into the container registry + :param str username: The username used to log into the container registry :param str password: The password used to log into the container registry ''' + validate_registry_name(registry_name) path = '/v2/_catalog' return _validate_user_credentials(registry_name, path, 'repositories', username, password) -def cr_tags(registry_name, container, username=None, password=None): - '''Returns the list of tags for a given container in the specified registry. +def cr_tags(registry_name, repository, username=None, password=None): + '''Returns the list of tags for a given repository in the specified registry. :param str registry_name: The name of your Azure container registry - :param str container: The container to obtain tags from - :param str username: The user name used to log into the container registry + :param str repository: The repository to obtain tags from + :param str username: The username used to log into the container registry :param str password: The password used to log into the container registry ''' - path = '/v2/' + container + '/tags/list' + validate_registry_name(registry_name) + path = '/v2/' + repository + '/tags/list' return _validate_user_credentials(registry_name, path, 'tags', username, password) cli_command('registry catalog', cr_catalog) diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.byos.json b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.byos.json new file mode 100644 index 00000000000..c75b37de368 --- /dev/null +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.byos.json @@ -0,0 +1,58 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "registryName": { + "type": "string", + "metadata": { + "description": "Name of the registry service" + } + }, + "registryLocation": { + "type": "string", + "metadata": { + "description": "Location of the registry service" + } + }, + "registryApiVersion": { + "type": "string", + "metadata": { + "description": "Api version of the registry service" + } + }, + "storageAccountName": { + "type": "string", + "metadata": { + "description": "Name of the storage account" + } + }, + "storageAccountKey": { + "type": "string", + "metadata": { + "description": "Key of the storage account" + } + }, + "storageEndPointUrl": { + "type": "string", + "metadata": { + "description": "End point URL of the storage account" + } + } + }, + "resources": [ + { + "comments": "# Registry", + "name": "[parameters('registryName')]", + "type": "Microsoft.Krater/registries", + "location": "[parameters('registryLocation')]", + "apiVersion": "[parameters('registryApiVersion')]", + "properties": { + "storageAccount": { + "name": "[parameters('storageAccountName')]", + "accessKey": "[parameters('storageAccountKey')]", + "endPointUrl": "[parameters('storageEndPointUrl')]" + } + } + } + ] +} \ No newline at end of file diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.dedicated.json b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.dedicated.json new file mode 100644 index 00000000000..dfeed312999 --- /dev/null +++ b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.dedicated.json @@ -0,0 +1,83 @@ +{ + "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "registryName": { + "type": "string", + "metadata": { + "description": "Name of the registry service" + } + }, + "registryLocation": { + "type": "string", + "metadata": { + "description": "Location of the registry service" + } + }, + "registryApiVersion": { + "type": "string", + "metadata": { + "description": "Api version of the registry service" + } + }, + "storageAccountName": { + "type": "string", + "metadata": { + "description": "Name of the storage account" + } + }, + "storageAccountLocation": { + "type": "string", + "metadata": { + "description": "Location of the storage account" + } + }, + "storageAccountApiVersion": { + "type": "string", + "metadata": { + "description": "Api version of the storage account" + } + } + }, + "resources": [ + { + "comments": "# Storage Account", + "name": "[parameters('storageAccountName')]", + "type": "Microsoft.Storage/storageAccounts", + "location": "[parameters('storageAccountLocation')]", + "apiVersion": "[parameters('storageAccountApiVersion')]", + "properties": { + "accountType": "Standard_LRS" + } + }, + { + "comments": "# Registry", + "name": "[parameters('registryName')]", + "type": "Microsoft.Krater/registries", + "location": "[parameters('registryLocation')]", + "apiVersion": "[parameters('registryApiVersion')]", + "dependsOn": [ + "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]" + ], + "properties": { + "storageAccount": { + "name": "[parameters('storageAccountName')]", + "accessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), parameters('storageAccountApiVersion')).key1]", + "endPointUrl": "[reference(concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName')), parameters('storageAccountApiVersion')).primaryEndpoints.blob]" + } + } + }, + { + "type": "Microsoft.Krater/registries/providers/links", + "apiVersion": "2015-01-01", + "name": "[concat(parameters('registryName'),'/Microsoft.Resources/RegistryToStorage')]", + "dependsOn": [ + "[parameters('registryName')]" + ], + "properties": { + "targetId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]", + "notes": "This registry uses the storage account to store registry information." + } + } + ] +} \ No newline at end of file diff --git a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.json b/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.json deleted file mode 100644 index e7a0cc32cd7..00000000000 --- a/src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/template.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#", - "contentVersion": "1.0.0.0", - "parameters": { - "registryName": { - "type": "string" - }, - "location": { - "type": "string" - }, - "storageAccountName": { - "type": "string" - } - }, - "resources": [ - { - "name": "[parameters('storageAccountName')]", - "type": "Microsoft.Storage/storageAccounts", - "location": "westus", - "apiVersion": "2015-05-01-preview", - "properties": { - "accountType": "Standard_LRS" - } - }, - { - "name": "[parameters('registryName')]", - "type": "Microsoft.Krater/registries", - "location": "[parameters('location')]", - "apiVersion": "2016-06-27-preview", - "dependsOn": [ - "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]" - ], - "properties": { - "storageAccount": { - "name": "[parameters('storageAccountName')]", - "accessKey": "[listKeys(resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName')), '2015-05-01-preview').key1]", - "endPoint": "[reference(concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName')), '2015-05-01-preview').primaryEndpoints.blob]" - } - } - } - ] -} \ No newline at end of file diff --git a/src/command_modules/azure-cli-registry/setup.py b/src/command_modules/azure-cli-registry/setup.py index 2db739b1143..3423e350af1 100644 --- a/src/command_modules/azure-cli-registry/setup.py +++ b/src/command_modules/azure-cli-registry/setup.py @@ -52,5 +52,5 @@ 'azure.cli.command_modules.registry.mgmt_cr.operations', ], install_requires=DEPENDENCIES, - package_data={'azure.cli.command_modules.registry': ['template.json']}, + package_data={'azure.cli.command_modules.registry': ['template.dedicated.json', 'template.byos.json']}, )