fiftyone.geolocation 4.3.0 → 4.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ci/build-and-test.yml +21 -0
- package/ci/common-ci/.github/labels.yml +80 -0
- package/ci/common-ci/.github/workflows/sync-labels.yml +52 -0
- package/ci/common-ci/CiTips.md +30 -1
- package/ci/common-ci/GitVersion.yml +18 -0
- package/ci/common-ci/README.md +155 -17
- package/ci/common-ci/build-and-test.yml +65 -0
- package/ci/common-ci/check-merge-commit-format.yml +56 -0
- package/ci/common-ci/cloud-release-config.json +51 -0
- package/ci/common-ci/create-tag.yml +41 -0
- package/ci/common-ci/deploy.yml +16 -2
- package/ci/common-ci/dotnet/shared-code-signing-steps.yml +20 -0
- package/ci/common-ci/dotnet/shared-extract-and-publish-packages.yml +29 -0
- package/ci/common-ci/go/shared-go-list-stage.yml +64 -0
- package/ci/common-ci/java/readme.md +22 -0
- package/ci/common-ci/java/shared-package-signing-steps.yml +17 -0
- package/ci/{shared-extract-and-publish-packages.yml → common-ci/node/shared-extract-and-publish-packages.yml} +7 -1
- package/ci/common-ci/php/readme.md +15 -0
- package/ci/common-ci/release-config-schema.json +52 -0
- package/ci/common-ci/release-config-template.json +310 -0
- package/ci/common-ci/release-config.json +89 -0
- package/ci/common-ci/release-process.drawio +165 -0
- package/ci/common-ci/release-process.png +0 -0
- package/ci/common-ci/scripts/azure/checkSlot.ps1 +28 -0
- package/ci/common-ci/scripts/modules/51DAuthorizationModule/51DAuthorizationModule.Tests.ps1 +1 -0
- package/ci/common-ci/scripts/modules/51DAuthorizationModule/51DAuthorizationModule.psm1 +16 -0
- package/ci/common-ci/scripts/modules/51DBuildModule/51DBuildModule.Tests.ps1 +3 -0
- package/ci/common-ci/scripts/modules/51DBuildModule/51DBuildModule.psm1 +200 -0
- package/ci/common-ci/scripts/modules/51DDeployModule/51DDeployModule.psm1 +66 -0
- package/ci/common-ci/scripts/modules/51DDownloadDataFileModule/51DDownloadDataFileModule.psm1 +74 -0
- package/ci/common-ci/scripts/modules/51DEnvironmentModule/51DEnvironmentModule.Tests.ps1 +25 -0
- package/ci/common-ci/scripts/modules/51DEnvironmentModule/51DEnvironmentModule.psm1 +22 -0
- package/ci/common-ci/scripts/modules/51DErrorHandleModule/51DErrorHandleModule.Tests.ps1 +1 -0
- package/ci/common-ci/scripts/modules/51DErrorHandleModule/51DErrorHandleModule.psm1 +41 -0
- package/ci/common-ci/scripts/modules/51DGitModule/51DGitModule.Tests.ps1 +5 -0
- package/ci/common-ci/scripts/modules/51DGitModule/51DGitModule.psm1 +702 -0
- package/ci/common-ci/scripts/modules/51DPackageModule/51DPackageModule.Tests.ps1 +842 -0
- package/ci/common-ci/scripts/modules/51DPackageModule/51DPackageModule.psm1 +926 -0
- package/ci/common-ci/scripts/modules/51DPipelineModule/51DPipelineModule.Tests.ps1 +1 -0
- package/ci/common-ci/scripts/modules/51DPipelineModule/51DPipelineModule.psm1 +87 -0
- package/ci/common-ci/scripts/modules/51DPullRequestModule/51DPullRequestModule.Tests.ps1 +194 -0
- package/ci/common-ci/scripts/modules/51DPullRequestModule/51DPullRequestModule.psm1 +653 -0
- package/ci/common-ci/scripts/modules/51DReleaseModule/51DReleaseModule.Tests.ps1 +277 -0
- package/ci/common-ci/scripts/modules/51DReleaseModule/51DReleaseModule.psm1 +554 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.Tests.ps1 +1141 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.psd1 +0 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/51DReleaseTestEnvModule.psm1 +1465 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ConfigurationVerifier.Tests.ps1 +318 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ConfigurationVerifier.psm1 +344 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ReleaseVerifier.Tests.ps1 +1186 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/ReleaseVerifier.psm1 +900 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/SharedVariables.psm1 +139 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/c-test-env-config.json +268 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/dotnet-deploy-test-env-config.json +700 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/dotnet-test-env-config.json +533 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/go-deploy-test-env-config.json +290 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/go-test-env-config.json +260 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/java-deploy-test-env-config.json +511 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/java-test-env-config.json +388 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/node-deploy-test-env-config.json +419 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/node-test-env-config.json +329 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/php-test-env-config.json +540 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/python-deploy-test-env-config.json +411 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/python-test-env-config.json +321 -0
- package/ci/common-ci/scripts/modules/51DReleaseTestEnvModule/config/test-env-config.json +457 -0
- package/ci/common-ci/scripts/modules/51DRestModule/51DRestModule.psm1 +38 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DApplicationInsightsModule/51DApplicationInsightsModule.psm1 +104 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DChecksModule/51DChecksModule.psm1 +68 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DCloudModule/51DCloudModule.psm1 +155 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DConnectAzureModule/51DConnectAzureModule.psm1 +45 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DSSLBindingsModule/51DSSLBIndingsModule.psm1 +100 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DStagingSlotModule/51DStagingSlotModule.psm1 +50 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DStorageAccountModule/51DStorageAccountModule.psm1 +248 -0
- package/ci/common-ci/scripts/modules/AzurePortalModules/51DTrafficManagerModule/51DTrafficManagerModule.psm1 +58 -0
- package/ci/common-ci/shared-auto-complete-pr-stage.yml +61 -0
- package/ci/common-ci/shared-create-tag-job.yml +19 -30
- package/ci/common-ci/shared-docker-build-steps.yml +34 -0
- package/ci/common-ci/shared-docker-push-steps.yml +32 -0
- package/ci/common-ci/shared-docker-test-http-steps.yml +69 -0
- package/ci/common-ci/shared-git-tag-job.yml +38 -0
- package/ci/common-ci/shared-git-version-job.yml +71 -0
- package/ci/common-ci/shared-publish-github-stage.yml +69 -60
- package/ci/common-ci/shared-submodule-trigger-stage.yml +110 -0
- package/ci/common-ci/shared-variables.yml +3 -0
- package/ci/common-ci/trigger-release-apis.yml +39 -0
- package/ci/create-packages.yml +24 -36
- package/ci/deploy-external.yml +55 -0
- package/ci/{deploy.yml → deploy-internal.yml} +3 -29
- package/ci/shared-build-and-test-platforms.yml +7 -1
- package/ci/shared-build-and-test-stage.yml +9 -2
- package/ci/submodule-trigger.yml +12 -0
- package/examples/examples.test.js +3 -3
- package/geoLocationPipelineBuilder.js +13 -10
- package/package.json +11 -7
- package/setup.js +1 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
<#
|
|
2
|
+
==================== Cloud =====================
|
|
3
|
+
.Description
|
|
4
|
+
This module contains functions specific to the cloud environment configuration
|
|
5
|
+
#>
|
|
6
|
+
|
|
7
|
+
# Create a new blocklist json file and add it to the provided storage account
|
|
8
|
+
function Add-BlocklistFile {
|
|
9
|
+
|
|
10
|
+
param (
|
|
11
|
+
[Parameter(Mandatory=$true)]
|
|
12
|
+
[Object]$storageAccount, # storage account object
|
|
13
|
+
|
|
14
|
+
[string]$shareName = "cloudconfig", # file share name
|
|
15
|
+
[string]$fileName = "blocklist.json" # blocklist filename
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# Storage context
|
|
19
|
+
$ctx = $storageAccount.Context
|
|
20
|
+
|
|
21
|
+
$storageFiles = Get-AzStorageFile `
|
|
22
|
+
-ShareName $shareName `
|
|
23
|
+
-Context $ctx
|
|
24
|
+
|
|
25
|
+
$storageFile = $storageFiles | Where-Object {$_.Name -eq $fileName }
|
|
26
|
+
|
|
27
|
+
# If the blocklist file does not exist then create a new one.
|
|
28
|
+
if(-not $storageFile) {
|
|
29
|
+
Write-Host "Adding blocklist file..."
|
|
30
|
+
|
|
31
|
+
# Create the blocklist json object
|
|
32
|
+
$blocklist = @{
|
|
33
|
+
DataPublishedDateTime = (Get-Date).ToString("yyyy-MM-dd")
|
|
34
|
+
UpdateAvailableTime = (Get-Date).ToString("yyyy-MM-dd")
|
|
35
|
+
BlacklistedKeys = @()
|
|
36
|
+
BlacklistedReferers = @()
|
|
37
|
+
BlacklistedIPs = @()
|
|
38
|
+
BlacklistedLicenseIds = @()
|
|
39
|
+
BlacklistedResourceKeys = @()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
# Convert the object to JSON.
|
|
43
|
+
$content = $blocklist | ConvertTo-Json -depth 32
|
|
44
|
+
|
|
45
|
+
# Create a file with the JSON content on disk.
|
|
46
|
+
$Null = New-Item . -Name $fileName -ItemType "file" -Value $content -Force
|
|
47
|
+
|
|
48
|
+
# Try to get the file share
|
|
49
|
+
$share = $null
|
|
50
|
+
try {
|
|
51
|
+
$share = Get-AzStorageShare `
|
|
52
|
+
-Name $shareName `
|
|
53
|
+
-Context $ctx `
|
|
54
|
+
-ErrorAction SilentlyContinue
|
|
55
|
+
} catch {}
|
|
56
|
+
|
|
57
|
+
# Create the file share if it does not exist.
|
|
58
|
+
if(-not($share)) {
|
|
59
|
+
$share = New-AzStorageShare `
|
|
60
|
+
-Name $shareName `
|
|
61
|
+
-Context $ctx
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
# Add the file to the file share.
|
|
65
|
+
$Null = Set-AzStorageFileContent `
|
|
66
|
+
-ShareName $shareName `
|
|
67
|
+
-Source $fileName `
|
|
68
|
+
-Context $ctx
|
|
69
|
+
|
|
70
|
+
# Cleanup the file on disk.
|
|
71
|
+
$Null = Remove-Item $fileName
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Create the shared access signature URI for accessing the file.
|
|
75
|
+
$StartTime = Get-Date
|
|
76
|
+
$EndTime = $StartTime.AddYears(50)
|
|
77
|
+
|
|
78
|
+
$token = New-AzStorageFileSASToken `
|
|
79
|
+
-ShareName $shareName `
|
|
80
|
+
-Path $fileName `
|
|
81
|
+
-Permission "r" `
|
|
82
|
+
-StartTime $StartTime `
|
|
83
|
+
-ExpiryTime $EndTime `
|
|
84
|
+
-Context $ctx
|
|
85
|
+
|
|
86
|
+
$sas = "$($ctx.FileEndPoint)$($shareName)/$($fileName)$($token)"
|
|
87
|
+
|
|
88
|
+
return $sas
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
# Add a Resource key to the entitlement table of a storage account.
|
|
92
|
+
function Add-ResourceKey {
|
|
93
|
+
param (
|
|
94
|
+
[Parameter(Mandatory=$true)]
|
|
95
|
+
[Object]$storageAccount
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
Write-Host "Setting up test resource key..."
|
|
99
|
+
|
|
100
|
+
# Make sure the AzTable module is installed
|
|
101
|
+
if (-not (Get-Module -ListAvailable -Name AzTable)) {
|
|
102
|
+
Write-Host "Az Table module does not exist, installing..."
|
|
103
|
+
Install-Module AzTable
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
# Construct the resource key table row
|
|
107
|
+
$resource = @{
|
|
108
|
+
partitionKey = "AQS5HKcyxmoxU0-q10g"
|
|
109
|
+
rowKey = "2020-02-05T15:23:17.1100358Z"
|
|
110
|
+
properties = @{
|
|
111
|
+
"AgreedToTerms"=$TRUE
|
|
112
|
+
"Domains"=""
|
|
113
|
+
"Email"="engineering@51degrees.com"
|
|
114
|
+
"ProductKeys"="FBVAAAELPALWBBNCEJAGALSAB2ASUP34ZHMR3475Y9SL92L2P7A5X6HUB8JYQFBC7GDNY9AYFYFS5VTYXTB8BNRCA5KXE"
|
|
115
|
+
"Properties"=""
|
|
116
|
+
"ReceiveMarketingEmails"=$FALSE
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
# Storage Account context
|
|
121
|
+
$ctx = $storageAccount.Context
|
|
122
|
+
|
|
123
|
+
# The name of the storage table
|
|
124
|
+
$name = "entitlement"
|
|
125
|
+
|
|
126
|
+
# Try to get the storage table.
|
|
127
|
+
$t = $null
|
|
128
|
+
try {
|
|
129
|
+
$t = Get-AzStorageTable `
|
|
130
|
+
-Name $name `
|
|
131
|
+
-Context $ctx `
|
|
132
|
+
-ErrorAction SilentlyContinue
|
|
133
|
+
} catch { }
|
|
134
|
+
|
|
135
|
+
# If the storage table sodes not exist then create it.
|
|
136
|
+
if (-not ($t)) {
|
|
137
|
+
$t = New-AzStorageTable -Name $name -Context $ctx
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# Try to get the exisiting Resource Key.
|
|
141
|
+
$table = $t.CloudTable
|
|
142
|
+
$row = Get-AzTableRow -table $table -partitionKey $resource.partitionKey | Format-Table
|
|
143
|
+
|
|
144
|
+
# If it does not exist then create the Resource Key Row in the table.
|
|
145
|
+
if(-not ($row)) {
|
|
146
|
+
Add-AzTableRow `
|
|
147
|
+
-table $table `
|
|
148
|
+
-partitionKey $resource.partitionKey `
|
|
149
|
+
-rowKey $resource.rowKey `
|
|
150
|
+
-property $resource.properties
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
# Log the key to console.
|
|
154
|
+
Write-Host "Resource key for testing: $($resource.partitionKey)"
|
|
155
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<#
|
|
2
|
+
==================== ConnectAzure =====================
|
|
3
|
+
.Description
|
|
4
|
+
This module contains functions to connect to an Azure Account and select an
|
|
5
|
+
Azure subscription.
|
|
6
|
+
#>
|
|
7
|
+
|
|
8
|
+
function Connect-AzSubscription {
|
|
9
|
+
|
|
10
|
+
$subscriptionId=''
|
|
11
|
+
$ctx = $null
|
|
12
|
+
|
|
13
|
+
# Connect to the Azure remote management API. Authentication may be required.
|
|
14
|
+
Read-Host -Prompt ("You will be prompted to log in to your Microsoft work account. " +
|
|
15
|
+
"Please choose an account which has access to create new Azure resources. " +
|
|
16
|
+
"Press enter to continue...")
|
|
17
|
+
Connect-AzAccount
|
|
18
|
+
|
|
19
|
+
$subs = Get-AzSubscription
|
|
20
|
+
|
|
21
|
+
if ($subs.Length -eq 0) {
|
|
22
|
+
Write-Host ("No Azure subscriptions for this account could be found." +
|
|
23
|
+
"Please confirm this account has access to azure and try again.")
|
|
24
|
+
exit 1
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
$subs | Format-Table
|
|
28
|
+
|
|
29
|
+
while ($null -eq $ctx) {
|
|
30
|
+
while ('' -eq $subscriptionId) {
|
|
31
|
+
$subscriptionId = Read-Host -Prompt ("Choose the azure subscription id from "+
|
|
32
|
+
"above and paste on this line, then press enter to continue")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# Set the context to the subscription Id where the cluster will be created
|
|
36
|
+
try {
|
|
37
|
+
$ctx = Select-AzSubscription -SubscriptionId $subscriptionId -ErrorAction Stop
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
Write-Host "Invalid subscription selected."
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
Export-ModuleMember -Function Connect-AzSubscription
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
<#
|
|
2
|
+
==================== SSLBindings =====================
|
|
3
|
+
.Description
|
|
4
|
+
This module contains a function to refresh the custom domains assigned to an
|
|
5
|
+
Azure app service and update the SSL bindings.
|
|
6
|
+
|
|
7
|
+
References:
|
|
8
|
+
https://github.com/uglide/azure-content/blob/master/articles/app-service-web/app-service-web-app-powershell-ssl-binding.md
|
|
9
|
+
https://docs.microsoft.com/en-us/powershell/module/Az.websites/remove-Azwebappsslbinding?view=Azps-6.13.0
|
|
10
|
+
#>
|
|
11
|
+
|
|
12
|
+
# Update hosts and SSL bindings for a web app.
|
|
13
|
+
function Set-SSLBindings {
|
|
14
|
+
|
|
15
|
+
param(
|
|
16
|
+
[Parameter(Mandatory=$true)]
|
|
17
|
+
[Hashtable[]]$Certs,
|
|
18
|
+
|
|
19
|
+
[Parameter(Mandatory=$true)]
|
|
20
|
+
[Hashtable[]]$Hosts,
|
|
21
|
+
|
|
22
|
+
[Parameter(Mandatory=$true)]
|
|
23
|
+
[Object]$Webapp
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
# Remove all the exising SSL bindings.
|
|
27
|
+
foreach ($hostName in $Hosts.Name) {
|
|
28
|
+
Remove-AzWebAppSSLBinding `
|
|
29
|
+
-ResourceGroupName $Webapp.ResourceGroup `
|
|
30
|
+
-WebAppName $Webapp.Name `
|
|
31
|
+
-Name $hostName `
|
|
32
|
+
-Force `
|
|
33
|
+
-DeleteCertificate $false
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
# Replace all the existing host names with the ones in this script.
|
|
37
|
+
Set-AzWebApp `
|
|
38
|
+
-ResourceGroupName $Webapp.ResourceGroup `
|
|
39
|
+
-Name $Webapp.Name `
|
|
40
|
+
-HostNames @($Hosts.Name, $Webapp.DefaultHostName) `
|
|
41
|
+
-Use32BitWorkerProcess $false
|
|
42
|
+
|
|
43
|
+
# # Upload the new SSL certificates if they do not exist and bind them to the
|
|
44
|
+
# # host name. If the SSL certificate does exist then use the existing one.
|
|
45
|
+
foreach($current in $Hosts) {
|
|
46
|
+
|
|
47
|
+
# Use the -like directive to find wildcard certificates that have the
|
|
48
|
+
# *.domain.com format.
|
|
49
|
+
Write-Host "Finding certificates for $($current.Name)"
|
|
50
|
+
$existing = New-Object -TypeName 'System.Collections.ArrayList'
|
|
51
|
+
foreach($cert in (Get-AzWebAppCertificate `
|
|
52
|
+
-ResourceGroupName $Webapp.ResourceGroup) | `
|
|
53
|
+
Where-Object { `
|
|
54
|
+
($_.Location -eq $Webapp.Location) -and `
|
|
55
|
+
($_.ExpirationDate -gt (Get-Date))}) {
|
|
56
|
+
foreach($hostName in $cert.HostNames) {
|
|
57
|
+
if ($current.Name -like $hostName) {
|
|
58
|
+
$existing.Add($cert) | Out-Null
|
|
59
|
+
Write-Host "Found" $cert.Thumbprint
|
|
60
|
+
Break
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (($null -eq $existing) -OR ($existing.Count -eq 0)) {
|
|
66
|
+
|
|
67
|
+
# There are no available certificates. Find the one that is contained
|
|
68
|
+
# in the same folder as this script and add it to the web app.
|
|
69
|
+
$cert = $Certs |
|
|
70
|
+
Where-Object CertificateFile -eq $current.CertificateFile |
|
|
71
|
+
Select-Object -First 1
|
|
72
|
+
if ($null -ne $cert) {
|
|
73
|
+
Write-Host "Adding certificate for $($current.Name)"
|
|
74
|
+
New-AzWebAppSSLBinding `
|
|
75
|
+
-ResourceGroupName $Webapp.ResourceGroup `
|
|
76
|
+
-WebAppName $Webapp.Name `
|
|
77
|
+
-Name $current.Name `
|
|
78
|
+
-CertificateFilePath (Join-Path $pwd $cert.CertificateFile) `
|
|
79
|
+
-CertificatePassword $cert.Password
|
|
80
|
+
} else {
|
|
81
|
+
Write-Host "No cerificate available for $($current.Name)"
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
|
|
85
|
+
# Order the list so that the certificate that expires the furthest in the
|
|
86
|
+
# future is used form the domain.
|
|
87
|
+
$existing = $existing | Sort-Object ExpirationDate -Descending
|
|
88
|
+
|
|
89
|
+
# Use the thumbprint from the certicate to set bind to the domain.
|
|
90
|
+
Write-Host "Using existing certificate $($existing[0].Thumbprint) for $($current.Name)"
|
|
91
|
+
New-AzWebAppSSLBinding `
|
|
92
|
+
-ResourceGroupName $Webapp.ResourceGroup `
|
|
93
|
+
-WebAppName $Webapp.Name `
|
|
94
|
+
-Name $current.Name `
|
|
95
|
+
-Thumbprint $existing[0].Thumbprint
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
Export-ModuleMember -Function Set-SSLBindings
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<#
|
|
2
|
+
==================== Staging Slots =====================
|
|
3
|
+
.Description
|
|
4
|
+
This module contains a function to refresh or add the staging slot on an
|
|
5
|
+
Azure App Service.
|
|
6
|
+
#>
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
function Add-WebAppStagingSlot {
|
|
10
|
+
|
|
11
|
+
param(
|
|
12
|
+
[Parameter(Mandatory=$true)]
|
|
13
|
+
[Object]$Webapp,
|
|
14
|
+
|
|
15
|
+
[Hashtable]$AppSettings
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
Write-Host "Adding Staging slot..."
|
|
19
|
+
|
|
20
|
+
# Remove the staging slot ready to rebuild it.
|
|
21
|
+
$null = Remove-AzWebAppSlot `
|
|
22
|
+
-ResourceGroupName $webapp.ResourceGroup `
|
|
23
|
+
-Name $webapp.Name `
|
|
24
|
+
-Slot "Staging" `
|
|
25
|
+
-Force
|
|
26
|
+
|
|
27
|
+
# Adds a new staging slot with fresh configuration.
|
|
28
|
+
$null = New-AzWebAppSlot `
|
|
29
|
+
-ResourceGroupName $webapp.ResourceGroup `
|
|
30
|
+
-Name $webapp.Name `
|
|
31
|
+
-Slot "Staging"
|
|
32
|
+
|
|
33
|
+
if ($null -eq $AppSettings){
|
|
34
|
+
$AppSettings = $webapp.SiteConfig.AppSettings
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
# Config the fresh staging slot. Belt and braces incase the CD script doesn't
|
|
38
|
+
# set the correct parameters.
|
|
39
|
+
$null = Set-AzWebAppSlot `
|
|
40
|
+
-ResourceGroupName $webapp.ResourceGroup `
|
|
41
|
+
-Name $webapp.Name `
|
|
42
|
+
-Slot "Staging" `
|
|
43
|
+
-AppSettings $AppSettings `
|
|
44
|
+
-WebSocketsEnabled $false `
|
|
45
|
+
-Use32BitWorkerProcess $false `
|
|
46
|
+
-AlwaysOn $true `
|
|
47
|
+
-FtpsState "Disabled"
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
Export-ModuleMember -Function Add-WebAppStagingSlot
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
<#
|
|
2
|
+
==================== Stroage Accounts =====================
|
|
3
|
+
.Description
|
|
4
|
+
This module contains a function to create storage accounts.
|
|
5
|
+
References:
|
|
6
|
+
https://docs.microsoft.com/en-us/azure/cosmos-db/scripts/powershell/table/create
|
|
7
|
+
https://docs.microsoft.com/en-us/powershell/module/az.cosmosdb/new-azcosmosdbaccount
|
|
8
|
+
#>
|
|
9
|
+
|
|
10
|
+
# Create a new Storage Account
|
|
11
|
+
function New-StorageAcc {
|
|
12
|
+
param (
|
|
13
|
+
[Parameter(Mandatory = $true)]
|
|
14
|
+
[string]$storageAccName,
|
|
15
|
+
|
|
16
|
+
[Parameter(Mandatory = $true)]
|
|
17
|
+
[string]$resourceGroupName,
|
|
18
|
+
|
|
19
|
+
[Parameter(Mandatory = $true)]
|
|
20
|
+
[string]$region,
|
|
21
|
+
|
|
22
|
+
[Hashtable]$tags = @{}
|
|
23
|
+
)
|
|
24
|
+
Write-Host ""
|
|
25
|
+
|
|
26
|
+
while ($storageAccName.length -lt 3) {
|
|
27
|
+
$choice = Read-Host -Prompt ("Storage account name '$($storageAccName)' " +
|
|
28
|
+
"is too short, enter a new name here")
|
|
29
|
+
if (-not [string]::IsNullOrWhiteSpace($choice)) {
|
|
30
|
+
$storageAccName = $choice.Replace("-", "").ToLower()
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
while ($storageAccName.length -gt 24) {
|
|
35
|
+
$truncated = $storageAccName.Substring(0, 24)
|
|
36
|
+
$choice = Read-Host -Prompt ("Storage account name '$($storageAccName)' " +
|
|
37
|
+
"is too long, use trunctated name or enter a new name here [$($truncated)]")
|
|
38
|
+
if ([string]::IsNullOrWhiteSpace($choice)) {
|
|
39
|
+
$storageAccName = truncated
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
$storageAccName = $choice.Replace("-", "").ToLower()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
$sb = $null
|
|
47
|
+
|
|
48
|
+
while (-not $sb) {
|
|
49
|
+
# Check if storage account exists
|
|
50
|
+
$sb = Get-AzStorageAccount `
|
|
51
|
+
-ResourceGroupName $resourceGroupName `
|
|
52
|
+
-Name $storageAccName `
|
|
53
|
+
-ErrorAction SilentlyContinue
|
|
54
|
+
|
|
55
|
+
if(-not $sb) {
|
|
56
|
+
# create sotrage account
|
|
57
|
+
Write-Host "Creating storage account:" $storageAccName
|
|
58
|
+
|
|
59
|
+
$sb = New-AzStorageAccount `
|
|
60
|
+
-ResourceGroupName $resourceGroupName `
|
|
61
|
+
-Name $storageAccName `
|
|
62
|
+
-Location $region `
|
|
63
|
+
-Tag $tags `
|
|
64
|
+
-SkuName Standard_RAGRS `
|
|
65
|
+
-Kind StorageV2
|
|
66
|
+
|
|
67
|
+
if(-not $sb) {
|
|
68
|
+
# If there is still no storage account then the
|
|
69
|
+
# 'New-AzStorageAccount' command has failed. Retreive the last
|
|
70
|
+
# Azure Error.
|
|
71
|
+
$lastError = Resolve-AzError -Last -WarningAction silentlyContinue
|
|
72
|
+
|
|
73
|
+
# Check that the last error is from the expected source, if not
|
|
74
|
+
# we can't handle it. Prompt the user to check the Errors
|
|
75
|
+
# manually.
|
|
76
|
+
if ($lastError.Exception.Source -ne "Microsoft.Azure.PowerShell.Cmdlets.Storage.Management") {
|
|
77
|
+
Write-Host ("Could not resolve error creating storage " +
|
|
78
|
+
"account. Use the PowerShell Cmdlet 'Resolve-AzError -Last' to " +
|
|
79
|
+
"inspect the last Azure error in this session.")
|
|
80
|
+
exit 1
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
# If the stroage account name has already been taken then
|
|
84
|
+
# prompt the user for a new account name.
|
|
85
|
+
if ($lastError.Message.Contains("The storage account named " +
|
|
86
|
+
"$($storageAccName) is already taken. (Parameter 'Name')")) {
|
|
87
|
+
$storageAccName = Read-Host -Prompt ("Storage account name " +
|
|
88
|
+
"'$($storageAccName)' already taken in a different Azure " +
|
|
89
|
+
"subscription, enter a new name here")
|
|
90
|
+
} elseif ($lastError.Message.Contains("$($storageAccName) is not a " +
|
|
91
|
+
"valid storage account name.")) {
|
|
92
|
+
$storageAccName = Read-Host -Prompt ("'$($storageAccName)' is not a " +
|
|
93
|
+
"valid storage account name, enter a new name here")
|
|
94
|
+
# If the Azure error is not the expected error then abort
|
|
95
|
+
# the process and ask the user to review the Azure errors
|
|
96
|
+
# manually.
|
|
97
|
+
} else {
|
|
98
|
+
Write-Host "Error message: $($lastError.Message)"
|
|
99
|
+
Write-Host ("Could not resolve error creating storage " +
|
|
100
|
+
"account. Use the PowerShell Cmdlet 'Resolve-AzError -Last' to " +
|
|
101
|
+
"inspect the last Azure error in this session.")
|
|
102
|
+
exit 1
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
} else {
|
|
106
|
+
Write-Host -ForegroundColor Magenta ("Storage account '$($storageAccName)' " +
|
|
107
|
+
"already exists, using exsiting account")
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return $sb
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
# Function to create a new Cosmos DB account. First check if one with the same
|
|
115
|
+
# account name exists already, if not the create a new one, otherwise prompt the
|
|
116
|
+
# user for a new name.
|
|
117
|
+
function New-CosmosAccount {
|
|
118
|
+
|
|
119
|
+
param (
|
|
120
|
+
# The name of the Cosmos DB Account
|
|
121
|
+
[Parameter(Mandatory = $true)]
|
|
122
|
+
[string]$accountName,
|
|
123
|
+
|
|
124
|
+
# The name of the resource group where the Cosmos DB account is created
|
|
125
|
+
# or located
|
|
126
|
+
[Parameter(Mandatory = $true)]
|
|
127
|
+
[string]$resourceGroupName,
|
|
128
|
+
|
|
129
|
+
# Tags to create the Cosmos DB account with.
|
|
130
|
+
[hashtable]$tags = @{},
|
|
131
|
+
|
|
132
|
+
# The kind of CosmosDB API to use.
|
|
133
|
+
[string]$apiKind = "Table",
|
|
134
|
+
[string]$consistencyLevel = "BoundedStaleness",
|
|
135
|
+
[int]$maxStalenessIntervalInSeconds = 86400,
|
|
136
|
+
[int]$maxStalenessPrefix = 1000000,
|
|
137
|
+
[Array]$locations = @(
|
|
138
|
+
(New-AzCosmosDBLocationObject -LocationName "West Europe" -FailoverPriority 0 -IsZoneRedundant 0),
|
|
139
|
+
(New-AzCosmosDBLocationObject -LocationName "Central US" -FailoverPriority 1 -IsZoneRedundant 0)
|
|
140
|
+
# TODO consider adding central india as a cosmos db region.
|
|
141
|
+
#(New-AzCosmosDBLocationObject -LocationName "Central India" -FailoverPriority 1 -IsZoneRedundant 0)
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
$cosmosDBAccount = $null
|
|
146
|
+
|
|
147
|
+
while (-not $cosmosDBAccount) {
|
|
148
|
+
# Get an existing Cosmos DB account.
|
|
149
|
+
$cosmosDBAccount = Get-AzCosmosDBAccount `
|
|
150
|
+
-ResourceGroupName $resourceGroupName `
|
|
151
|
+
-Name $accountName `
|
|
152
|
+
-ErrorAction SilentlyContinue
|
|
153
|
+
|
|
154
|
+
if (-not $cosmosDBAccount) {
|
|
155
|
+
# If there is no Cosmos DB account then try to create one.
|
|
156
|
+
Write-Host "Creating Cosmos DB account '$($accountName)'"
|
|
157
|
+
$cosmosDBAccount = New-AzCosmosDBAccount `
|
|
158
|
+
-ResourceGroupName $resourceGroupName `
|
|
159
|
+
-Name $accountName `
|
|
160
|
+
-LocationObject $locations `
|
|
161
|
+
-ApiKind $apiKind `
|
|
162
|
+
-DefaultConsistencyLevel $consistencyLevel `
|
|
163
|
+
-MaxStalenessIntervalInSeconds $maxStalenessIntervalInSeconds `
|
|
164
|
+
-MaxStalenessPrefix $maxStalenessPrefix `
|
|
165
|
+
-Tag $tags
|
|
166
|
+
|
|
167
|
+
if (-not $cosmosDBAccount) {
|
|
168
|
+
# If there is still no Cosmos DB account then the
|
|
169
|
+
# 'New-AzCosmosDBAccount' command has failed. Retreive the last
|
|
170
|
+
# Az Error.
|
|
171
|
+
$lastError = Resolve-AzError -Last -WarningAction silentlyContinue
|
|
172
|
+
|
|
173
|
+
# Check that the last error is from the expected source, if not
|
|
174
|
+
# we can't handle it. Prompt the user to check the Errors
|
|
175
|
+
# manually.
|
|
176
|
+
if ($lastError.Exception.Source -ne "Microsoft.Azure.Management.CosmosDB") {
|
|
177
|
+
Write-Host ("Could not resolve error creating cosmos DB " +
|
|
178
|
+
"account. Use the PowerShell Cmdlet 'Resolve-AzError -Last' to " +
|
|
179
|
+
"inspect the last Azure error in this session.")
|
|
180
|
+
exit 1
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
# The Cosmos DB DNS record is determined by the account name.
|
|
184
|
+
# If the error is caused by the DNS record being taken then
|
|
185
|
+
# prompt the user for a new account name.
|
|
186
|
+
if ($lastError.Message.Contains("Dns record for " +
|
|
187
|
+
"$($accountName) under zone Document is already " +
|
|
188
|
+
"taken. Please use a different name for the account")) {
|
|
189
|
+
$suggestion = $accountName + "-1"
|
|
190
|
+
$choice = Read-Host -Prompt ("Cosmos DB account name " +
|
|
191
|
+
"'$($accountName)' already taken in a different Azure " +
|
|
192
|
+
"Subscription, use suggestion or enter a new name here [$($suggestion)]")
|
|
193
|
+
|
|
194
|
+
if ([string]::IsNullOrWhiteSpace($choice)) {
|
|
195
|
+
$accountName = $suggestion
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
$accountName = $choice
|
|
199
|
+
}
|
|
200
|
+
# If the Cosmos DB error is not the expected error then abort
|
|
201
|
+
# the process and ask the user to review the Azure errors
|
|
202
|
+
# manually.
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
Write-Host "Error message: $($lastError.Message)"
|
|
206
|
+
Write-Host ("Could not resolve error creating cosmos DB " +
|
|
207
|
+
"account. Use the PowerShell Cmdlet 'Resolve-AzError -Last' to " +
|
|
208
|
+
"inspect the last Azure error in this session.")
|
|
209
|
+
exit 1
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
} else {
|
|
213
|
+
Write-Host -ForegroundColor Magenta ("Cosmos DB account '$($accountName)' " +
|
|
214
|
+
"exists, using existing account.")
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return $cosmosDBAccount
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function New-CosmosDbTable {
|
|
222
|
+
|
|
223
|
+
param (
|
|
224
|
+
[Parameter(Mandatory=$true)]
|
|
225
|
+
[object]$cosmosAccount,
|
|
226
|
+
|
|
227
|
+
[Parameter(Mandatory=$true)]
|
|
228
|
+
[string]$tableName,
|
|
229
|
+
|
|
230
|
+
[Parameter(Mandatory=$true)]
|
|
231
|
+
[int]$tableRUs
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
$table = Get-AzCosmosDBTable `
|
|
235
|
+
-Name $tableName `
|
|
236
|
+
-ParentObject $cosmosAccount `
|
|
237
|
+
-ErrorAction SilentlyContinue
|
|
238
|
+
|
|
239
|
+
if(-not $table) {
|
|
240
|
+
Write-Host "Creating Cosmos DB table: $($tableName)"
|
|
241
|
+
New-AzCosmosDBTable `
|
|
242
|
+
-ParentObject $cosmosAccount `
|
|
243
|
+
-Name $tableName `
|
|
244
|
+
-Throughput $tableRUs
|
|
245
|
+
} else {
|
|
246
|
+
Write-Host "Cosmos DB table '$($tableName)' already exists."
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<#
|
|
2
|
+
==================== TrafficManager =====================
|
|
3
|
+
.Description
|
|
4
|
+
This module contains functions for managing the Azure Traffic Manager profiles
|
|
5
|
+
#>
|
|
6
|
+
|
|
7
|
+
# function to add or udpate a traffic manager endpoint with a type of
|
|
8
|
+
# AzureEndpoint
|
|
9
|
+
function Update-TrafficManagerAzureEndpoint {
|
|
10
|
+
|
|
11
|
+
param(
|
|
12
|
+
[Parameter(Mandatory=$true)]
|
|
13
|
+
[Object]$webapp,
|
|
14
|
+
|
|
15
|
+
[Parameter(Mandatory=$true)]
|
|
16
|
+
[string]$trafficManagerProfile,
|
|
17
|
+
|
|
18
|
+
[Parameter(Mandatory=$true)]
|
|
19
|
+
[string]$trafficManagerResourceGroup
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
$EndpointType = "AzureEndpoints"
|
|
23
|
+
|
|
24
|
+
# Get exisiting traffic manager endpoint.
|
|
25
|
+
$trafficManagerEndpoint = $null
|
|
26
|
+
try {
|
|
27
|
+
$trafficManagerEndpoint = Get-AzTrafficManagerEndpoint `
|
|
28
|
+
-Name $webapp.Name `
|
|
29
|
+
-ProfileName $trafficManagerProfile `
|
|
30
|
+
-ResourceGroupName $trafficManagerResourceGroup `
|
|
31
|
+
-Type $EndpointType `
|
|
32
|
+
-ErrorAction SilentlyContinue
|
|
33
|
+
} catch {}
|
|
34
|
+
|
|
35
|
+
# Check if traffic manager endpoint already exists.
|
|
36
|
+
if ($trafficManagerEndpoint) {
|
|
37
|
+
# If traffic manager endpoint exists then update the existing endpoint
|
|
38
|
+
# target, leave other settings the same.
|
|
39
|
+
Write-Host "Updating endpoint in traffic manager"
|
|
40
|
+
$trafficManagerEndpoint.TargetResourceId = $webapp.Id
|
|
41
|
+
|
|
42
|
+
Set-AzTrafficManagerEndpoint -TrafficManagerEndpoint $trafficManagerEndpoint
|
|
43
|
+
} else {
|
|
44
|
+
# If traffic manager endpoint does not exist then add App Service to
|
|
45
|
+
# traffic manager (as a disabled endpoint).
|
|
46
|
+
Write-Host ("Adding endpoint to traffic manager, endpoint will be added as " +
|
|
47
|
+
"disabled. The endpoint should only be enabled when the cloud "+
|
|
48
|
+
"application has been tested on the new App Service")
|
|
49
|
+
|
|
50
|
+
New-AzTrafficManagerEndpoint `
|
|
51
|
+
-Name $webapp.Name `
|
|
52
|
+
-ProfileName $trafficManagerProfile `
|
|
53
|
+
-ResourceGroupName $trafficManagerResourceGroup `
|
|
54
|
+
-Type $EndpointType `
|
|
55
|
+
-TargetResourceId $webapp.Id `
|
|
56
|
+
-EndpointStatus Disabled
|
|
57
|
+
}
|
|
58
|
+
}
|