forked from Azure/azure-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KeyVault] Onboard KeyVault Round 1 (Azure#1037)
* Initial KeyVault data plane commands and management plane revisions. * Code review comments. * Bump to wake up CI. * Bump to wake up CI. * Fix imports. * Updates to setup.py * Updates to setup.py * Update vault_base_url
- Loading branch information
1 parent
4133de3
commit d72cfaa
Showing
111 changed files
with
8,222 additions
and
915 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -1,2 +1 @@ | ||
azure==2.0.0rc6 | ||
azure-mgmt-iothub==0.1.0 |
This file contains 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 |
---|---|---|
|
@@ -26,7 +26,6 @@ | |
] | ||
|
||
DEPENDENCIES = [ | ||
'azure==2.0.0rc6', | ||
'azure-mgmt-iothub==0.1.0', | ||
'azure-cli-core', | ||
] | ||
|
This file contains 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
77 changes: 77 additions & 0 deletions
77
src/command_modules/azure-cli-keyvault/azure/cli/command_modules/keyvault/_command_type.py
This file contains 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,77 @@ | ||
#--------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
#--------------------------------------------------------------------------------------------- | ||
|
||
import base64 | ||
|
||
from msrest.paging import Paged | ||
from msrest.exceptions import ValidationError | ||
from msrestazure.azure_operation import AzureOperationPoller | ||
|
||
from azure.cli.core.commands import command_table, CliCommand, LongRunningOperation | ||
from azure.cli.core.commands._introspection import \ | ||
(extract_full_summary_from_signature, extract_args_from_signature) | ||
from azure.cli.core._profile import Profile, CredentialType | ||
from azure.cli.core._util import CLIError | ||
|
||
from azure.cli.command_modules.keyvault.convenience import KeyVaultClient | ||
from azure.cli.command_modules.keyvault.keyvaultclient.models import KeyVaultErrorException | ||
|
||
def _encode_hex(item): | ||
""" Recursively crawls the object structure and converts bytes or bytearrays to base64 | ||
encoded strings. """ | ||
if isinstance(item, list): | ||
return [_encode_hex(x) for x in item] | ||
elif hasattr(item, '__dict__'): | ||
for key, val in item.__dict__.items(): | ||
item.__dict__[key] = _encode_hex(val) | ||
return item | ||
elif isinstance(item, bytes) or isinstance(item, bytearray): | ||
return base64.b64encode(item).decode('utf-8') | ||
else: | ||
return item | ||
|
||
def _create_key_vault_command(name, operation, transform_result, table_transformer): | ||
|
||
def _execute_command(kwargs): | ||
|
||
try: | ||
client = KeyVaultClient( | ||
Profile().get_login_credentials(credential_type=CredentialType.keyvault)[0]) | ||
result = operation(client, **kwargs) | ||
|
||
# apply results transform if specified | ||
if transform_result: | ||
return _encode_hex(transform_result(result)) | ||
|
||
# otherwise handle based on return type of results | ||
if isinstance(result, AzureOperationPoller): | ||
return _encode_hex(LongRunningOperation('Starting {}'.format(name))(result)) | ||
elif isinstance(result, Paged): | ||
try: | ||
return _encode_hex(list(result)) | ||
except TypeError: | ||
# TODO: Workaround for an issue in either KeyVault server-side or msrest | ||
# See https://github.com/Azure/autorest/issues/1309 | ||
return [] | ||
else: | ||
return _encode_hex(result) | ||
except (ValidationError, KeyVaultErrorException) as ex: | ||
try: | ||
raise CLIError(ex.inner_exception.error.message) | ||
except AttributeError: | ||
raise CLIError(ex) | ||
|
||
name = ' '.join(name.split()) | ||
cmd = CliCommand(name, _execute_command, table_transformer=table_transformer) | ||
cmd.description = extract_full_summary_from_signature(operation) | ||
cmd.arguments.update(extract_args_from_signature(operation)) | ||
return cmd | ||
|
||
def cli_keyvault_data_plane_command( | ||
name, operation, transform=None, table_transformer=None): | ||
""" Registers an Azure CLI KeyVault Data Plane command. These commands must respond to a | ||
challenge from the service when they make requests. """ | ||
command = _create_key_vault_command(name, operation, transform, table_transformer) | ||
command_table[command.name] = command |
This file contains 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 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
Oops, something went wrong.