114 lines
4.2 KiB
PowerShell
114 lines
4.2 KiB
PowerShell
|
function Set-BeaconFeatureSettings{
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Sets the Beacon/Feature settings in machine config.
|
||
|
|
||
|
.DESCRIPTION
|
||
|
Removes current beacon settings in configuration.appSettings
|
||
|
and adds in the given settings.
|
||
|
|
||
|
.PARAMETER EnvironmentName
|
||
|
String, the environment name with which to set the beacon settings.
|
||
|
|
||
|
.PARAMETER EnvironmentType
|
||
|
String, the environment type with which to set the beacon settings.
|
||
|
|
||
|
.PARAMETER EnvironmentHosting
|
||
|
String, the hosting environment with which to set the beacon settings.
|
||
|
|
||
|
.PARAMETER EnvironmentServer
|
||
|
String, the server environment with which to set the beacon settings.
|
||
|
|
||
|
.PARAMETER use64bit
|
||
|
Boolean, passed to Get-DotNetConfigPath - if set to true, will return the filepath
|
||
|
of the 64 bit machine config file.
|
||
|
|
||
|
.EXAMPLE
|
||
|
|
||
|
Set-BeaconFeatureSettings -EnvironmentName "Lane B" -EnvironmentType Build -EnvironmentHosting Aws -EnvironmentServer Nag
|
||
|
|
||
|
Base usage, will set the beacon settings in configuration.appSettigns of the machineConfig file to
|
||
|
|
||
|
<add key="Environment.Name" value="Lane B" />
|
||
|
<add key="Environment.Type" value="Build" />
|
||
|
<add key="Environment.Hosting" value="Aws" />
|
||
|
<add key="Environment.Server" value="Nag" />
|
||
|
|
||
|
#>
|
||
|
[CmdletBinding()]
|
||
|
param(
|
||
|
[Parameter(Mandatory=$True)]
|
||
|
[Alias("Name", "Lane", "Pod")]
|
||
|
[string]$EnvironmentName,
|
||
|
|
||
|
[Parameter(Mandatory=$True)]
|
||
|
[ValidateSet("Development","TeamQA","QA","Build","Secure","Staging","Production")]
|
||
|
[Alias("Type")]
|
||
|
[string]$EnvironmentType,
|
||
|
|
||
|
[Parameter(Mandatory=$True)]
|
||
|
[ValidateSet("Firehost","OnPremise","Aws","Azure","Other")]
|
||
|
[Alias("Hosting")]
|
||
|
[string]$EnvironmentHosting,
|
||
|
|
||
|
[Parameter(Mandatory=$True)]
|
||
|
[ValidateSet("All","Web","App","Sql","Radium","Nag","Other")]
|
||
|
[Alias("Server")]
|
||
|
[string]$EnvironmentServer,
|
||
|
|
||
|
[Parameter(Mandatory=$False)]
|
||
|
[bool]$use64Bit = $True
|
||
|
)
|
||
|
begin{
|
||
|
$logLead = (Get-LogLeadName);
|
||
|
|
||
|
Write-Verbose "$logLead Getting Maching.Config path, use64Bit set to $use64Bit"
|
||
|
$machineConfigPath = Get-DotNetConfigPath -use64Bit $use64Bit
|
||
|
if(!$machineConfigPath){throw "Machine config path could not be found"}
|
||
|
|
||
|
Write-Verbose "$logLead Reading machine config file located at $machineConfigPath"
|
||
|
$machineConfig = Read-XMLFile $machineConfigPath
|
||
|
if(!$machineConfig){throw "Machine config at $machineConfigPath could not be converted to xml"}
|
||
|
|
||
|
Write-Verbose "$logLead Constructing redis xml string"
|
||
|
$BeaconSettingsXmlString = @"
|
||
|
<beaconSettings>
|
||
|
<add key="Environment.Name" value="$EnvironmentName" />
|
||
|
<add key="Environment.Type" value="$EnvironmentType" />
|
||
|
<add key="Environment.Hosting" value="$EnvironmentHosting" />
|
||
|
<add key="Environment.Server" value="$EnvironmentServer" />
|
||
|
</beaconSettings>
|
||
|
"@
|
||
|
}
|
||
|
process{
|
||
|
Write-Verbose "$logLead Ensuring configuration and appSetting nodes exist"
|
||
|
if(!$machineConfig.configuration){
|
||
|
[void]$machineConfig.AppendChild($machineConfig.CreateNode("element","configuration", $null))
|
||
|
}
|
||
|
if(!$machineConfig.configuration.appSettings){
|
||
|
[void]$machineConfig.SelectSingleNode("configuration").AppendChild($machineConfig.CreateElement("appSettings"))
|
||
|
}
|
||
|
|
||
|
Write-Verbose "$logLead Initializing new beacon settings doc"
|
||
|
$BeaconSettingsXmlDoc = [xml]($BeaconSettingsXmlString)
|
||
|
|
||
|
Write-Verbose "$logLead Removing current beacon settings"
|
||
|
$appSettings = $machineConfig.configuration.SelectSingleNode("appSettings")
|
||
|
if($appSettings.SelectNodes("add").count -gt 0){
|
||
|
$CurrentBeaconSettings = $appSettings.add | Where-Object {$BeaconSettingsXmlDoc.beaconSettings.add.key.Contains($_.key)}
|
||
|
$CurrentBeaconSettings | ForEach-Object {[void]$appSettings.RemoveChild($_)}
|
||
|
}
|
||
|
|
||
|
Write-Verbose "$logLead Setting new beacon settings"
|
||
|
$BeaconNode = $machineConfig.ImportNode($BeaconSettingsXmlDoc.FirstChild, $true)
|
||
|
$BeaconNode.add | ForEach-Object {[void]$appSettings.AppendChild($_)}
|
||
|
|
||
|
Write-Verbose "$logLead Saving machine config to path $machineConfigPath"
|
||
|
$machineConfig.Save($machineConfigPath)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
#region Private Functions
|
||
|
|