-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSet-Endpoints.ps1
More file actions
88 lines (74 loc) · 2.6 KB
/
Set-Endpoints.ps1
File metadata and controls
88 lines (74 loc) · 2.6 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
76
77
78
79
80
81
82
83
84
85
86
87
88
<#
.SYNOPSIS
The script updates terminal hostnames in the database to prepare it for integration testing.
Only Fr8 own terminals are affected. They should have port-based URLs (e.g. localhost:12345)
and have IsFr8OwnTerminal set to 1.
Called during CI processes for Dev/Master builds.
#>
param(
[Parameter(Mandatory = $true)]
[string]$connectionString,
[Parameter(Mandatory = $true)]
[ValidateSet("sta", "dev", "prod", "staging","development", "production")]
[string]$environment,
[Parameter(Mandatory = $false)]
[string]$newHostname,
[Parameter(Mandatory = $false)]
[string]$overrideDbName,
[Parameter(Mandatory = $false)]
[string]$serviceName
)
if (-Not $newHostname.StartsWith("http://"))
{
$newHostname = "http://{newHostName}"
}
$ErrorActionPreference = 'Stop'
$commandTextTmpl = "
UPDATE Terminals SET [Endpoint] =
('{newHostname}' + RIGHT ([DevUrl], CHARINDEX (':', REVERSE ([DevUrl]))))
WHERE CHARINDEX (':', REVERSE ([DevUrl])) <= 6 AND IsFr8OwnTerminal = 1"
switch ($environment) {
dev {}
development {
if ($newHostname -eq $null) {
throw "-newHostname is not specified. This argument is required for the development environment."
}
$commandText = $commandTextTmpl -replace '{newHostname}', $newHostname
break;
}
sta {}
staging {
if ($serviceName -eq $null) {
throw "-serviceName is not specified. This argument is required for the staging environment."
}
$deployment = Get-AzureDeployment -ServiceName $serviceName -Slot Staging
if ($newHostname -ne $null) {
Write-Warning "-newHostname parameter is ignored when -environment is set to 'staging'"
}
$newHostname = $deployment.Url.Host
Write-Host "Staging hostname is $newHostname"
$commandText = $commandTextTmpl -replace '{newHostname}', $newHostname
break;
}
prod {}
production {
if ($newHostname -ne $null) {
Write-Warning "-newHostname parameter is ignored when -environment is set to 'production'"
}
$commandText = "
UPDATE Terminals SET [Endpoint] = [ProdUrl] WHERE ProdUrl IS NOT NULL AND ParticipationState=1"
break;
}
}
Write-Host "Updating terminal URLs to $newHostname"
Write-Host $commandText
if ([System.String]::IsNullOrEmpty($overrideDbName) -ne $true) {
$builder = new-object system.data.SqlClient.SqlConnectionStringBuilder($connectionString)
$builder["Initial Catalog"] = $overrideDbName
$connectionString = $builder.ToString()
}
$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
$command = new-object system.data.sqlclient.sqlcommand($commandText, $connection)
$connection.Open()
$command.CommandTimeout = 20 #20 seconds
$command.ExecuteNonQuery()