Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ complete -o nospace -F _python_argcomplete \"az\"\n\
" > /etc/az.completion
RUN echo "\nsource '/etc/az.completion'\n" >> /etc/bash.bashrc

RUN curl -sSL https://get.docker.com/ | sh

WORKDIR /

CMD az; bash
7 changes: 0 additions & 7 deletions src/command_modules/azure-cli-cr/README.rst

This file was deleted.

6 changes: 0 additions & 6 deletions src/command_modules/azure-cli-cr/azure/__init__.py

This file was deleted.

6 changes: 0 additions & 6 deletions src/command_modules/azure-cli-cr/azure/cli/__init__.py

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion src/command_modules/azure-cli-cr/requirements.txt

This file was deleted.

52 changes: 0 additions & 52 deletions src/command_modules/azure-cli-cr/setup.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +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
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def arm_get_registry_by_name(registry_name):
:param str registry_name: The name of container registry
'''
registries = arm_get_registries_in_subscription()
elements = [item for item in registries if item.name == registry_name]
elements = [item for item in registries if item.name.lower() == registry_name.lower()]

if len(elements) == 0:
raise ValueError('No container registry can be found with name: ' + registry_name)
return None
elif len(elements) == 1:
return elements[0]
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="Microsoft.Krater", mode='incremental'):
deployment_name, mode='incremental'):
'''Deploys ARM template to create a container registry.
:param str resource_group: The name of resource group
:param str registry_name: The name of container registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@
help='Name of storage account.'
)

deployment_name_type = CliArgumentType(
options_list=('--deployment-name', '-d'),
help='Name of deployment.'
)

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)
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def get_registry_by_name(registry_name):
:param str registry_name: The name of container registry
'''
registries = _get_registries_in_subscription()
elements = [item for item in registries if item.name == registry_name]
elements = [item for item in registries if item.name.lower() == registry_name.lower()]

if len(elements) == 0:
raise ValueError('No container registry can be found with name: ' + registry_name)
return None
elif len(elements) == 1:
return elements[0]
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#---------------------------------------------------------------------------------------------
# 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!


from azure.cli.commands import cli_command

from ._utils import get_registry_by_name

import azure.cli._logging as _logging
logger = _logging.get_az_logger(__name__)

def _obtain_data_from_registry(registry_name, path, resultIndex, username, password):
registryEndpoint = 'https://' + registry_name + '.azurecr.io'
resultList = []
executeNextHttpCall = True

while executeNextHttpCall:
executeNextHttpCall = False
response = requests.get(registryEndpoint + path,
auth=requests.auth.HTTPBasicAuth(
username,
password
)
)

if response.status_code == 200:
resultList += response.json()[resultIndex]
if 'link' in response.headers and response.headers['link']:
linkHeader = response.headers['link']
# the registry is telling us there's more items in the list, and another call is needed
# the link header looks something like `Link: </v2/_catalog?last=hello-world&n=1>; rel="next"`
# we should follow the next path indicated in the link header
path = linkHeader[(linkHeader.index('<')+1):linkHeader.index('>')]
executeNextHttpCall = True
else:
response.raise_for_status()

return {resultIndex: resultList}

def _validate_user_credentials(registry_name, path, resultIndex, username=None, password=None):
if username and password:
return _obtain_data_from_registry(registry_name, path, resultIndex, username, password)

try:
registry = get_registry_by_name(registry_name)
username = registry.properties.username
password = registry.properties.key
return _obtain_data_from_registry(registry_name, path, resultIndex, username, password)
except: # pylint: disable=W0702
logger.error('No container registry can be found with name: ' + registry_name)
logger.error('Please switch subscription or enter username/password')
raise SystemExit(1)

def cr_catalog(registry_name, username=None, password=None):
'''Returns the catalog of containers 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 password: The password used to log into the container registry
'''
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.
: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 password: The password used to log into the container registry
'''
path = '/v2/' + container + '/tags/list'
return _validate_user_credentials(registry_name, path, 'tags', username, password)

cli_command('registry catalog', cr_catalog)
cli_command('registry tags', cr_tags)
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

from ._format import output_format

def _cr_list(resource_group=None):
import azure.cli._logging as _logging
logger = _logging.get_az_logger(__name__)

def cr_list(resource_group=None):
'''Returns the list of container registries.
:param str resource_group: The name of resource group
'''
Expand All @@ -32,39 +35,52 @@ 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):
def cr_create(resource_group, registry_name, location, storage_account_name=None, deployment_name="Microsoft.Krater"):
'''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
'''
if storage_account_name:
return arm_deploy_template(resource_group, registry_name, location, storage_account_name)
return arm_deploy_template(resource_group, registry_name, location, storage_account_name, deployment_name)
else:
return get_mgmt_service_client().create(resource_group, registry_name, RegistryParameters(location=location))

def _cr_delete(registry_name):
def cr_delete(registry_name):
'''Deletes the container registry that matches the registry name
:param str registry_name: The name of container registry
'''
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)

def _cr_show(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
'''
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)

def _cr_update(registry_name, tags=None):
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
'''
registry = 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)

newTags = registry.tags
Expand All @@ -81,8 +97,8 @@ def _cr_update(registry_name, tags=None):

return get_mgmt_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)
cli_command('registry delete', _cr_delete, simple_output_query=output_format)
cli_command('registry show', _cr_show, simple_output_query=output_format)
cli_command('registry update', _cr_update, simple_output_query=output_format)
cli_command('registry list', cr_list, simple_output_query=output_format)
cli_command('registry create', cr_create, simple_output_query=output_format)
cli_command('registry delete', cr_delete, simple_output_query=output_format)
cli_command('registry show', cr_show, simple_output_query=output_format)
cli_command('registry update', cr_update, simple_output_query=output_format)