-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reduce keyvault lookups increase performance
- Loading branch information
1 parent
f22f43e
commit fc7133f
Showing
7 changed files
with
72 additions
and
46 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
Modules/CippExtensions/Public/Extension Functions/Get-ExtensionAPIKey.ps1
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,30 @@ | ||
function Get-ExtensionAPIKey { | ||
<# | ||
.FUNCTIONALITY | ||
Internal | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$Extension, | ||
[switch]$Force | ||
) | ||
|
||
$Var = "Ext_$Extension" | ||
$APIKey = Get-Item -Path "ENV:$Var" -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Value | ||
if ($APIKey) { | ||
Write-Information "Using cached API Key for $Extension" | ||
} else { | ||
Write-Information "Retrieving API Key for $Extension" | ||
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') { | ||
$DevSecretsTable = Get-CIPPTable -tablename 'DevSecrets' | ||
$APIKey = (Get-CIPPAzDataTableEntity @DevSecretsTable -Filter "PartitionKey eq '$Extension' and RowKey eq '$Extension'").APIKey | ||
} else { | ||
$keyvaultname = ($ENV:WEBSITE_DEPLOYMENT_ID -split '-')[0] | ||
$null = Connect-AzAccount -Identity | ||
$APIKey = (Get-AzKeyVaultSecret -VaultName $keyvaultname -Name $Extension -AsPlainText) | ||
} | ||
Set-Item -Path "ENV:$Var" -Value $APIKey -Force -ErrorAction SilentlyContinue | ||
} | ||
return $APIKey | ||
} |
33 changes: 33 additions & 0 deletions
33
Modules/CippExtensions/Public/Extension Functions/Set-ExtensionAPIKey.ps1
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,33 @@ | ||
function Set-ExtensionAPIKey { | ||
<# | ||
.FUNCTIONALITY | ||
Internal | ||
#> | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidUsingConvertToSecureStringWithPlainText', '', Scope = 'Function')] | ||
[CmdletBinding(SupportsShouldProcess = $true)] | ||
param( | ||
[Parameter(Mandatory = $true)] | ||
[string]$Extension, | ||
[Parameter(Mandatory = $true)] | ||
[string]$APIKey | ||
) | ||
|
||
if ($PSCmdlet.ShouldProcess('API Key', "Set API Key for $Extension")) { | ||
$Var = "Ext_$Extension" | ||
if ($env:AzureWebJobsStorage -eq 'UseDevelopmentStorage=true') { | ||
$DevSecretsTable = Get-CIPPTable -tablename 'DevSecrets' | ||
$Secret = [PSCustomObject]@{ | ||
'PartitionKey' = $Extension | ||
'RowKey' = $Extension | ||
'APIKey' = $APIKey | ||
} | ||
Add-CIPPAzDataTableEntity @DevSecretsTable -Entity $Secret -Force | ||
} else { | ||
$keyvaultname = ($ENV:WEBSITE_DEPLOYMENT_ID -split '-')[0] | ||
$null = Connect-AzAccount -Identity | ||
$null = Set-AzKeyVaultSecret -VaultName $keyvaultname -Name $Extension -SecretValue (ConvertTo-SecureString -AsPlainText -Force -String $APIKey) | ||
} | ||
Set-Item -Path "ENV:$Var" -Value $APIKey -Force -ErrorAction SilentlyContinue | ||
} | ||
return $true | ||
} |
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
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
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
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
9 changes: 1 addition & 8 deletions
9
Modules/CippExtensions/Public/Sherweb/Get-SherwebAuthentication.ps1
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