Skip to content

Conversation

@djyou
Copy link
Member

@djyou djyou commented Jun 15, 2017

Fixes #2445 Azure/acr#33
Includes #3734


This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • The PR has modified HISTORY.rst with an appropriate description of the change (see Modifying change log).

Command Guidelines

  • Each command and parameter has a meaningful description.
  • Each new command has a test.

(see Authoring Command Modules)

@codecov-io
Copy link

codecov-io commented Jun 16, 2017

Codecov Report

Merging #3747 into master will decrease coverage by 1.14%.
The diff coverage is 45.26%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3747      +/-   ##
==========================================
- Coverage   72.12%   70.98%   -1.15%     
==========================================
  Files         420      424       +4     
  Lines       26044    26890     +846     
  Branches     3945     4092     +147     
==========================================
+ Hits        18785    19087     +302     
- Misses       6042     6565     +523     
- Partials     1217     1238      +21
Impacted Files Coverage Δ
...li-acr/azure/cli/command_modules/acr/credential.py 70.58% <ø> (-3.1%) ⬇️
...e-cli-acr/azure/cli/command_modules/acr/_format.py 27.77% <0%> (-11.12%) ⬇️
...e-cli-acr/azure/cli/command_modules/acr/_params.py 100% <100%> (ø) ⬆️
...-cli-acr/azure/cli/command_modules/acr/_factory.py 100% <100%> (+11.11%) ⬆️
...li-acr/azure/cli/command_modules/acr/_constants.py 100% <100%> (ø) ⬆️
...ure-cli-acr/azure/cli/command_modules/acr/_help.py 100% <100%> (ø) ⬆️
...-cli-acr/azure/cli/command_modules/acr/commands.py 100% <100%> (ø) ⬆️
...li-acr/azure/cli/command_modules/acr/repository.py 17.26% <18.05%> (-34.67%) ⬇️
src/azure-cli-core/azure/cli/core/_profile.py 86.52% <20%> (-1.56%) ⬇️
...acr/azure/cli/command_modules/acr/_docker_utils.py 22% <22%> (ø)
... and 18 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b5e9e3...bddfd33. Read the comment docs.

@djyou
Copy link
Member Author

djyou commented Jun 16, 2017

@djyou
Copy link
Member Author

djyou commented Jun 16, 2017

/cc @listonb

@sajayantony
Copy link
Contributor

LGTM

@listonb
Copy link

listonb commented Jun 16, 2017

LGTM! Thanks for adding the docker exec check! Excellent additions to the cli!

Copy link
Member

@derekbekoe derekbekoe left a comment

Choose a reason for hiding this comment

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

Questions about use of Docker in the Docker install of the CLI.

Dockerfile Outdated
Copy link
Member

Choose a reason for hiding this comment

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

What scenario is this for? The user could run apk add docker if they need docker.
It adds close to 100MB to our Docker image.
https://pkgs.alpinelinux.org/package/v3.6/community/aarch64/docker
356MB -> 433MB

Copy link
Member Author

Choose a reason for hiding this comment

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

docker is needed for acr login command.

Copy link
Member

Choose a reason for hiding this comment

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

Does this work inside the Docker install of Azure CLI?
I get this:

# docker login --username username --password "mypassword"
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
#

I get that error message for almost all Docker commands.

Copy link
Member Author

Choose a reason for hiding this comment

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

You will need to run the container with

docker run -it -v /var/run/docker.sock:/var/run/docker.sock azuresdk/azure-cli-python

Also apk add docker if docker is not installed in the container.

Copy link
Member

Choose a reason for hiding this comment

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

Okay thanks for removing it from the Dockerfile.

Copy link
Member

@derekbekoe derekbekoe left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

Choose a reason for hiding this comment

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

Does this arg pick up the default registry name if it's configured? The help text below doesn't seem to indicate it does, and it would be ideal to have it be defaulted when the ACR default is set.

@troydai
Copy link
Contributor

troydai commented Jun 19, 2017

Please rebase your changes and resolve the conflicts.

djyou and others added 3 commits June 19, 2017 11:34
* expose refresh token retrieving mechanism in profile
* added unit tests for refresh token operations
Repository querying operations can use AAD now (#36)
Renaming tokenserver user_type to credential_type (#37)
Rename credential_type to grant_type (#38)
Improve acr login strategy with fallbacks (#39)
Copy link
Contributor

@troydai troydai left a comment

Choose a reason for hiding this comment

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

Besides the questions regarding SDK - API version mechanism, I notice the code is formatted following a narrower line length limitation. The current line limitation is 120, you can fully utilize the room on one line to produce more condense code.



def get_acr_service_client():
def get_acr_service_client(api_version='2017-03-01'):
Copy link
Contributor

Choose a reason for hiding this comment

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

if customized_api_version:
logger.warning('Customized api-version is used: %s', customized_api_version)
return customized_api_version
return get_mgmt_service_client(ContainerRegistryManagementClient,
Copy link
Contributor

Choose a reason for hiding this comment

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

The line length limitation is 120 so you don't have to break the line here.

from azure.cli.core.util import CLIError
from azure.cli.core.commands.parameters import get_resources_in_subscription

from azure.mgmt.containerregistry.v2017_03_01.models import SkuTier
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use

def get_sdk(resource_type, *attr_args, **kwargs):

@derekbekoe

Copy link
Member Author

Choose a reason for hiding this comment

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

We are using multiple api-version SDK to direct registry creation calls to different versions based on SKU. Basically, Basic SKU will go to 2017-03-01 version and Managed SKUs will go to 2017-06-01-preview. At this point there is no need to expose multiple api-versions to users and the user specified SKU is enough to determine which api-version to go.

Copy link
Contributor

Choose a reason for hiding this comment

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

@derekbekoe
In this case, when user set CLI to be executed on an older version of API profile, will these commands be hidden from users?

Copy link
Member Author

Choose a reason for hiding this comment

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

AFAIK, this PR is not related to API profile. We simply direct calls to different api-versions based on SKU selection, but I will let @derekbekoe comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Some API versions may be missing in Azure Stack or different cloud. Will the command fail in those environments?

Copy link
Member

Choose a reason for hiding this comment

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

@troydai since @djyou says there is no need to expose multiple api-versions to the users, it's fine to import a specific version. It won't work on Azure Stack but I assume that was not intended anyway.

from azure.cli.core.util import CLIError
from azure.cli.core.commands.parameters import get_resources_in_subscription

from azure.mgmt.containerregistry.v2017_03_01.models import SkuTier
Copy link
Contributor

Choose a reason for hiding this comment

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

@derekbekoe
In this case, when user set CLI to be executed on an older version of API profile, will these commands be hidden from users?

"""
arm_resource = _arm_get_resource_by_name(registry_name, ACR_RESOURCE_TYPE)
return get_resource_group_name_by_resource_id(arm_resource.id)
if resource_group_name is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

if not resource_group_name

Unless an empty group name is legal, which I don't think should be the case.

:param str storage_account_name: The name of storage account
:param str resource_group_name: The name of resource group
"""
if resource_group_name is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

arm_resource = _arm_get_resource_by_name(registry_name, ACR_RESOURCE_TYPE)

if arm_resource.sku.tier == SkuTier.basic.value:
raise CLIError(message if message else "This operation is not supported for registries in Basic SKU.")
Copy link
Contributor

Choose a reason for hiding this comment

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

raise CLIError(message or "This operation is not supported for registries in Basic SKU.")

)
instance.storage_account = storage_account if storage_account_name else None

if admin_enabled is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

if admin_enable. In this case, when admin_enable is empty, it must yield negative result.

Copy link
Member Author

Choose a reason for hiding this comment

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

admin_enabled has a choice of either true or false and it does yield negative result if it is empty.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok. but it is actually weird that a bool parameter is not represented by a "switch" option.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I understand correctly, we will need a pair of switch options support both enable and disable admin user. We used to have it implemented that way (in fact in Powershell cmdlets we still have a pair of switch parameters) but was updated to the current implementation as suggested.

if admin_enabled is not None:
instance.admin_user_enabled = admin_enabled == 'true'

if tags is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is tag allowed to be an empty string? Otherwise, use if tags

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, empty clears tags.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

"""
registry, resource_group_name = get_registry_by_name(registry_name, resource_group_name)

if parameters.storage_account is not None and registry.sku.name != SkuTier.basic.value: # pylint: disable=no-member
Copy link
Contributor

Choose a reason for hiding this comment

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

if parameters.storage_account and ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Right now, if the specified storage account name is empty, we error out by saying that the storage account (with empty name) couldn't be found, which I think is the right behavior. If we make it the way you suggested, the command will go through but ignore the specified storage account. I personally think empty name is a negative scenario and should error out rather than ignore, what is the guideline here?

Copy link
Contributor

Choose a reason for hiding this comment

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

The truthiness of an empty string is False. Both None and empty in my opinion should render the same failed result.

logger.warning("'%s' SKU are managed registries. " +
"The specified storage account will be ignored.", registry.sku.name) # pylint: disable=no-member

if parameters.storage_account is not None and isinstance(parameters.storage_account, dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above.


# 1. if username was specified, verify that password was also specified
if username:
if not password:
Copy link
Contributor

Choose a reason for hiding this comment

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

if username and not password:



def acr_webhook_list(registry_name,
resource_group_name=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

Same line.

@troydai
Copy link
Contributor

troydai commented Jun 20, 2017

Most of my comments are about the truthiness in the condition when a string is in place. They're all about whether the empty strings should be treated as the legal values. Other than that the one outstanding question is whether the commands with a hard requirement of api version will be hidden when user switch to an older API profile. That is the case in Azure Stack.

Copy link
Member

@derekbekoe derekbekoe left a comment

Choose a reason for hiding this comment

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

LGTM

from azure.cli.core.util import CLIError
from azure.cli.core.commands.parameters import get_resources_in_subscription

from azure.mgmt.containerregistry.v2017_03_01.models import SkuTier
Copy link
Member

Choose a reason for hiding this comment

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

@troydai since @djyou says there is no need to expose multiple api-versions to the users, it's fine to import a specific version. It won't work on Azure Stack but I assume that was not intended anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants