-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathazureconfig.sh
executable file
·198 lines (148 loc) · 8.06 KB
/
azureconfig.sh
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
clear
echo "***********************************************************"
echo "******Welcome to Cognitive Locator Configuration Tool******"
echo "***********************************************************"
ConfigureAzureSubscription ()
{
# authenticate to azure suscription
az login
echo "Verify your default subscription where you created the Cognitive Locator resources:"
az account list
read -p "Paste the id of the subscription where you created the Cognitive Locator resources: " subscriptionId
az account set --subscription $subscriptionId
echo "The subscription you have selected is: "
az account show
read -p "In this subscription your previously created the Cognitive Locator resources, is that correct? (yes/no)" answer
# all to lower case
answer=$(echo $answer | awk '{print tolower($0)}')
# check and act on given answer
case $answer in
"yes") ProceedConfiguration ;;
*) echo "Please answer yes or no" ; ConfigureAzureSubscription ;;
esac
}
ProceedConfiguration ()
{
read -p "Introduce the name of your Cognitive Locator Resource Group: " resourceGroupName
az group show --name $resourceGroupName
ConfigureDatabase
ConfigureFaceAPI
ConfigureFunctionApp
echo "Great, your backend has been configured successfully!"
#more code here
exit 0
}
ConfigureDatabase ()
{
echo "* Configuring: Database>>"
collectionName="Person"
echo "Collection name: " collectionName
databaseAccountName=$resourceGroupName"-cos"
echo "Account name: " $databaseAccountName
databaseName="CognitiveLocator"
echo "Database name: " $databaseName
# create database
az cosmosdb database create --name $databaseAccountName --db-name $databaseName --resource-group $resourceGroupName
echo "Database created!"
# create person collection in documentDB database
az cosmosdb collection create --collection-name $collectionName --name $databaseAccountName --db-name $databaseName --resource-group $resourceGroupName
echo "Database configured successfully!"
}
ConfigureFaceAPI ()
{
echo "* Configuring: Face API>>"
echo "1) West US - westus.api.cognitive.microsoft.com"
echo "2) West US 2 - westus2.api.cognitive.microsoft.com"
echo "3) East US - eastus.api.cognitive.microsoft.com"
echo "4) East US 2 - eastus2.api.cognitive.microsoft.com"
echo "5) West Central US - westcentralus.api.cognitive.microsoft.com"
echo "6) South Central US - southcentralus.api.cognitive.microsoft.com"
echo "7) West Europe - westeurope.api.cognitive.microsoft.com"
echo "8) North Europe - northeurope.api.cognitive.microsoft.com"
echo "9) Southeast Asia - southeastasia.api.cognitive.microsoft.com"
echo "10) East Asia - eastasia.api.cognitive.microsoft.com"
echo "11) Australia East - australiaeast.api.cognitive.microsoft.com"
echo "12) Brazil South - brazilsouth.api.cognitive.microsoft.com"
read -p "Select your Face API region: " answer
# all to lower case
answer=$(echo $answer | awk '{print tolower($0)}')
# check and act on given answer
case $answer in
"1") ProceedConfigureFaceAPI "westus" ;;
"2") ProceedConfigureFaceAPI "westus2" ;;
"3") ProceedConfigureFaceAPI "eastus" ;;
"4") ProceedConfigureFaceAPI "eastus2" ;;
"5") ProceedConfigureFaceAPI "westcentralus" ;;
"6") ProceedConfigureFaceAPI "southcentralus" ;;
"7") ProceedConfigureFaceAPI "westeurope" ;;
"8") ProceedConfigureFaceAPI "northeurope" ;;
"9") ProceedConfigureFaceAPI "southeastasia" ;;
"10") ProceedConfigureFaceAPI "eastasia" ;;
"11") ProceedConfigureFaceAPI "australiaeast" ;;
"12") ProceedConfigureFaceAPI "brazilsouth" ;;
*) echo "Please select a valid region" ; ConfigureFaceAPI ;;
esac
}
ProceedConfigureFaceAPI ()
{
faceApiName=$resourceGroupName"-fac"
echo "Face API name: " $faceApiName
# get cognitive services face api key 1
faceApiKeys="$(az cognitiveservices account keys list --resource-group $resourceGroupName --name $faceApiName)"
# echo "Face API keys: " $faceApiKeys
tfaceApiKey1="$(jq '.key1' <<< "$faceApiKeys")"
faceApiKey1=$(echo "$tfaceApiKey1" | sed -e 's/^"//' -e 's/"$//')
echo "Face API key1: " $faceApiKey1
# create person group
curl -v -X PUT "https://$1.api.cognitive.microsoft.com/face/v1.0/persongroups/missingpeople" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $faceApiKey1" --data-ascii "{'name':'Missing People','userData':'Missing people person group'}"
# create face list
curl -v -X PUT "https://$1.api.cognitive.microsoft.com/face/v1.0/facelists/list" -H "Content-Type: application/json" -H "Ocp-Apim-Subscription-Key: $faceApiKey1" --data-ascii "{'name':'Face List','userData':'Face list'}"
# face api region
faceApiRegion=$1
echo "Face API configured successfully!"
}
ConfigureFunctionApp ()
{
echo "* Configuring: Function App>>"
functionAppName=$resourceGroupName"-fun"
echo "Function App name: " $functionAppName
# configure face api key
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings Face_API_Subscription_Key=$faceApiKey1
# configure person group
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings Face_API_PersonGroupId=missingpeople
# configure face list
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings Face_API_FaceList=list
# configure face api region
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings Face_API_Zone=$faceApiRegion
# configure database uri
databaseUri="https://$databaseAccountName.documents.azure.com:443/"
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings CosmosDB_URI=$databaseUri
# configure database key
databaseKeys="$(az cosmosdb list-keys --name $databaseAccountName --resource-group $resourceGroupName)"
tdatabaseKey1="$(jq '.primaryMasterKey' <<< "$databaseKeys")"
databaseKey1=$(echo "$tdatabaseKey1" | sed -e 's/^"//' -e 's/"$//')
echo "Database key1: " $databaseKey1
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings CosmosDB_AuthKey=$databaseKey1
# configure database id
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings CosmosDB_DatabaseId=CognitiveLocator
# configure database person collection
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings CosmosDB_PersonCollection=Person
# configure notification hub access signature
notificationHubName=$resourceGroupName"-hub"
echo "Notification Hub name: " $notificationHubName
# note: notification hub is not supported in CLI, then need to be configured manually
# configure notification hub name
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings NotificationHub_Name=$notificationHubName
# configure crytography key
read -p "Paste your cryptography key: " cryptographyKey
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings Cryptography_Key=$cryptographyKey
# configure app center android
read -p "Paste your App Center Id for Android: " appCenterAndroid
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings MobileCenterID_Android=$appCenterAndroid
# configure app center ios
read -p "Paste your App Center Id for iOS: " appCenteriOS
az functionapp config appsettings set --resource-group $resourceGroupName --name $functionAppName --settings MobileCenterID_iOS=$appCenteriOS
echo "Function App configured successfully!"
}
ConfigureAzureSubscription