Skip to content

Commit da345e7

Browse files
authored
Merge branch 'Azure:dev' into dev
2 parents d79417e + e773a71 commit da345e7

File tree

347 files changed

+2776
-29559
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

347 files changed

+2776
-29559
lines changed

scripts/regression_test/extension_regression_test.yml

+17-14
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
- task: AzureCLI@1
2525
displayName: 'checkout branch'
2626
inputs:
27-
azureSubscription: 'Azure CLI release'
27+
azureSubscription: $(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)
2828
scriptLocation: inlineScript
2929
inlineScript: |
3030
set -ev
@@ -81,7 +81,7 @@ jobs:
8181
- task: AzureCLI@1
8282
displayName: 'checkout cli and extension repo'
8383
inputs:
84-
azureSubscription: 'Azure CLI release'
84+
azureSubscription: $(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)
8585
scriptLocation: inlineScript
8686
inlineScript: |
8787
set -ev
@@ -106,17 +106,20 @@ jobs:
106106
- template: ../../.azure-pipelines/templates/azdev_setup.yml
107107
parameters:
108108
CLIExtensionRepoPath: ./azure-cli-extensions
109-
- bash: |
110-
set -ev
111-
112-
source env/bin/activate
113-
cd azure-cli-extensions
114-
115-
az login -u $(CLI_LIVE_TEST_ACCOUNT) -p "$(CLI_LIVE_TEST_PASSWORD)"
116-
az account set -s 0b1f6471-1bf0-4dda-aec3-cb9272f09590
117-
118-
python ../scripts/ci/automation_full_test.py "12" "$(Instance_idx)" "latest" "" "True" "extension"
119-
displayName: "Rerun tests"
109+
- task: AzureCLI@1
110+
displayName: 'Rerun tests'
111+
inputs:
112+
azureSubscription: $(AZURE_SDK_TEST_SUB_CONNECTED_SERVICE)
113+
scriptLocation: inlineScript
114+
inlineScript: |
115+
set -ev
116+
117+
source env/bin/activate
118+
cd azure-cli-extensions
119+
120+
az account set -s 0b1f6471-1bf0-4dda-aec3-cb9272f09590
121+
122+
python ../scripts/ci/automation_full_test.py "12" "$(Instance_idx)" "latest" "" "True" "extension"
120123
- bash: |
121124
publishErrorModules='false'
122125
if [[ -f '/$(HOME)/.azdev/env_config/mnt/vss/_work/1/s/env/test_results_error_modules_$(Instance_idx).txt' ]]; then
@@ -159,7 +162,7 @@ jobs:
159162
- task: AzureCLI@1
160163
displayName: 'Result Summary'
161164
inputs:
162-
azureSubscription: 'Azure CLI release'
165+
azureSubscription: $(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)
163166
scriptLocation: inlineScript
164167
inlineScript: |
165168
set -ev

scripts/regression_test/regression_test.yml

