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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
cli_command(__name__, 'acr credential show',
'azure.cli.command_modules.acr.credential#acr_credential_show',
table_transformer=credential_format, exception_handler=empty_on_404)
cli_command(__name__, 'acr credential login',
'azure.cli.command_modules.acr.credential#acr_credential_login',
exception_handler=empty_on_404)
cli_command(__name__, 'acr credential renew',
'azure.cli.command_modules.acr.credential#acr_credential_renew',
table_transformer=credential_format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import subprocess

from azure.cli.core.util import CLIError
import azure.cli.core.azlogging as azlogging

Expand All @@ -27,6 +29,27 @@ def acr_credential_show(registry_name, resource_group_name=None):
admin_not_enabled_error(registry_name)


def acr_credential_login(registry_name, resource_group_name=None):
"""Returns a docker login command for the specified container registry.
: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(registry_name, resource_group_name)
client = get_acr_service_client().registries

try:
subprocess.call(["docker"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
except:
raise CLIError("Docker is not currently installed. Please install docker")

if registry.admin_user_enabled:
credentials = client.list_credentials(resource_group_name, registry_name)
subprocess.call(["docker", "login", "-u", credentials.username, "-p",
credentials.passwords[0].value, registry.login_server])
else:
admin_not_enabled_error(registry_name)


def acr_credential_renew(registry_name, password_name, resource_group_name=None):
"""Regenerates one of the login credentials for the specified container registry.
:param str registry_name: The name of container registry
Expand Down