ps/Modules/Alkami.DevOps.Installation/Public/Get-NewRelicAccountDetails.ps1

65 lines
4.0 KiB
PowerShell
Raw Normal View History

2023-05-30 22:51:22 -07:00
function Get-NewRelicAccountDetails {
<#
.SYNOPSIS
Returns the appropriate New Relic account (not Admin) API key and license key based on environment string
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[Alias("Environment")]
[string]$environmentKey
)
$logLead = (Get-LogLeadName);
$specificAccountDetails = @(
# FI specific accounts.
@{EnvironmentRegex = "(AWS Production( Entrust)? 5)|(AWS Staging Lane FT\w+)"; APIKey = "5362c58099d6a19871a07f66b1ec50e2c00f66b4b69260e"; LicenseKey = "4e8134a277da93644407dc53931f81d99b69260e"; },
@{EnvironmentRegex = "AWS Production( Entrust)? 9"; APIKey = "b84b09aabf2ebe0773009698205220e9d53063bf84d041f"; LicenseKey = "417a21abe2bd84ca46940efc9c93cf75584d041f"; },
@{EnvironmentRegex = "(AWS Production( Entrust)? 10)|(AWS Staging Lane OTSStg)"; APIKey = "3d0346ec856cc9b02b3b0fcc481afc989a4f9941b28a80d"; LicenseKey = "d2eb268d151e57550de821438c3d99131b28a80d"; },
@{EnvironmentRegex = "(AWS Production( Entrust)? 15)|(AWS Staging Lane MACUStg)"; APIKey = "fcb208ec98958282362c4e7879bfa38e4073c10c073cc2f"; LicenseKey = "77b3cae28080be6a5ebcb7d2f3efdde8d073cc2f"; },
# Internal special-purpose accounts.
@{EnvironmentRegex = "^AWS Production 0$"; APIKey = "d34b1647dee7875568ebc4b7c97c37216c4c342b37bcce1"; LicenseKey = "b17e86388ca5c4a2c4777cd1b0e1e12a837bcce1"; }
)
$defaultAccountDetails = @(
# Legacy QA and Dev account.
@{EnvironmentRegex = "((?<!AWS )\bQ(A|W)\d*\b)|^AWS (DEV|CICD)"; APIKey = "0cdfe5a47b10db89acf3560e47d4657fbfec081040e50b8"; LicenseKey = "f88cf2f1ed5fca2600f6a49e63778274c40e50b8"; },
# AWS QA account.
@{EnvironmentRegex = "^AWS QA"; APIKey = "955b8bfccbdde190f855238dc55f17ba5d6382ee2492392"; LicenseKey = "e941422aebc76c48d195bcdcf86e4f7602492392"; },
# Default Load Test account.
@{EnvironmentRegex = "LT vPod"; APIKey = "b9a9731deca97828205662ffc9a4cc400d74abc94685b0c"; LicenseKey = "4c5f1d447e2fab98cc9c30ff5dc864d614685b0c"; },
# Default Sandbox environment account.
@{EnvironmentRegex = "Sandbox"; APIKey = "0cdfe5a47b10db89acf3560e47d4657fbfec081040e50b8"; LicenseKey = "f88cf2f1ed5fca2600f6a49e63778274c40e50b8"; },
# Default DR account.
@{EnvironmentRegex = "^AWS DR Production"; APIKey = "6a9e9820d3aaf12278c80d0bc1433b90aee1ea5769ac25f"; LicenseKey = "b55c8c163b1ede6fef75f6f586a1dbb6869ac25f"; },
# Default production account.
@{EnvironmentRegex = "^AWS Production"; APIKey = "NRRA-8fbdf2188c09dd34aef478e13e31668e405324a304"; LicenseKey = "e0318c558f353e420720d4417ebe4cbd43b7d425"; },
# Default staging account.
@{EnvironmentRegex = "^AWS Staging"; APIKey = "a156af42c6da91536e67f2414bc1c25f3742e41b0cb93ab"; LicenseKey = "3707290484dceca2dc2ecd71e40fb0ff40cb93ab"; }
)
[array]$accountInfo = $specificAccountDetails | Where-Object {$environmentKey -match $_.EnvironmentRegex}
# If the unique lookup failed, attempt to use a default.
if ( Test-IsCollectionNullOrEmpty $accountInfo ) {
Write-Verbose ( "$logLead : No specific account found for '{0}'; looking for default." -f $environmentKey )
[array]$accountInfo = $defaultAccountDetails | Where-Object {$environmentKey -match $_.EnvironmentRegex}
}
if (Test-IsCollectionNullOrEmpty $accountInfo) {
throw ("$logLead : Unable to find New Relic account info which matches environment key '{0}'." -f $environmentKey)
} elseif ($accountInfo.Count -gt 1) {
throw ("$logLead : Found more than one New Relic account info which matches environment key '{0}'." -f $environmentKey)
}
Write-Verbose ("$logLead : Returning entry with EnvironmentRegex '{0}'." -f $accountInfo.EnvironmentRegex)
return ($accountInfo | Select-Object -First 1)
}