forked from Azure/BuildYourOwnCopilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
postdeploy.ps1
48 lines (37 loc) · 1.73 KB
/
postdeploy.ps1
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
#! /usr/bin/pwsh
Param(
[parameter(Mandatory=$false)][string]$resourceGroup=$env:AZURE_RESOURCE_GROUP,
[parameter(Mandatory=$false)][string]$apiUrl=$env:SERVICE_CHATAPI_ENDPOINT_URL
)
Push-Location $($MyInvocation.InvocationName | Split-Path)
$blobUri = "https://cosmosdbcosmicworks.blob.core.windows.net/cosmic-works-small/product.json"
$result = Invoke-WebRequest -Uri $blobUri
$products = $result.Content | ConvertFrom-Json
Write-Output "Imported $($products.Length) products"
$blobUri = "https://cosmosdbcosmicworks.blob.core.windows.net/cosmic-works-small/customer.json"
$result = Invoke-WebRequest -Uri $blobUri
# The customers file has a BOM which needs to be ignored
$customers = $result.Content.Substring(1, $result.Content.Length - 1) | ConvertFrom-Json
Write-Output "Imported $($customers.Length) customers"
$OldProgressPreference = $ProgressPreference
$ProgressPreference = "SilentlyContinue"
$currentIndex = 0
foreach($product in $products)
{
Invoke-RestMethod -Uri $apiUrl/products -Method PUT -Body ($product | ConvertTo-Json) -ContentType 'application/json'
$currentIndex += 1
Write-Output "Imported product $currentIndex of $($products.Length)"
}
$currentIndex = 0
foreach($customer in $customers)
{
if ($customer.type -eq "customer") {
Invoke-RestMethod -Uri $apiUrl/customers -Method PUT -Body ($customer | ConvertTo-Json) -ContentType 'application/json'
} elseif ($customer.type -eq "salesOrder") {
Invoke-RestMethod -Uri $apiUrl/salesorders -Method PUT -Body ($customer | ConvertTo-Json) -ContentType 'application/json'
}
$currentIndex += 1
Write-Output "Imported customer/sales order $currentIndex of $($customers.Length)"
}
$ProgressPreference = $OldProgressPreference
Pop-Location