[Keyvault] az keyvault secret download : Add overwrite flag#31650
[Keyvault] az keyvault secret download : Add overwrite flag#31650
az keyvault secret download : Add overwrite flag#31650Conversation
️✔️AzureCLI-FullTest
|
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| keyvault secret download | cmd keyvault secret download added parameter overwrite |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull Request Overview
This PR adds an overwrite flag to the "az keyvault secret download" command to allow overwriting existing files when downloading secrets.
- Modified tests to verify overwrite functionality.
- Updated the secret download helper in custom.py to support the new overwrite flag.
- Enhanced parameter definitions in _params.py to include the overwrite flag.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/latest/test_keyvault_commands.py | Updated test functions to pass dest_path and validate overwrite behavior. |
| custom.py | Modified download_secret to include and check the overwrite flag. |
| _params.py | Added the overwrite flag argument definition. |
Comments suppressed due to low confidence (1)
src/azure-cli/azure/cli/command_modules/keyvault/custom.py:1465
- [nitpick] Consider updating the associated error message to mention that users can use the '--overwrite' flag to overwrite an existing file, which would provide clearer guidance on how to resolve the issue.
if not overwrite and (os.path.isfile(file_path) or os.path.isdir(file_path)):
| dest_path = os.path.join(TEST_DIR, 'recover-{}'.format(encoding)) | ||
| _test_set_and_download(encoding, dest_path) | ||
| _test_download_with_overwrite(encoding, dest_path) | ||
| if os.path.exists(dest_path): |
There was a problem hiding this comment.
[nitpick] Consider using a try-finally block or the test framework's cleanup features to ensure that the dest_path file is removed even if an assertion fails, thereby improving test reliability.
|
@microsoft-github-policy-service agree company="Microsoft" |
| help="Encoding of the secret. By default, will look for the 'file-encoding' tag on the secret. " | ||
| "Otherwise will assume 'utf-8'.", default=None) | ||
| c.argument('overwrite', arg_type=get_three_state_flag(), options_list=['--overwrite'], help="Overwrite the file if it exists.", | ||
| default=False) |
There was a problem hiding this comment.
Since download_secret has overwrite=False, we don't need to set default value here.
This line exceeds 120 characters; we only exceed the limit if there’s a valid reason.
|
|
||
| # region KeyVault Secret | ||
| def download_secret(client, file_path, name=None, encoding=None, version=''): # pylint: disable=unused-argument | ||
| def download_secret(client, file_path, name=None, encoding=None, version='', overwrite: bool = False): # pylint: disable=unused-argument |
There was a problem hiding this comment.
Our project does not have type hinting.
| """ Download a secret from a KeyVault. """ | ||
| if os.path.isfile(file_path) or os.path.isdir(file_path): | ||
| if not overwrite and (os.path.isfile(file_path) or os.path.isdir(file_path)): | ||
| raise CLIError("File or directory named '{}' already exists.".format(file_path)) |
There was a problem hiding this comment.
We can improve the error message by adding an introduction to overwrite.
|
For the PR title, it usually looks like this: |
az keyvault secret download : Add overwrite flag
Related command
keyvault
Description
az keyvault secret downloadcommand previously failed when provided with an existing file for the file path parameter.az keyvault secret downloadcommand to overwrite the existing file with the downloaded secret.Testing Guide
az keyvault secret download --vault-name {kv} -n download-{enc} --file "{dest_path}" --overwrite: overwrite existing path file with the contents of the downloaded secretThis checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.