Skip to content

[Keyvault] az keyvault secret download: Add --overwrite flag#31659

Merged
a0x1ab merged 12 commits intoAzure:devfrom
a0x1ab:keyvault-overwrite-flag
Jun 17, 2025
Merged

[Keyvault] az keyvault secret download: Add --overwrite flag#31659
a0x1ab merged 12 commits intoAzure:devfrom
a0x1ab:keyvault-overwrite-flag

Conversation

@a0x1ab
Copy link
Copy Markdown
Member

@a0x1ab a0x1ab commented Jun 16, 2025

Related command
keyvault

Description

  • From feature request: "az keyvault secret download --file" should allow for overwriting of existing files #30994
  • az keyvault secret download command previously failed when provided with an existing file for the file path parameter.
  • Feature was requested to allow users to provide an existing file along with the overwrite flag to allow the secret downloaded to be overwritten onto the selected file path.
  • This feature allows users to provide an additional flag to the az keyvault secret download command to overwrite the existing file with the downloaded secret.
  • Cassette for re-recorded for future tests

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 secret

This checklist is used to make sure that common guidelines for a pull request are followed.

@a0x1ab a0x1ab requested review from bebound and Copilot June 16, 2025 05:19
@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Jun 16, 2025

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.9
️✔️acs
️✔️latest
️✔️3.12
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.9
️✔️ams
️✔️latest
️✔️3.12
️✔️3.9
️✔️apim
️✔️latest
️✔️3.12
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️aro
️✔️latest
️✔️3.12
️✔️3.9
️✔️backup
️✔️latest
️✔️3.12
️✔️3.9
️✔️batch
️✔️latest
️✔️3.12
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.9
️✔️billing
️✔️latest
️✔️3.12
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.9
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.9
️✔️config
️✔️latest
️✔️3.12
️✔️3.9
️✔️configure
️✔️latest
️✔️3.12
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.9
️✔️container
️✔️latest
️✔️3.12
️✔️3.9
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.9
️✔️core
️✔️latest
️✔️3.12
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.9
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.9
️✔️dls
️✔️latest
️✔️3.12
️✔️3.9
️✔️dms
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.9
️✔️find
️✔️latest
️✔️3.12
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.9
️✔️identity
️✔️latest
️✔️3.12
️✔️3.9
️✔️iot
️✔️latest
️✔️3.12
️✔️3.9
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.9
️✔️lab
️✔️latest
️✔️3.12
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️maps
️✔️latest
️✔️3.12
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.9
️✔️network
️✔️latest
️✔️3.12
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.9
️✔️profile
️✔️latest
️✔️3.12
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.9
️✔️redis
️✔️latest
️✔️3.12
️✔️3.9
️✔️relay
️✔️latest
️✔️3.12
️✔️3.9
️✔️resource
️✔️latest
️✔️3.12
️✔️3.9
️✔️role
️✔️latest
️✔️3.12
️✔️3.9
️✔️search
️✔️latest
️✔️3.12
️✔️3.9
️✔️security
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.9
️✔️sql
️✔️latest
️✔️3.12
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.9
️✔️storage
️✔️latest
️✔️3.12
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.9
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.9
️✔️util
️✔️latest
️✔️3.12
️✔️3.9
️✔️vm
️✔️latest
️✔️3.12
️✔️3.9

@azure-client-tools-bot-prd
Copy link
Copy Markdown

azure-client-tools-bot-prd bot commented Jun 16, 2025

⚠️AzureCLI-BreakingChangeTest
⚠️keyvault
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd keyvault secret download cmd keyvault secret download added parameter overwrite

@github-actions
Copy link
Copy Markdown

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Jun 16, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces an --overwrite flag to the az keyvault secret download command, allowing users to overwrite an existing file instead of failing. It updates the command implementation, CLI parameter definitions, and adds corresponding tests.

  • Added overwrite parameter and conditional logic in download_secret
  • Defined the --overwrite argument in parameter configuration
  • Expanded tests to cover download without and with the overwrite flag

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test_keyvault_commands.py Refactored download tests and added overwrite tests
custom.py Updated download_secret to accept and handle flag
_params.py Added --overwrite argument to the download command

@bebound
Copy link
Copy Markdown
Contributor

bebound commented Jun 16, 2025

You need to change overwrite to `--overwrite` to pass the PR title check.

Our CI is broken now. Please wait #31652 to be merged and update the code.

@a0x1ab a0x1ab changed the title [Keyvault] az keyvault secret download : Add overwrite flag [Keyvault] az keyvault secret download : Add --overwrite flag Jun 16, 2025
@a0x1ab
Copy link
Copy Markdown
Member Author

a0x1ab commented Jun 16, 2025

You need to change overwrite to `--overwrite` to pass the PR title check.

Our CI is broken now. Please wait #31652 to be merged and update the code.

Thank you @bebound, I have updated the PR title and merged from main as the PR #31652 has been merged.

@a0x1ab a0x1ab assigned a0x1ab and unassigned evelyn-ys Jun 16, 2025
@a0x1ab a0x1ab changed the title [Keyvault] az keyvault secret download : Add --overwrite flag [Keyvault] az keyvault secret download : Add --overwrite flag Jun 16, 2025
@a0x1ab a0x1ab changed the title [Keyvault] az keyvault secret download : Add --overwrite flag [Keyvault] az keyvault secret download: Add --overwrite flag Jun 16, 2025
""" Download a secret from a KeyVault. """
if os.path.isfile(file_path) or os.path.isdir(file_path):
raise CLIError("File or directory named '{}' already exists.".format(file_path))
if not overwrite and (os.path.isfile(file_path) or os.path.isdir(file_path)):
Copy link
Copy Markdown
Contributor

@bebound bebound Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edge case: if the given path is a directory, we're not able to overwrite it.

bebound
bebound previously approved these changes Jun 17, 2025
Comment thread src/azure-cli/azure/cli/command_modules/keyvault/_params.py Outdated
Co-authored-by: Yishi Wang <yishiwang@microsoft.com>
@a0x1ab a0x1ab requested a review from bebound June 17, 2025 08:33
@a0x1ab a0x1ab merged commit 2fb12fb into Azure:dev Jun 17, 2025
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auto-Assign Auto assign by bot KeyVault az keyvault

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants