-
Notifications
You must be signed in to change notification settings - Fork 1.6k
add az vmware script* #3722
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
Merged
add az vmware script* #3722
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f129c94
custom action for script execution params
cataggar 74ced2d
script-execution tests recorded
cataggar 0542e07
package and cmdlet tests passing
cataggar b0ebe65
update help
cataggar 99bda24
add named outputs
cataggar 6833ac0
recording are generated
cataggar b139a94
mv .gitattributes to root
cataggar 0ec860f
mv .gitattributes
cataggar 086e2df
it is in azext_vmware
cataggar f26da08
fix style
cataggar f08c74d
fix linter errors
cataggar d8cc242
suppress cred scan false positive
cataggar 7a709dc
remove credential test
cataggar e4d3dfd
Merge remote-tracking branch 'origin/main' into az-vmware-script
cataggar c7bcd09
raise InvalidArgumentValueError, RequiredArgumentMissingError
cataggar 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| src/vmware/azext_vmware/tests/latest/recordings/*.yaml linguist-generated=true | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
|
|
||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| # pylint: disable=line-too-long, protected-access, too-few-public-methods | ||
|
|
||
| import argparse | ||
| from typing import Dict, List | ||
| from azure.cli.core.azclierror import InvalidArgumentValueError, RequiredArgumentMissingError | ||
| from knack.util import CLIError | ||
| from azext_vmware.vendored_sdks.avs_client.models import ScriptExecutionParameter, ScriptExecutionParameterType, ScriptStringExecutionParameter, ScriptSecureStringExecutionParameter, PSCredentialExecutionParameter | ||
|
|
||
|
|
||
| class ScriptExecutionNamedOutputAction(argparse._AppendAction): | ||
|
|
||
| def __call__(self, parser, namespace, values, option_string=None): | ||
| namespace.named_outputs = script_execution_named_outputs(values) | ||
|
|
||
|
|
||
| def script_execution_named_outputs(values: List[str]) -> Dict[str, str]: | ||
| try: | ||
| return dict(map(lambda x: x.split('=', 1), values)) | ||
| except ValueError as error: | ||
| raise CLIError('parsing named output parameter \'{}\''.format(values)) from error | ||
|
cataggar marked this conversation as resolved.
|
||
|
|
||
|
|
||
| class ScriptExecutionParameterAction(argparse._AppendAction): | ||
|
|
||
| def __call__(self, parser, namespace, values, option_string=None): | ||
| parameter = script_execution_parameters(values) | ||
| if namespace.parameters: | ||
| namespace.parameters.append(parameter) | ||
| else: | ||
| namespace.parameters = [parameter] | ||
|
|
||
|
|
||
| def script_execution_parameters(values: List[str]) -> ScriptExecutionParameter: | ||
| values = dict(map(lambda x: x.split('=', 1), values)) | ||
| tp = require(values, "type") | ||
| type_lower = tp.lower() | ||
|
|
||
| if type_lower == ScriptExecutionParameterType.VALUE.lower(): | ||
| try: | ||
| return ScriptStringExecutionParameter(name=require(values, "name"), value=values.get("value")) | ||
| except CLIError as error: | ||
| raise InvalidArgumentValueError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.VALUE)) from error | ||
|
|
||
| elif type_lower == ScriptExecutionParameterType.SECURE_VALUE.lower(): | ||
| try: | ||
| return ScriptSecureStringExecutionParameter(name=require(values, "name"), secure_value=values.get("secureValue")) | ||
| except CLIError as error: | ||
| raise InvalidArgumentValueError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.SECURE_VALUE)) from error | ||
|
|
||
| elif type_lower == ScriptExecutionParameterType.CREDENTIAL.lower(): | ||
| try: | ||
| return PSCredentialExecutionParameter(name=require(values, "name"), username=values.get("username"), password=values.get("password")) | ||
| except CLIError as error: | ||
| raise InvalidArgumentValueError('parsing {} script execution parameter'.format(ScriptExecutionParameterType.CREDENTIAL)) from error | ||
|
|
||
| else: | ||
| raise InvalidArgumentValueError('script execution paramater type \'{}\' not matched'.format(tp)) | ||
|
|
||
|
|
||
| def require(values: Dict[str, str], key: str) -> str: | ||
| '''Gets the required script execution parameter or raises a CLIError.''' | ||
| value = values.get(key) | ||
| if value is None: | ||
| raise RequiredArgumentMissingError('script execution parameter \'{}\' required'.format(key)) | ||
| return value | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.