From 0f61f25ec17f361bc83b32d1694baa0392184c9d Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Mon, 2 Mar 2020 18:08:02 -0600 Subject: [PATCH] !deploy v2.36.2 with logic fixes ## 2.36.2 - 2020-03-02 * [Issue #263](https://github.com/scrthq/PSGSuite/issues/263) * Cleaned up decryption logic for encrypted config. --- CHANGELOG.md | 6 ++ PSGSuite/PSGSuite.psd1 | 2 +- PSGSuite/Private/EncryptionHelpers.ps1 | 63 ++++++++++++++++++ .../Configuration/Get-PSGSuiteConfig.ps1 | 64 ++----------------- .../Configuration/Set-PSGSuiteConfig.ps1 | 14 ---- .../Configuration/Switch-PSGSuiteConfig.ps1 | 46 +------------ README.md | 5 ++ 7 files changed, 83 insertions(+), 117 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc602afa..63735b85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ * [PSGSuite - ChangeLog](#psgsuite---changelog) + * [2.36.2 - 2020-03-02](#2362---2020-03-02) * [2.36.1 - 2020-03-02](#2361---2020-03-02) * [2.36.0 - 2020-02-28](#2360---2020-02-28) * [2.35.1 - 2019-12-29](#2351---2019-12-29) @@ -108,6 +109,11 @@ # PSGSuite - ChangeLog +## 2.36.2 - 2020-03-02 + +* [Issue #263](https://github.com/scrthq/PSGSuite/issues/263) + * Cleaned up decryption logic for encrypted config. + ## 2.36.1 - 2020-03-02 * [Issue #263](https://github.com/scrthq/PSGSuite/issues/263) diff --git a/PSGSuite/PSGSuite.psd1 b/PSGSuite/PSGSuite.psd1 index ed838118..d97de64b 100644 --- a/PSGSuite/PSGSuite.psd1 +++ b/PSGSuite/PSGSuite.psd1 @@ -12,7 +12,7 @@ RootModule = 'PSGSuite.psm1' # Version number of this module. - ModuleVersion = '2.36.1' + ModuleVersion = '2.36.2' # ID used to uniquely identify this module GUID = '9d751152-e83e-40bb-a6db-4c329092aaec' diff --git a/PSGSuite/Private/EncryptionHelpers.ps1 b/PSGSuite/Private/EncryptionHelpers.ps1 index b939541d..533e225c 100644 --- a/PSGSuite/Private/EncryptionHelpers.ps1 +++ b/PSGSuite/Private/EncryptionHelpers.ps1 @@ -1,3 +1,66 @@ +function Get-GSDecryptedConfig { + [CmdletBinding()] + Param( + [parameter(Position = 0,ValueFromPipeline,Mandatory)] + [object] + $Config, + [parameter(Position = 1,Mandatory)] + [string] + $ConfigName, + [parameter(Position = 2)] + [string] + $ConfigPath + ) + Process { + $Config | Select-Object -Property ` + @{l = 'ConfigName';e = { $ConfigName }}, + @{l = 'P12KeyPath'; e = { Invoke-GSDecrypt $_.P12KeyPath } }, + 'P12Key', + @{l = 'P12KeyPassword'; e = { Invoke-GSDecrypt $_.P12KeyPassword } }, + @{l = 'P12KeyObject'; e = { Invoke-GSDecrypt $_.P12KeyObject } }, + @{l = 'ClientSecretsPath'; e = { Invoke-GSDecrypt $_.ClientSecretsPath } }, + @{l = 'ClientSecrets'; e = { Invoke-GSDecrypt $_.ClientSecrets } }, + @{l = 'AppEmail'; e = { + if ($_.AppEmail) { + Invoke-GSDecrypt $_.AppEmail + } + elseif ($_.ClientSecrets) { + (Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_email + } + } + }, + @{l = 'AdminEmail'; e = { Invoke-GSDecrypt $_.AdminEmail } }, + @{l = 'CustomerID'; e = { Invoke-GSDecrypt $_.CustomerID } }, + @{l = 'Domain'; e = { Invoke-GSDecrypt $_.Domain } }, + @{l = 'Preference'; e = { Invoke-GSDecrypt $_.Preference } }, + @{l = 'ServiceAccountClientID'; e = { + if ($_.ServiceAccountClientID) { + Invoke-GSDecrypt $_.ServiceAccountClientID + } + elseif ($_.ClientSecrets) { + (Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_id + } + } + }, + @{l = 'Chat'; e = { + $dict = @{ + Webhooks = @{ } + Spaces = @{ } + } + foreach ($key in $_.Chat.Webhooks.Keys) { + $dict['Webhooks'][$key] = (Invoke-GSDecrypt $_.Chat.Webhooks[$key]) + } + foreach ($key in $_.Chat.Spaces.Keys) { + $dict['Spaces'][$key] = (Invoke-GSDecrypt $_.Chat.Spaces[$key]) + } + $dict + } + }, + @{l = 'ConfigPath'; e = { + if ($ConfigPath) {(Resolve-Path $ConfigPath).Path} elseif ($_.ConfigPath) {$_.ConfigPath} else {$null} + }} + } +} function Invoke-GSDecrypt { param($String) if ($String -is [System.Security.SecureString]) { diff --git a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 index d69f3c67..60690dbf 100644 --- a/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Get-PSGSuiteConfig.ps1 @@ -77,63 +77,13 @@ function Get-PSGSuiteConfig { } } } - $decryptedConfig = $encConf | Select-Object -Property @{l = 'ConfigName';e = { $choice }}, - @{l = 'P12KeyPath'; e = { Invoke-GSDecrypt $_.P12KeyPath } }, - 'P12Key', - @{l = 'P12KeyPassword'; e = { Invoke-GSDecrypt $_.P12KeyPassword } }, - @{l = 'P12KeyObject'; e = { Invoke-GSDecrypt $_.P12KeyObject } }, - @{l = 'ClientSecretsPath'; e = { Invoke-GSDecrypt $_.ClientSecretsPath } }, - @{l = 'ClientSecrets'; e = { Invoke-GSDecrypt $_.ClientSecrets } }, - @{l = 'AppEmail'; e = { - if ($_.AppEmail) { - Invoke-GSDecrypt $_.AppEmail - } - elseif ($_.ClientSecrets) { - (Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_email - } - } - }, - @{l = 'AdminEmail'; e = { Invoke-GSDecrypt $_.AdminEmail } }, - @{l = 'CustomerID'; e = { Invoke-GSDecrypt $_.CustomerID } }, - @{l = 'Domain'; e = { Invoke-GSDecrypt $_.Domain } }, - @{l = 'Preference'; e = { Invoke-GSDecrypt $_.Preference } }, - @{l = 'ServiceAccountClientID'; e = { - if ($_.ServiceAccountClientID) { - Invoke-GSDecrypt $_.ServiceAccountClientID - } - elseif ($_.ClientSecrets) { - (Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_id - } - } - }, - @{l = 'Chat'; e = { - $dict = @{ - Webhooks = @{ } - Spaces = @{ } - } - foreach ($key in $_.Chat.Webhooks.Keys) { - $dict['Webhooks'][$key] = (Invoke-GSDecrypt $_.Chat.Webhooks[$key]) - } - foreach ($key in $_.Chat.Spaces.Keys) { - $dict['Spaces'][$key] = (Invoke-GSDecrypt $_.Chat.Spaces[$key]) - } - $dict - } - }, - @{ - l = 'ConfigPath' - e = { - if ($_.ConfigPath) { - $_.ConfigPath - } - elseif ($Path) { - (Resolve-Path $Path).Path - } - else { - $null - } - } - } + $decryptParams = @{ + ConfigName = $choice + } + if ($Path) { + $decryptParams['ConfigPath'] = $Path + } + $decryptedConfig = $encConf | Get-GSDecryptedConfig @decryptParams Write-Verbose "Retrieved configuration '$choice'" if (!$NoImport) { $script:PSGSuite = $decryptedConfig diff --git a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 index 2b35a457..aaf37ce4 100644 --- a/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Set-PSGSuiteConfig.ps1 @@ -142,20 +142,6 @@ function Set-PSGSuiteConfig { [switch] $NoImport ) - Begin { - Function Invoke-GSEncrypt { - param($string) - if ($string -is [System.Security.SecureString]) { - $string - } - elseif ($string -is [System.String] -and $String -notlike '') { - ConvertTo-SecureString -String $string -AsPlainText -Force - } - elseif ($string -is [System.Management.Automation.ScriptBlock]) { - $string - } - } - } Process { $script:ConfigScope = $Scope $configHash = Import-SpecificConfiguration -CompanyName 'SCRT HQ' -Name 'PSGSuite' diff --git a/PSGSuite/Public/Configuration/Switch-PSGSuiteConfig.ps1 b/PSGSuite/Public/Configuration/Switch-PSGSuiteConfig.ps1 index b941ab38..81ed8308 100644 --- a/PSGSuite/Public/Configuration/Switch-PSGSuiteConfig.ps1 +++ b/PSGSuite/Public/Configuration/Switch-PSGSuiteConfig.ps1 @@ -74,51 +74,7 @@ } } if ($choice) { - $script:PSGSuite = [PSCustomObject]($fullConf[$choice]) | - Select-Object -Property @{l = 'ConfigName';e = { $choice }}, - @{l = 'P12KeyPath'; e = { Invoke-GSDecrypt $_.P12KeyPath } }, - 'P12Key', - @{l = 'P12KeyPassword'; e = { Invoke-GSDecrypt $_.P12KeyPassword } }, - @{l = 'P12KeyObject'; e = { Invoke-GSDecrypt $_.P12KeyObject } }, - @{l = 'ClientSecretsPath'; e = { Invoke-GSDecrypt $_.ClientSecretsPath } }, - @{l = 'ClientSecrets'; e = { Invoke-GSDecrypt $_.ClientSecrets } }, - @{l = 'AppEmail'; e = { - if ($_.AppEmail) { - Invoke-GSDecrypt $_.AppEmail - } - elseif ($_.ClientSecrets) { - (Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_email - } - } - }, - @{l = 'AdminEmail'; e = { Invoke-GSDecrypt $_.AdminEmail } }, - @{l = 'CustomerID'; e = { Invoke-GSDecrypt $_.CustomerID } }, - @{l = 'Domain'; e = { Invoke-GSDecrypt $_.Domain } }, - @{l = 'Preference'; e = { Invoke-GSDecrypt $_.Preference } }, - @{l = 'ServiceAccountClientID'; e = { - if ($_.ServiceAccountClientID) { - Invoke-GSDecrypt $_.ServiceAccountClientID - } - elseif ($_.ClientSecrets) { - (Invoke-GSDecrypt $_.ClientSecrets | ConvertFrom-Json).client_id - } - } - }, - @{l = 'Chat'; e = { - $dict = @{ - Webhooks = @{ } - Spaces = @{ } - } - foreach ($key in $_.Chat.Webhooks.Keys) { - $dict['Webhooks'][$key] = (Invoke-GSDecrypt $_.Chat.Webhooks[$key]) - } - foreach ($key in $_.Chat.Spaces.Keys) { - $dict['Spaces'][$key] = (Invoke-GSDecrypt $_.Chat.Spaces[$key]) - } - $dict - } - }, - ConfigPath + $script:PSGSuite = [PSCustomObject]($fullConf[$choice]) | Get-GSDecryptedConfig -ConfigName $choice if ($SetToDefault) { if ($defaultConfigName -ne $choice) { Write-Verbose "Setting config name '$choice' for domain '$($script:PSGSuite.Domain)' as default" diff --git a/README.md b/README.md index 69a0f407..757afff2 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,11 @@ All other functions are either intact or have an alias included to support backw [Full CHANGELOG here](https://github.com/scrthq/PSGSuite/blob/master/CHANGELOG.md) +#### 2.36.2 - 2020-03-02 + +* [Issue #263](https://github.com/scrthq/PSGSuite/issues/263) + * Cleaned up decryption logic for encrypted config. + #### 2.36.1 - 2020-03-02 * [Issue #263](https://github.com/scrthq/PSGSuite/issues/263)