-
-
Save Madhufuture/82e6cae683fdb9a506166a652dbbd14c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################## | |
# 1) Get ACS Connection string # | |
# 2) Read all the json in the repo folder # | |
# 3) Insert each json file data into ACS # | |
# 4) Read the json file content and construct the key # | |
# 5) Read the key values from ACS # | |
# 6) Compare json file content keys vs ACS keys # | |
# 7) Delete the delta keys in ACS # | |
######################################################## | |
# Get the connection string | |
$connString=az appconfig credential list -g {resource group} -n {name of the app config service} --query "[0].{name:connectionString}" --output tsv | |
$folder="int-mso" | |
Get-ChildItem -Path "." -Recurse -Filter *.json | Where-Object {$_.DirectoryName -match $folder} | |
ForEach-Object { | |
Write-Host "file name: ",$_.FullName | |
az appconfig kv import --name {name of the app config service} --label '$folder' -s file --format json --path $_.FullName --auth-mode key --connection-string $connString --depth 3 --separator : --yes | |
# Reading data from json file | |
$resourceNames=[System.Collections.ArrayList]@() | |
$Content=Get-Content $_.FullName | |
$data=$Content | ConvertFrom-Json | |
foreach($s in $data.PSObject.Properties) | |
{ | |
$rootNode=$s.Name | |
foreach($r1 in $data.$rootNode) | |
{ | |
$childNode = $($r1 | Get-Member -MemberType *Property).Name | |
for($i=0;$i -lt $childNode.Count;$i++) | |
{ | |
if($childNode.Count -eq 1) | |
{ | |
$childNode1=$($r1 | Get-Member -MemberType *Property).Name | |
} | |
elseif($childNode.Count -gt 1) | |
{ | |
$childNode1=$($r1 | Get-Member -MemberType *Property).Name[$i]; | |
} | |
foreach($r2 in $data.$rootNode.$childNode1) | |
{ | |
$childNode2=$($r2 | Get-Member -MemberType *Property).Name | |
$resourceNames.Add($rootNode+':'+$childNode1+':'+$childNode2) | |
} | |
} | |
} | |
} | |
for($i=0;$i -lt $resourceNames.Count;$i++) | |
{ | |
Write-Host ('Values from json: '+$resourceNames[$i]) | |
} | |
# end reading data from json file | |
# Reading data from ACS | |
$fileName = $_.Name | |
$fileNamewithoutExt = [System.IO.Path]::GetFileNameWithoutExtension($fileName) | |
Write-Host $fileNamewithoutExt | |
$keys=az appconfig kv list -n {name of the app config service} --key $fileNamewithoutExt* --label test --auth-mode key --connection-string $connString --fields key --output tsv | |
#end reading data from ACS | |
for($i=0;$i -lt $keys.Count;$i++) | |
{ | |
Write-Host ('Values from ACS: '+$keys[$i]) | |
} | |
$diffKeys=$keys | where {$resourceNames -notcontains $_} | |
for($i=0;$i -lt $diffKeys.Count;$i++) | |
{ | |
if($diffKeys.Count -eq 1) | |
{ | |
az appconfig kv delete --key $diffKeys --connection-string $connString -n {name of the app config service} --auth-mode key --yes | |
} | |
elseif($diffKeys.Count -gt 1) | |
{ | |
for($i=0;$i -lt $diffKeys.Count; $i++) | |
{ | |
az appconfig kv delete --key $diffKeys[$i] --connection-string $connString -n {name of the app config service} --auth-mode key --yes | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment