-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathUpdate-HostnameInTerminals.ps1
More file actions
75 lines (60 loc) · 2.24 KB
/
Update-HostnameInTerminals.ps1
File metadata and controls
75 lines (60 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<#
.SYNOPSIS
The script updates terminal hostname in the database to prepare it for integration testing.
Called during CI process for non-Dev/Master builds.
#>
param(
[Parameter(Mandatory = $true)]
[string]$connectionString,
[Parameter(Mandatory = $false)]
[string]$stagingHostname,
[Parameter(Mandatory = $false)]
[ValidateSet("staging", "sta", "production", "prod")]
[string]$slot,
[Parameter(Mandatory = $false)]
[string]$overrideDbName,
[Parameter(Mandatory = $false)]
[string]$csdef = "terminalCloudService\ServiceDefinition.csdef"
)
$ErrorActionPreference = 'Stop'
$rootDir = Split-Path -parent (Split-Path -parent $MyInvocation.MyCommand.Path)
$defFile = $rootDir + "\" + $csdef
if ([System.String]::IsNullOrEmpty($overrideDbName) -ne $true) {
$builder = new-object system.data.SqlClient.SqlConnectionStringBuilder($connectionString)
$builder["Initial Catalog"] = $overrideDbName
$connectionString = $builder.ToString()
}
if(-not (Test-Path $defFile))
{
throw "Cloud Service definition file is not found at $defFile"
}
$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
$command = new-object system.data.sqlclient.sqlcommand
$command.Connection = $connection
$connection.Open()
$command.CommandTimeout = 20 #20 seconds
if ($slot -contains "sta")
{
if([string]::IsNullOrEmpty($stagingHostname))
{
throw "Specify -stagingHostname for Staging configuration"
}
$xml = [xml](Get-Content $defFile)
$roleNode = $xml.ServiceDefinition.WebRole | where {$_.name -eq 'terminalWebRole'}
$terminalEndpointSettings = $roleNode.Endpoints.InputEndpoint | where {($_.name -like 'terminal*') -and ($_.protocol -like 'http')}
$terminalEndpointSettings | ForEach-Object {
$terminalPort = $_.port
$terminalName = $_.name
$command.CommandText = "UPDATE Terminals SET Endpoint = '$stagingHostname" + ":$terminalPort' WHERE Name = '$terminalName'"
Write-Host "Executing: " + $command.CommandText
$command.ExecuteNonQuery()
}
}
if ($slot -contains "prod")
{
$command.CommandText = "UPDATE Terminals SET Endpoint = 'https://' + LOWER(Name) + '.fr8.co'"
Write-Host "Executing: " + $command.CommandText
$command.ExecuteNonQuery()
}
Write-Host "Successfully updated terminal hostname."
$connection.Close()