You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sync eng/common directory with azure-sdk-tools for PR 1912 (#20340)
* Attempt to purge all vaults, managed HSMs
Reverts #1910. Vaults and managed HSMs are automatically purged on their purge date. The point was to purge them daily to preserve capacity. The default purge date is +90 days.
* Add timeout and more logging
* Pass required -Resource
* Fix log message
* Ensure the $Resource is correctly captured
Added comment to new code explaining why, since ScriptBlock.GetNewClosure() is not working as expected.
* Add -ErrorAction to Receive-Job
Worked without terminating when run locally, but failed on the first error in the AzDO agent.
* Use $using:r instead of creating ScriptBlock
More idiomatic for passing ScriptBlocks to jobs.
* Resolve PR feedback
* Change default DeleteAfterHours to 120
Resolves#1917
* Use the Az cmdlets built-in -AsJob
Co-authored-by: Heath Stewart <[email protected]>
Log "Attempting to purge $($r.AzsdkResourceType) '$($r.Name)'"
109
124
if ($r.EnablePurgeProtection) {
110
-
# We will try anyway but will ignore errors
125
+
# We will try anyway but will ignore errors.
111
126
Write-Warning"Managed HSM '$($r.Name)' has purge protection enabled and may not be purged for $($r.SoftDeleteRetentionInDays) days"
112
127
}
113
128
114
-
$response=Invoke-AzRestMethod-Method POST -Path "/subscriptions/$subscriptionId/providers/Microsoft.KeyVault/locations/$($r.Location)/deletedManagedHSMs/$($r.Name)/purge?api-version=2021-04-01-preview"-ErrorAction Ignore
115
-
if ($response.StatusCode-ge200-and$response.StatusCode-lt300) {
116
-
Write-Warning"Successfully requested that Managed HSM '$($r.Name)' be purged, but may take a few minutes before it is actually purged."
117
-
} elseif ($response.Content) {
118
-
$content=$response.Content|ConvertFrom-Json
119
-
if ($content.error) {
120
-
$err=$content.error
121
-
Write-Warning"Failed to deleted Managed HSM '$($r.Name)': ($($err.code)) $($err.message)"
122
-
}
123
-
}
129
+
# Use `GetNewClosure()` on the `-Action` ScriptBlock to make sure variables are captured.
130
+
Invoke-AzRestMethod-Method POST -Path "/subscriptions/$subscriptionId/providers/Microsoft.KeyVault/locations/$($r.Location)/deletedManagedHSMs/$($r.Name)/purge?api-version=2021-04-01-preview"-ErrorAction Ignore -AsJob `
if ($response.StatusCode-ge200-and$response.StatusCode-lt300) {
134
+
Write-Warning"Successfully requested that Managed HSM '$($r.Name)' be purged, but may take a few minutes before it is actually purged."
135
+
} elseif ($response.Content) {
136
+
$content=$response.Content|ConvertFrom-Json
137
+
if ($content.error) {
138
+
$err=$content.error
139
+
Write-Warning"Failed to deleted Managed HSM '$($r.Name)': ($($err.code)) $($err.message)"
140
+
}
141
+
}
142
+
}.GetNewClosure()
124
143
}
125
144
126
145
default {
127
-
Write-Warning"Cannot purge resource type $($r.AzsdkResourceType). Add support to https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/scripts/Helpers/Resource-Helpers.ps1."
146
+
Write-Warning"Cannot purge $($r.AzsdkResourceType) '$($r.AzsdkName)'. Add support to https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/scripts/Helpers/Resource-Helpers.ps1."
0 commit comments