forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 5
Integrated repository catalog and tags commands #4
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
src/command_modules/azure-cli-cr/azure/cli/command_modules/__init__.py
This file was deleted.
Oops, something went wrong.
58 changes: 0 additions & 58 deletions
58
src/command_modules/azure-cli-cr/azure/cli/command_modules/cr/__init__.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/command_modules/azure-cli-registry/azure/cli/command_modules/registry/container.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| 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) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks!