-
Notifications
You must be signed in to change notification settings - Fork 0
/
seeding.sh
executable file
·85 lines (78 loc) · 2.56 KB
/
seeding.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
PERMISSIONS_URL=$(jq -r '.permissionsUrl' 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 "Permissions URL: " PERMISSIONS_URL
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\"
}" | jq -r .access_token)
# Create a tenant
curl --no-progress-meter -i --location "$PERMISSIONS_URL/management/tenants" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"id": "default",
"name": "Default"
}'
# Create cities
curl --no-progress-meter -i --location "$PERMISSIONS_URL/management/tenants/default/resources/city" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"id": "cansas",
"parent": {
"id" : "default"
}
}'
curl --no-progress-meter -i --location "$PERMISSIONS_URL/management/tenants/default/resources/city" \
--request POST \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"id": "seattle",
"parent": {
"id" : "default"
}
}'
# Assign roles to Cansas
curl --no-progress-meter -i --location "$PERMISSIONS_URL/management/tenants/default/resources/city/cansas/members" \
--request PATCH \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"subjects": {
"alice": [],
"linda": ["future-forecast-viewer"]
}
}'
# Assign roles to Seattle
curl --no-progress-meter -i --location "$PERMISSIONS_URL/management/tenants/default/resources/city/seattle/members" \
--request PATCH \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $ACCESS_TOKEN" \
--header "apiKey: $API_KEY" \
--data '{
"subjects": {
"alice": ["current-forecast-viewer"],
"linda": ["future-forecast-viewer"]
}
}'