- Removed KeePass and SecretStore provider implementations. - Integrated KeePass and SecretStore as vaults under the SecretManagement provider. - Added new functions: Get-DSCConfigurationDataCredentialProvider and Set-DSCConfigurationDataCredentialProvider for managing credential providers. - Implemented Unlock-ConfigurationDataSecretManagementVault to handle vault unlocking with master passwords. - Updated README to reflect changes in provider usage and examples. - Enhanced error handling and validation for vault registration and settings.
101 lines
3.2 KiB
PowerShell
101 lines
3.2 KiB
PowerShell
function Unregister-DSCConfigurationDataCredentialProvider {
|
|
[CmdletBinding(SupportsShouldProcess=$true, ConfirmImpact="High")]
|
|
Param(
|
|
[Parameter(Mandatory=$true)]
|
|
[string]
|
|
$Vault,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[string]
|
|
$SettingsPath,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[switch]
|
|
$RemoveSettings,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[switch]
|
|
$UnregisterVault,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[switch]
|
|
$Force,
|
|
|
|
[Parameter(Mandatory=$false)]
|
|
[switch]
|
|
$PassThru
|
|
)
|
|
|
|
DynamicParam {
|
|
$ProviderNames = @(Get-ConfigurationDataSecretProviderName)
|
|
if($ProviderNames.Count -eq 0){
|
|
$ProviderNames = @("__NoProvidersRegistered__")
|
|
}
|
|
|
|
$ParameterAttribute = [System.Management.Automation.ParameterAttribute]::new()
|
|
$ParameterAttribute.Mandatory = $false
|
|
$ParameterAttribute.Position = 0
|
|
|
|
$ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute -ArgumentList (,[string[]]$ProviderNames)
|
|
$Attributes = [System.Collections.ObjectModel.Collection[System.Attribute]]::new()
|
|
$Attributes.Add($ParameterAttribute)
|
|
$Attributes.Add($ValidateSetAttribute)
|
|
|
|
$RuntimeParameter = [System.Management.Automation.RuntimeDefinedParameter]::new(
|
|
"Provider",
|
|
[string],
|
|
$Attributes
|
|
)
|
|
|
|
$Dictionary = [System.Management.Automation.RuntimeDefinedParameterDictionary]::new()
|
|
$Dictionary.Add("Provider", $RuntimeParameter)
|
|
return $Dictionary
|
|
}
|
|
|
|
begin {
|
|
$Provider = [string]$PSBoundParameters["Provider"]
|
|
if([string]::IsNullOrWhiteSpace($Provider)){
|
|
$ProviderNames = @(Get-ConfigurationDataSecretProviderName)
|
|
if($ProviderNames.Count -eq 1){
|
|
$Provider = $ProviderNames[0]
|
|
}elseif($ProviderNames.Count -eq 0){
|
|
throw "No configuration data secret providers are registered."
|
|
}else{
|
|
throw "Provider is required. Registered providers: $($ProviderNames -join ', ')."
|
|
}
|
|
}
|
|
|
|
$SettingsPath = Resolve-ConfigurationDataProviderSettingsPath -Provider $Provider -SettingsPath $SettingsPath
|
|
}
|
|
|
|
process {
|
|
$Result = [ordered]@{
|
|
Provider = $Provider
|
|
Vault = $Vault
|
|
SettingsPath = $SettingsPath
|
|
RemovedSettings = $false
|
|
UnregisteredVault = $false
|
|
}
|
|
|
|
if($RemoveSettings -or (-not $PSBoundParameters.ContainsKey("RemoveSettings"))){
|
|
if(Test-Path -Path $SettingsPath -PathType Leaf){
|
|
if($PSCmdlet.ShouldProcess($SettingsPath, "Remove provider settings file")){
|
|
Remove-Item -Path $SettingsPath -Force:$Force
|
|
$Result.RemovedSettings = $true
|
|
}
|
|
}
|
|
}
|
|
|
|
if($UnregisterVault){
|
|
if($PSCmdlet.ShouldProcess($Vault, "Unregister SecretManagement vault")){
|
|
Unregister-SecretVault -Name $Vault
|
|
$Result.UnregisteredVault = $true
|
|
}
|
|
}
|
|
|
|
if($PassThru){
|
|
return [PSCustomObject]$Result
|
|
}
|
|
}
|
|
}
|