+21-18
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
- task: AzureCLI@1
2626
displayName: 'update version'
2727
inputs:
28-
azureSubscription: 'Azure CLI release'
28+
azureSubscription: $(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)
2929
scriptLocation: inlineScript
3030
inlineScript: |
3131
set -ev
@@ -93,7 +93,7 @@ jobs:
9393
- task: AzureCLI@1
9494
displayName: 'Checkout Target Branch'
9595
inputs:
96-
azureSubscription: 'Azure CLI release'
96+
azureSubscription: $(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)
9797
scriptLocation: inlineScript
9898
inlineScript: |
9999
set -ev
@@ -114,21 +114,24 @@ jobs:
114114
115115
git checkout -b ${GITHUB_BRANCH} ${GITHUB_REPO}/${GITHUB_BRANCH}
116116
- template: ../../.azure-pipelines/templates/azdev_setup.yml
117-
- bash: |
118-
set -ev
119-
120-
source env/bin/activate
121-
122-
if [[ -n "$(CUSTOM_WHL_URL)" ]]; then
123-
pip install $(CUSTOM_WHL_URL) --force-reinstall
124-
fi
125-
126-
az login -u $(CLI_LIVE_TEST_ACCOUNT) -p "$(CLI_LIVE_TEST_PASSWORD)"
127-
az account set -s 0b1f6471-1bf0-4dda-aec3-cb9272f09590
128-
129-
serial_modules="appservice botservice cloud network azure-cli-core azure-cli-telemetry"
130-
python scripts/ci/automation_full_test.py "8" "$(Instance_idx)" "latest" "$serial_modules" "True"
131-
displayName: "Rerun tests"
117+
- task: AzureCLI@1
118+
displayName: 'Rerun tests'
119+
inputs:
120+
azureSubscription: $(AZURE_SDK_TEST_SUB_CONNECTED_SERVICE)
121+
scriptLocation: inlineScript
122+
inlineScript: |
123+
set -ev
124+
125+
source env/bin/activate
126+
127+
if [[ -n "$(CUSTOM_WHL_URL)" ]]; then
128+
pip install $(CUSTOM_WHL_URL) --force-reinstall
129+
fi
130+
131+
az account set -s 0b1f6471-1bf0-4dda-aec3-cb9272f09590
132+
133+
serial_modules="appservice botservice cloud network azure-cli-core azure-cli-telemetry"
134+
python scripts/ci/automation_full_test.py "8" "$(Instance_idx)" "latest" "$serial_modules" "True"
132135
- task: PublishTestResults@2
133136
inputs:
134137
testResultsFiles: '/$(HOME)/.azdev/env_config/mnt/vss/_work/1/s/env/test_results_*.xml'
@@ -144,7 +147,7 @@ jobs:
144147
- task: AzureCLI@1
145148
displayName: 'Create PR'
146149
inputs:
147-
azureSubscription: 'Azure CLI release'
150+
azureSubscription: $(AZURE_SDK_INFRA_SUB_CONNECTED_SERVICE)
148151
scriptLocation: inlineScript
149152
inlineScript: |
150153
set -ev

src/azure-cli/azure/cli/command_modules/appconfig/_kv_helpers.py

+11-17
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from knack.log import get_logger
1919
from knack.util import CLIError
2020

