Skip to content

Commit

Permalink
Added export/import config from/to Azure
Browse files Browse the repository at this point in the history
  • Loading branch information
timoklimmer committed Nov 28, 2023
1 parent 7bde9dd commit ec16a6e
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Export-ConfigFromAzure.ps1
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."
56 changes: 56 additions & 0 deletions Import-ConfigToAzure.ps1
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."

0 comments on commit ec16a6e

Please sign in to comment.