PSAzureAppConfiguration.psm1
#Region '.\Public\Convert-KeyReference.ps1' 0 function Convert-KeyReference { [cmdletbinding()] param( $String , $Dictionary , $Prefix = '\$\(' , $Suffix = '\)' ) $stringOutput = $string $references = Get-KeyReference -String $string -Regex "$Prefix[\w.]*$Suffix" if (-not $references) { Return $stringOutput } $references | Foreach-Object { $refKey = $_ $refValue = ($Dictionary | Where-Object {$_.key -eq $refkey}).Value Write-Verbose "$refkey resolved to $refValue" $stringOutput = $stringOutput -replace "$Prefix$refKey$Suffix",$refValue } Convert-KeyReference -String $stringOutput -Dictionary $Dictionary } #EndRegion '.\Public\Convert-KeyReference.ps1' 25 #Region '.\Public\ConvertFrom-UnixTime.ps1' 0 Function ConvertFrom-UnixTime ($unixtime) { <# .DESCRIPTION Datetimes from JSON are stored as Unixtime. We need this funtion to convert it back as 'Human' time .EXAMPLE (ConvertFrom-UnixTime 1550504688).toString() Expected Output: "18/02/2019 15:44:48" #> if ( ($unixtime -ne -1) -and ($null -ne $unixtime) ) { $origin = New-Object -Type DateTime -ArgumenTlist 1970, 1, 1, 0, 0, 0, 0 $datetime = $origin.AddSeconds($unixtime) Return $datetime } else { return $null } } #EndRegion '.\Public\ConvertFrom-UnixTime.ps1' 19 #Region '.\Public\Get-AppConfigurationKeyValue.ps1' 0 function Get-AppConfigurationKeyValue { [cmdletbinding()] param( [string] $Key = '*' , [string] $Store , [string] $Label = '*' , [switch] $NoResolveSecret , [switch] $ExcludeNoLabel ) # az appconfig kv list -h If (-not $NoResolveSecret) { $resolveKv = '--resolve-keyvault' } $Output = az appconfig kv list --name $Store --label \0 --key $Key $resolveKv | ConvertFrom-Json $Output += az appconfig kv list --name $Store --label $Label --key $Key $resolveKv | ConvertFrom-Json ForEach ($kv in $Output) { $value = $kv.value $value = Convert-KeyReference -String $value -Dictionary $Output Write-Output @{ $kv.key = $value} } } #EndRegion '.\Public\Get-AppConfigurationKeyValue.ps1' 27 #Region '.\Public\Get-KeyReference.ps1' 0 function Get-KeyReference { <# .SYNOPSIS Parses a string and extracts the tokenized strings Default prefix and suffix is '$(' and ')' Only words chars and dots are allowed as key strings .EXAMPLE Get-KeyReference -String 'MyServer=$(MyApp.Database.Server);Database=$(MyApp.Database.Name);Trusted_Connection=Yes' Expected Output: @('MyApp.Database.Server','MyApp.Database.Name') .EXAMPLE $string = '$(MyDomain)\$(MyUserName)_$(Environment)' Get-KeyReference -String $string Expected Output: @('MyDomain','MyUserName','Environment') #> param( [string] $String , [string] $regex = '\$\([\w.]*\)' ) $references = ($string | select-string -pattern $regex -AllMatches).Matches.Value if ($references) { $references.replace('$(','').replace(')','') } } #EndRegion '.\Public\Get-KeyReference.ps1' 25 |