-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·85 lines (78 loc) · 3.1 KB
/
setup.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
#! /bin/bash
if [ $1 = "--secrets-from-file" ]; then
PROJECT_ID=$(jq -r '.projectId' secrets.json)
ENVIRONMENT_ID=$(jq -r '.environmentId' secrets.json)
API_KEY=$(jq -r '.apiKey' secrets.json)
CLIENT_ID=$(jq -r '.clientId' secrets.json)
CLIENT_SECRET=$(jq -r '.clientSecret' secrets.json)
else
read -p "Project ID: " PROJECT_ID
read -p "Environment ID: " ENVIRONMENT_ID
read -p "API Key: " API_KEY
read -p "Client ID: " CLIENT_ID
read -p "Client Secret: " CLIENT_SECRET
fi
ACCESS_TOKEN=$(curl --no-progress-meter -f --location "https://auth.spaceblocks.cloud/token-manager/token" \
--request POST \
--header "Content-Type: application/json" \
--header "apiKey: $API_KEY" \
--data "{
\"client_id\": \"$CLIENT_ID\",
\"client_secret\": \"$CLIENT_SECRET\",
\"scope\": \"permissions:management:read permissions:management:write core:permissions:config:read core:permissions:config:write\"
}" | jq -r .access_token)
# Create resource type
curl --no-progress-meter -i --location "https://api.spaceblocks.cloud/public/projects/$PROJECT_ID/environments/$ENVIRONMENT_ID/permissions/config/resource-types" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"name": "City",
"id": "city",
"parentId": "tenant"
}'
# Create permissions
curl --no-progress-meter -i --location "https://api.spaceblocks.cloud/public/projects/$PROJECT_ID/environments/$ENVIRONMENT_ID/permissions/config/resource-types/city/permissions" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"name": "Get current forecast",
"id": "get-current-forecast"
}'
curl --no-progress-meter -i --location "https://api.spaceblocks.cloud/public/projects/$PROJECT_ID/environments/$ENVIRONMENT_ID/permissions/config/resource-types/city/permissions" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"name": "Get future forecast",
"id": "get-future-forecast"
}'
# Create roles
curl --no-progress-meter -i --location "https://api.spaceblocks.cloud/public/projects/$PROJECT_ID/environments/$ENVIRONMENT_ID/permissions/config/static-roles" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"name": "Current Forecast Viewer",
"id": "current-forecast-viewer",
"permissions": {
"city": [ "get-current-forecast" ]
}
}'
curl --no-progress-meter -i --location "https://api.spaceblocks.cloud/public/projects/$PROJECT_ID/environments/$ENVIRONMENT_ID/permissions/config/static-roles" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"name": "Future Forecast Viewer",
"id": "future-forecast-viewer",
"permissions": {
"city": [ "get-future-forecast" ]
}
}'