21-
from azure.cli.command_modules.keyvault.vendored_sdks.azure_keyvault_t1.key_vault_id import KeyVaultIdentifier
21+
from azure.keyvault.secrets._shared import parse_key_vault_id
2222
from azure.appconfiguration import ResourceReadOnlyError, ConfigurationSetting
2323
from azure.core.exceptions import HttpResponseError
2424
from azure.cli.core.util import user_confirmation
@@ -314,12 +314,6 @@ def __read_kv_from_config_store(azconfig_client,
314314
elif top is None:
315315
top = 100
316316

317-
if cli_ctx:
318-
from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
319-
keyvault_client = keyvault_data_plane_factory(cli_ctx)
320-
else:
321-
keyvault_client = None
322-
323317
for setting in configsetting_iterable:
324318
kv = convert_configurationsetting_to_keyvalue(setting)
325319

@@ -333,8 +327,8 @@ def __read_kv_from_config_store(azconfig_client,
333327

334328
if kv.content_type and kv.value:
335329
# resolve key vault reference
336-
if keyvault_client and __is_key_vault_ref(kv):
337-
__resolve_secret(keyvault_client, kv)
330+
if cli_ctx and __is_key_vault_ref(kv):
331+
__resolve_secret(cli_ctx, kv)
338332

339333
# trim unwanted fields from kv object instead of leaving them as null.
340334
if fields:
@@ -437,7 +431,7 @@ def __read_kv_from_app_service(cmd, appservice_account, prefix_to_add="", conten
437431
secret_identifier = "https://{0}.vault.azure.net/secrets/{1}/{2}".format(vault_name, secret_name, secret_version)
438432
try:
439433
# this throws an exception for invalid format of secret identifier
440-
KeyVaultIdentifier(uri=secret_identifier)
434+
parse_key_vault_id(source_id=secret_identifier)
441435
kv = KeyValue(key=key,
442436
value=json.dumps({"uri": secret_identifier}, ensure_ascii=False, separators=(',', ':')),
443437
tags=tags,
@@ -816,15 +810,15 @@ def __compact_key_values(key_values):
816810
return compacted
817811

818812

819-
def __resolve_secret(keyvault_client, keyvault_reference):
820-
from azure.cli.command_modules.keyvault.vendored_sdks.azure_keyvault_t1.key_vault_id import SecretId
813+
def __resolve_secret(cli_ctx, keyvault_reference):
821814
try:
822815
secret_id = json.loads(keyvault_reference.value)["uri"]
823-
kv_identifier = SecretId(uri=secret_id)
816+
kv_identifier = parse_key_vault_id(source_id=secret_id)
817+
from azure.cli.command_modules.keyvault._client_factory import data_plane_azure_keyvault_secret_client
818+
keyvault_client = data_plane_azure_keyvault_secret_client(cli_ctx, kv_identifier.vault_url)
824819

825-
secret = keyvault_client.get_secret(vault_base_url=kv_identifier.vault,
826-
secret_name=kv_identifier.name,
827-
secret_version=kv_identifier.version)
820+
secret = keyvault_client.get_secret(name=kv_identifier.name,
821+
version=kv_identifier.version)
828822
keyvault_reference.value = secret.value
829823
return keyvault_reference
830824
except (TypeError, ValueError):
@@ -890,7 +884,7 @@ def __validate_import_keyvault_ref(kv):
890884
# URL with a valid scheme and netloc is a valid url, but keyvault ref has path as well, so validate it
891885
if parsed_url.scheme and parsed_url.netloc and parsed_url.path:
892886
try:
893-
KeyVaultIdentifier(uri=value['uri'])
887+
parse_key_vault_id(source_id=value['uri'])
894888
return True
895889
except Exception: # pylint: disable=broad-except
896890
pass

src/azure-cli/azure/cli/command_modules/appconfig/_validators.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ def validate_identity(namespace):
227227

228228
def validate_secret_identifier(namespace):
229229
""" Validate the format of keyvault reference secret identifier """
230-
from azure.cli.command_modules.keyvault.vendored_sdks.azure_keyvault_t1.key_vault_id import KeyVaultIdentifier
230+
from azure.keyvault.secrets._shared import parse_key_vault_id
231231

232232
identifier = getattr(namespace, 'secret_identifier', None)
233233
try:
234234
# this throws an exception for invalid format of secret identifier
235-
KeyVaultIdentifier(uri=identifier)
235+
parse_key_vault_id(source_id=identifier)
236236
except Exception as e:
237237
raise CLIError("Received an exception while validating the format of secret identifier.\n{0}".format(str(e)))
238238

src/azure-cli/azure/cli/command_modules/keyvault/_client_factory.py

+1-28
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ def get_client_factory(resource_type, client_name=''):
109109
if is_mgmt_plane(resource_type):
110110
return keyvault_mgmt_client_factory(resource_type, client_name)
111111
if resource_type == ResourceType.DATA_KEYVAULT:
112-
if client_name == Clients.private_7_2:
113-
return keyvault_private_data_plane_factory_v7_2_preview
114-
return keyvault_data_plane_factory
112+
return keyvault_private_data_plane_factory_v7_2_preview
115113
if resource_type == ResourceType.DATA_KEYVAULT_ADMINISTRATION_BACKUP:
116114
return data_plane_azure_keyvault_administration_backup_client
117115
if resource_type == ResourceType.DATA_KEYVAULT_ADMINISTRATION_ACCESS_CONTROL:
@@ -167,31 +165,6 @@ def _keyvault_mgmt_client_factory(cli_ctx, _):
167165
return _keyvault_mgmt_client_factory
168166

169167

170-
def keyvault_data_plane_factory(cli_ctx, *_):
171-
from azure.cli.command_modules.keyvault.vendored_sdks.azure_keyvault_t1 import (
172-
KeyVaultAuthentication, KeyVaultClient)
173-
from azure.cli.core.util import should_disable_connection_verify
174-
175-
version = str(get_api_version(cli_ctx, ResourceType.DATA_KEYVAULT))
176-
177-
def get_token(server, resource, scope): # pylint: disable=unused-argument
178-
return Profile(cli_ctx=cli_ctx).get_raw_token(resource=resource,
179-
subscription=cli_ctx.data.get('subscription_id'))[0]
180-
181-
client = KeyVaultClient(KeyVaultAuthentication(get_token), api_version=version)
182-
183-
# HACK, work around the fact that KeyVault library does't take confiuration object on constructor
184-
# which could be used to turn off the verifiaction. Remove this once we migrate to new data plane library
185-
# pylint: disable=protected-access
186-
if hasattr(client, '_client') and hasattr(client._client, 'config'):
187-
verify = not should_disable_connection_verify()
188-
client._client.config.connection.verify = verify
189-
else:
190-
logger.info('Could not find the configuration object to turn off the verification if needed')
191-
192-
return client
193-
194-
195168
def keyvault_private_data_plane_factory_v7_2_preview(cli_ctx, _):
196169
from azure.cli.command_modules.keyvault.vendored_sdks.azure_keyvault_t1 import (
197170
KeyVaultAuthentication, KeyVaultClient)

src/azure-cli/azure/cli/command_modules/keyvault/_command_type.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,9 @@ def _encode_hex(item):
2929
return item
3030

3131

32-
def keyvault_exception_handler(cmd, ex):
32+
def keyvault_exception_handler(ex):
3333
from msrest.exceptions import ValidationError, ClientRequestError
34-
from azure.cli.core.profiles import ResourceType
35-
KeyVaultErrorException = cmd.get_models('KeyVaultErrorException', resource_type=ResourceType.DATA_KEYVAULT)
36-
if isinstance(ex, (ValidationError, KeyVaultErrorException)):
34+
if isinstance(ex, ValidationError):
3735
try:
3836
raise CLIError(ex.inner_exception.error.message)
3937
except AttributeError:
@@ -54,10 +52,9 @@ def keyvault_exception_handler(cmd, ex):
5452
class KeyVaultCommandGroup(AzCommandGroup):
5553

5654
def __init__(self, command_loader, group_name, **kwargs):
57-
from azure.cli.command_modules.keyvault._client_factory import keyvault_data_plane_factory
58-
# all regular and custom commands should use the keyvault data plane client
55+
from azure.cli.command_modules.keyvault._client_factory import keyvault_mgmt_client_factory
5956
merged_kwargs = self._merge_kwargs(kwargs, base_kwargs=command_loader.module_kwargs)
60-
merged_kwargs['custom_command_type'].settings['client_factory'] = keyvault_data_plane_factory
57+
merged_kwargs['custom_command_type'].settings['client_factory'] = keyvault_mgmt_client_factory
6158
super(KeyVaultCommandGroup, self).__init__(command_loader, group_name, **kwargs)
6259

6360
def _create_keyvault_command(self, name, method_name=None, command_type_name=None, **kwargs):
@@ -135,7 +132,7 @@ def keyvault_command_handler(command_args):
135132
show_exception_handler(ex)
136133
except Exception: # pylint: disable=broad-except
137134
pass
138-
return keyvault_exception_handler(self.command_loader, ex)
135+
return keyvault_exception_handler(ex)
139136

140137
self.command_loader._cli_command(command_name, handler=keyvault_command_handler, # pylint: disable=protected-access
141138
argument_loader=keyvault_arguments_loader,

src/azure-cli/azure/cli/command_modules/keyvault/_completers.py

+46-21
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,35 @@
77
from azure.cli.core._profile import Profile
88

99

10-
def _get_token(cli_ctx, server, resource, scope): # pylint: disable=unused-argument
11-
return Profile(cli_ctx=cli_ctx).get_raw_token(resource)[0]
12-
13-
1410
def get_keyvault_name_completion_list(resource_name):
1511

1612
@Completer
1713
def completer(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument
18-
from .vendored_sdks.azure_keyvault_t1 import KeyVaultAuthentication, KeyVaultClient
19-
from azure.cli.core.profiles import ResourceType, get_api_version
20-
version = str(get_api_version(cmd.cli_ctx, ResourceType.DATA_KEYVAULT))
21-
client = KeyVaultClient(KeyVaultAuthentication(_get_token), api_version=version)
22-
func_name = 'get_{}s'.format(resource_name)
14+
func_name = 'list_properties_of_{}s'.format(resource_name)
2315
vault = namespace.vault_base_url
16+
profile = Profile(cli_ctx=cmd.cli_ctx)
17+
credential, _, _ = profile.get_login_credentials(subscription_id=cmd.cli_ctx.data.get('subscription_id'))
18+
if resource_name == 'key':
19+
from azure.keyvault.keys import KeyClient
20+
from azure.cli.command_modules.keyvault._client_factory import is_azure_stack_profile
21+
version = '7.5-preview.1' if not is_azure_stack_profile(cmd=cmd) else '2016-10-01'
22+
client = KeyClient(vault_url=vault, credential=credential, api_version=version,
23+
verify_challenge_resource=False)
24+
elif resource_name == 'secret':
25+
from azure.keyvault.secrets import SecretClient
26+
from azure.cli.command_modules.keyvault._client_factory import is_azure_stack_profile
27+
version = '7.4' if not is_azure_stack_profile(cmd=cmd) else '2016-10-01'
28+
client = SecretClient(vault_url=vault, credential=credential, api_version=version,
29+
verify_challenge_resource=False)
30+
else:
31+
from azure.keyvault.certificates import CertificateClient
32+
from azure.cli.command_modules.keyvault._client_factory import is_azure_stack_profile
33+
version = '7.4' if not is_azure_stack_profile(cmd=cmd) else '2016-10-01'
34+
client = CertificateClient(vault_url=vault, credential=credential, api_version=version,
35+
verify_challenge_resource=False)
2436
items = []
25-
for y in list(getattr(client, func_name)(vault)):
26-
id_val = getattr(y, 'id', None) or getattr(y, 'kid', None)
27-
items.append(id_val.rsplit('/', 1)[1])
37+
for y in list(getattr(client, func_name)()):
38+
items.append(y.name)
2839
return items
2940

3041
return completer
@@ -34,17 +45,31 @@ def get_keyvault_version_completion_list(resource_name):
3445

3546
@Completer
3647
def completer(cmd, prefix, namespace, **kwargs): # pylint: disable=unused-argument
37-
from .vendored_sdks.azure_keyvault_t1 import KeyVaultAuthentication, KeyVaultClient
38-
from azure.cli.core.profiles import ResourceType, get_api_version
39-
version = str(get_api_version(cmd.cli_ctx, ResourceType.DATA_KEYVAULT))
40-
client = KeyVaultClient(KeyVaultAuthentication(_get_token), api_version=version)
41-
func_name = 'get_{}_versions'.format(resource_name)
48+
func_name = 'list_properties_of_{}_versions'.format(resource_name)
4249
vault = namespace.vault_base_url
43-
name = getattr(namespace, '{}_name'.format(resource_name))
50+
profile = Profile(cli_ctx=cmd.cli_ctx)
51+
credential, _, _ = profile.get_login_credentials(subscription_id=cmd.cli_ctx.data.get('subscription_id'))
52+
if resource_name == 'key':
53+
from azure.keyvault.keys import KeyClient
54+
from azure.cli.command_modules.keyvault._client_factory import is_azure_stack_profile
55+
version = '7.5-preview.1' if not is_azure_stack_profile(cmd=cmd) else '2016-10-01'
56+
client = KeyClient(vault_url=vault, credential=credential, api_version=version,
57+
verify_challenge_resource=False)
58+
elif resource_name == 'secret':
59+
from azure.keyvault.secrets import SecretClient
60+
from azure.cli.command_modules.keyvault._client_factory import is_azure_stack_profile
61+
version = '7.4' if not is_azure_stack_profile(cmd=cmd) else '2016-10-01'
62+
client = SecretClient(vault_url=vault, credential=credential, api_version=version,
63+
verify_challenge_resource=False)
64+
else:
65+
from azure.keyvault.certificates import CertificateClient
66+
from azure.cli.command_modules.keyvault._client_factory import is_azure_stack_profile
67+
version = '7.4' if not is_azure_stack_profile(cmd=cmd) else '2016-10-01'
68+
client = CertificateClient(vault_url=vault, credential=credential, api_version=version,
69+
verify_challenge_resource=False)
4470
items = []
45-
for y in list(getattr(client, func_name)(vault, name)):
46-
id_val = getattr(y, 'id', None) or getattr(y, 'kid', None)
47-
items.append(id_val.rsplit('/', 1)[1])
71+
for y in list(getattr(client, func_name)()):
72+
items.append(y.version)
4873
return items
4974

5075
return completer

0 commit comments

Comments
 (0)