Prevent duplicate rotation for same request
This commit is contained in:
Родитель
2a604b3323
Коммит
7af9f53a09
|
@ -37,11 +37,17 @@ function AddSecretToKeyVault($keyVAultName,$secretName,$secretvalue,$exprityDate
|
|||
|
||||
}
|
||||
|
||||
function RoatateSecret($keyVaultName,$secretName){
|
||||
function RoatateSecret($keyVaultName,$secretName,$secretVersion){
|
||||
#Retrieve Secret
|
||||
$secret = (Get-AzKeyVaultSecret -VaultName $keyVAultName -Name $secretName)
|
||||
Write-Host "Secret Retrieved"
|
||||
|
||||
If($secret.Version -ne $secretVersion){
|
||||
#if current version is different than one retrived in event
|
||||
Write-Host "Secret version is already rotated"
|
||||
return
|
||||
}
|
||||
|
||||
#Retrieve Secret Info
|
||||
$validityPeriodDays = $secret.Tags["ValidityPeriodDays"]
|
||||
$credentialId= $secret.Tags["CredentialId"]
|
||||
|
@ -77,12 +83,15 @@ $ErrorActionPreference = "Stop"
|
|||
$eventGridEvent | ConvertTo-Json | Write-Host
|
||||
|
||||
$secretName = $eventGridEvent.subject
|
||||
$secretVersion = $eventGridEvent.data.Version
|
||||
$keyVaultName = $eventGridEvent.data.VaultName
|
||||
|
||||
Write-Host "Key Vault Name: $keyVAultName"
|
||||
Write-Host "Secret Name: $secretName"
|
||||
Write-Host "Secret Name: $secretVersion"
|
||||
|
||||
#Rotate secret
|
||||
Write-Host "Rotation started."
|
||||
RoatateSecret $keyVAultName $secretName
|
||||
RoatateSecret $keyVAultName $secretName $secretVersion
|
||||
Write-Host "Secret Rotated Successfully"
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче