Skip to content

Commit 788cddd

Browse files
committed
Add suggestion frm copilot to dsc resouces
1 parent 26ff4f5 commit 788cddd

3 files changed

Lines changed: 25 additions & 8 deletions

File tree

resources/windows_secretstore/test/windows_secretstore.config.tests.ps1

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Describe 'Windows SecretStore config tests' -Skip:(!$IsWindows) {
1515
return
1616
}
1717

18-
if (-not (Get-PackageProvider -Name NuGet -ListAvailable -ErrorAction SilentlyContinue)) {
19-
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Scope CurrentUser | Out-Null
20-
}
21-
22-
Install-Module -Name $Name -Repository PSGallery -Scope CurrentUser -Force -AllowClobber -Confirm:$false -ErrorAction Stop
18+
$installPsResourceCommand = Get-Command -Name Install-PSResource -ErrorAction SilentlyContinue
19+
if (-not $installPsResourceCommand) {
20+
throw "Install-PSResource is required to install test dependency module '$Name'."
21+
Install-PSResource -Name $Name -Scope CurrentUser -TrustRepository -Quiet -ErrorAction Stop
22+
}
2323
}
2424

2525
foreach ($moduleName in @(

resources/windows_secretstore/windows_secretstore.dsc.resource.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"properties": {
6767
"authentication": {
6868
"title": "Authentication",
69-
"description": "Specifies whether the SecretStore vault requires a password for access. This DSC resource runs non-interactively and only supports 'None' for unattended automation.",
69+
"description": "Specifies the SecretStore authentication mode for vault access. Allowed values are 'None', 'Prompt', and 'Password'.",
7070
"type": "string",
7171
"enum": [
7272
"None",
@@ -105,7 +105,8 @@
105105
"null"
106106
],
107107
"default": null
108-
}
108+
},
109+
"additionalProperties": false
109110
}
110111
}
111112
}

resources/windows_secretstore/windows_secretstore.ps1

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,24 @@ switch ($Operation) {
306306
} else {
307307
'SecretStore requires interactive input.'
308308
}
309+
310+
$allowDestructiveReset = $false
311+
if ($null -ne $env:DSC_SECRETSTORE_ALLOW_RESET) {
312+
$allowDestructiveReset = $env:DSC_SECRETSTORE_ALLOW_RESET -match '^(?i:true|1|yes)$'
313+
}
314+
if (-not $allowDestructiveReset) {
315+
$errorMessage = (
316+
"$reason Reset-SecretStore was blocked because it is destructive and can remove existing secrets. " +
317+
"To allow this fallback intentionally, set the environment variable " +
318+
"'DSC_SECRETSTORE_ALLOW_RESET' to 'true' before applying the configuration."
319+
)
320+
Write-DscTrace -Level Error -Message $errorMessage
321+
throw $errorMessage
322+
}
323+
309324
Write-DscTrace -Level Warn -Message (
310-
"$reason Attempting Reset-SecretStore with desired settings to enable unattended DSC execution."
325+
"$reason Proceeding with Reset-SecretStore because explicit opt-in was provided via " +
326+
"DSC_SECRETSTORE_ALLOW_RESET. This operation is destructive and may remove existing secrets."
311327
)
312328
Reset-SecretStore @resetParams -ErrorAction Stop
313329
}

0 commit comments

Comments
 (0)