forked from timoklimmer/powerproxy-aoai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added export/import config from/to Azure
- Loading branch information
1 parent
7bde9dd
commit ec16a6e
Showing
2 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<# | ||
.SYNOPSIS | ||
Exports a PowerProxy's configuration from a given Key Vault. | ||
.DESCRIPTION | ||
Writes a PowerProxy's configuration from the given Key Vault to the given file. | ||
.PARAMETER KeyVaultName | ||
Name of the Key Vault in which the configuration is stored. | ||
.EXAMPLE | ||
PS> .\Export-ConfigFromAzure.ps1 -KeyVaultName abdefpowerproxyaoai -ToFile powerproxy.config.json | ||
Exports the PowerProxy config from Key Vault 'abdefpowerproxyaoai' to JSON file 'powerproxy.config.json'. | ||
.LINK | ||
GitHub repo: https://github.com/timoklimmer/powerproxy-aoai | ||
.NOTES | ||
PowerShell version should be 7+. Also make sure your Azure CLI installation is up-to-date. | ||
#> | ||
param( | ||
[Parameter(mandatory=$true)] | ||
[string] $KeyVaultName, | ||
|
||
[Parameter(mandatory=$true)] | ||
[string] $ToFile | ||
) | ||
|
||
#---------------------------------------[Initialisation]-------------------------------------------- | ||
$ErrorActionPreference = "Stop" | ||
Write-Host "Exporting PowerProxy config from Key Vault '$KeyVaultName' to file '$ToFile'..." | ||
|
||
#--------------------------------------------[Code]------------------------------------------------- | ||
Write-Host "Getting config from Key Vault..." | ||
$config_json_string = ( ` | ||
az keyvault secret show ` | ||
-n config-string ` | ||
--vault-name $KeyVaultName ` | ||
--query value ` | ||
-o tsv ` | ||
) | ||
Write-Host "Saving file..." | ||
$config_json_string | Out-File $ToFile | ||
|
||
#--------------------------------------------[Done]------------------------------------------------- | ||
Write-Host "Done." |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<# | ||
.SYNOPSIS | ||
Imports a PowerProxy's configuration into a given Key Vault. | ||
.DESCRIPTION | ||
Writes a PowerProxy's configuration into the given Key Vault from the given file. | ||
.PARAMETER KeyVaultName | ||
Name of the Key Vault in which the configuration is stored. | ||
.EXAMPLE | ||
PS> .\Import-ConfigToAzure.ps1 -KeyVaultName abdefpowerproxyaoai -FromFile production.config.json | ||
Imports the PowerProxy config from Key Vault 'abdefpowerproxyaoai' from JSON file 'production.config.json'. | ||
.LINK | ||
GitHub repo: https://github.com/timoklimmer/powerproxy-aoai | ||
.NOTES | ||
PowerShell version should be 7+. Also make sure your Azure CLI installation is up-to-date. | ||
#> | ||
param( | ||
[Parameter(mandatory=$true)] | ||
[string] $KeyVaultName, | ||
|
||
[Parameter(mandatory=$true)] | ||
[string] $FromFile, | ||
|
||
[Parameter(mandatory=$true)] | ||
[string] $ResourceGroup | ||
) | ||
|
||
#---------------------------------------[Initialisation]-------------------------------------------- | ||
$ErrorActionPreference = "Stop" | ||
Write-Host "Importing PowerProxy config into Key Vault '$KeyVaultName' from file '$FromFile'..." | ||
$CONTAINER_APP_NAME = "powerproxyaoai" | ||
|
||
#--------------------------------------------[Code]------------------------------------------------- | ||
Write-Host "Updating config in Key Vault..." | ||
az keyvault secret set ` | ||
--name config-string ` | ||
--vault-name $KeyVaultName ` | ||
--file $FromFile ` | ||
--output none | ||
|
||
Write-Host "Creating new revision in Container App (required for the new config to come into effect)..." | ||
$random_revision_suffix = (` | ||
-join ((48..57) + (97..122) | Get-Random -Count 7 | ForEach-Object {[char]$_}) ` | ||
) | ||
az containerapp revision copy ` | ||
-n $CONTAINER_APP_NAME ` | ||
-g $ResourceGroup ` | ||
--revision-suffix $random_revision_suffix | ||
|
||
#--------------------------------------------[Done]------------------------------------------------- | ||
Write-Host "Done." |