Add secret provider functionality and enhance configuration data resolution
This commit is contained in:
40
Private/Register-ConfigurationDataSecretProvider.ps1
Normal file
40
Private/Register-ConfigurationDataSecretProvider.ps1
Normal file
@@ -0,0 +1,40 @@
|
||||
function Register-ConfigurationDataSecretProvider {
|
||||
[CmdletBinding()]
|
||||
Param(
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string]
|
||||
$Name,
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[string[]]
|
||||
$SupportedTypes,
|
||||
|
||||
[Parameter(Mandatory=$true)]
|
||||
[scriptblock]
|
||||
$Resolver
|
||||
)
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($Name)){
|
||||
throw "Secret provider [Name] must not be empty."
|
||||
}
|
||||
|
||||
if($SupportedTypes.Count -eq 0){
|
||||
throw "Secret provider [$Name] must define at least one supported type."
|
||||
}
|
||||
|
||||
foreach($Type in $SupportedTypes){
|
||||
if($Type -notin @("credential", "securestring", "string")){
|
||||
throw "Secret provider [$Name] uses unsupported type [$Type]."
|
||||
}
|
||||
}
|
||||
|
||||
if($null -eq $script:ConfigurationDataSecretProviders){
|
||||
$script:ConfigurationDataSecretProviders = @{}
|
||||
}
|
||||
|
||||
$script:ConfigurationDataSecretProviders[$Name.ToLowerInvariant()] = [PSCustomObject]@{
|
||||
Name = $Name
|
||||
SupportedTypes = @($SupportedTypes | ForEach-Object { $_.ToLowerInvariant() })
|
||||
Resolver = $Resolver
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user