Skip to content

Improved the error message of Az.KeyVault.Extension #16815

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 2 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,30 @@
function Check-SubscriptionLogIn
{
param (
[string] $SubscriptionId,
[string] $AzKVaultName
[object] $SubscriptionId,
[object] $AzKVaultName
)

if("string" -ne $SubscriptionId.GetType().Name)
{
throw "The type of SubscriptionId should be string, current is " + $SubscriptionId.GetType().Name + ". Please check registration information by 'Get-SecretVault | fl'"
}

if("string" -ne $AzKVaultName.GetType().Name)
{
throw "The type of AzKVaultName should be string, current is " + $AzKVaultName.GetType().Name + ". Please check registration information by 'Get-SecretVault | fl'"
}

$azContext = Az.Accounts\Get-AzContext
if (($azContext -eq $null) -or ($azContext.Subscription.Id -ne $SubscriptionId))
if (($null -eq $azContext) -or ($azContext.Subscription.Id -ne $SubscriptionId))
{
try
{
Set-AzContext -SubscriptionId ${SubscriptionId} -ErrorAction Stop
}
catch
{
throw "To use ${AzKVaultName} Azure vault, the current user must be logged into Azure account subscription ${SubscriptionId}. Run 'Connect-AzAccount -SubscriptionId ${SubscriptionId}'."
throw $_.ToString() + "To use Azure vault named '${AzKVaultName}', please try 'Connect-AzAccount -SubscriptionId {SubscriptionId}' to log into Azure account subscription '${SubscriptionId}'."
}
}
}
Expand All @@ -33,7 +43,7 @@ function Get-Secret
Check-SubscriptionLogIn $AdditionalParameters.SubscriptionId $AdditionalParameters.AZKVaultName

$secret = Az.KeyVault\Get-AzKeyVaultSecret -Name $Name -VaultName $AdditionalParameters.AZKVaultName
if ($secret -ne $null)
if ($null -ne $secret)
{
switch ($secret.ContentType) {
'ByteArray'
Expand Down
1 change: 1 addition & 0 deletions src/KeyVault/KeyVault/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Improved the error message of Az.KeyVault.Extension [#16798]
* Added default access policies for Key Vault key as "All but purge"
* Absorbed KeyOps from parameter when importing key from certificate on managed HSM [#16773]
* Fixed a bug when updating key operations on managed HSM [#16774]
Expand Down