-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.sh
105 lines (57 loc) · 7.65 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
UCP=x.x.x.x
USER=admin
PASS=pass
# Run this on your UCP controller to set up LDAP backend
docker run --name orcabank-ldap --constraint "node.role=manager" -p 389:389 -p 636:636 --detach -v /docker-access-control:/ldap osixia/openldap:1.1.9
docker service create --name orcabank-ldap --constraint "node.role==manager" -p 389:389 -p 636:636 --detach --mount "type=bind,source=/docker-access-control,target=/ldap" osixia/openldap:1.1.9
# Check users in LDAP
docker exec openldap ldapsearch -x -h localhost -b dc=example,dc=org -D "cn=adminorca,dc=example,dc=org" -w docker123
docker exec orcabank-ldap ldapsearch -x -h localhost -b dc=orcabank,dc=com -D "cn=admin,dc=example,dc=org" -w admin
# LDAP Admin Console
docker run -p 6443:443 \
--env PHPLDAPADMIN_LDAP_HOSTS=ldap://localhost \
--detach osixia/phpldapadmin:0.7.0
# Add users to LDAP
docker exec orcabank-ldap ldapadd -x -D "cn=admin,dc=example,dc=org" -w admin -f /ldap/orcabank.ldif -h localhost -ZZc
# Create /Shared/mobile and /Shared/payments collections
token=$(curl -sk -d "{\"username\":\"$USER\",\"password\":\"$PASS\"}" https://${UCP}/auth/login | jq -r .auth_token) > /dev/null 2>&1
shared_mobile_id=$(curl -skX POST "https://${UCP}/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"mobile\",\"path\":\"/\",\"parent_id\": \"shared\"}" | jq -r .id)
shared_payments_id=$(curl -skX POST "https://${UCP}/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"payments\",\"path\":\"/\",\"parent_id\": \"shared\"}" | jq -r .id)
#write id to a tmp file
echo $shared_payments_id > col_tmp.txt
echo $shared_mobile_id >> col_tmp.txt
function basic-demo-setup() {
echo -n "Creating Orgs and Teams"
token=$(curl -sk -d "{\"username\":\"$USER\",\"password\":\"$PASS\"}" https://${UCP}/auth/login | jq -r .auth_token) > /dev/null 2>&1
curl -sk -X POST https://${UCP}/accounts/ -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"orcabank\",\"isOrg\":true}" > /dev/null 2>&1
ops_team_id=$(curl -sk -X POST https://${UCP}/accounts/orcabank/teams -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"ops\",\"description\":\"ops team of awesomeness\"}" | jq -r .id)
mobile_team_id=$(curl -sk -X POST https://${UCP}/accounts/orcabank/teams -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"mobile\",\"description\":\"dev team of awesomeness\"}" | jq -r .id)
payments_team_id=$(curl -sk -X POST https://${UCP}/accounts/orcabank/teams -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"payments\",\"description\":\"dev team of awesomeness\"}" | jq -r .id)
security_team_id=$(curl -sk -X POST https://${UCP}/accounts/orcabank/teams -H "Authorization: Bearer $token" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -d "{\"name\":\"security\",\"description\":\"security team of awesomeness\"}" | jq -r .id)
echo "$GREEN" "[ok]" "$NORMAL"
echo -n "Inputing Users"
token=$(curl -sk -d "{\"username\":\"$USER\",\"password\":\"$PASS\"}" https://${UCP}/auth/login | jq -r .auth_token) > /dev/null 2>&1
curl -skX POST "https://${UCP}/api/accounts" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -H "Authorization: Bearer $token" -d "{\"role\":1,\"username\":\"ashley\",\"password\":\"docker123\",\"first_name\":\"ashley admin\"}"
curl -skX POST "https://${UCP}/api/accounts" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -H "Authorization: Bearer $token" -d "{\"role\":1,\"username\":\"mindi\",\"password\":\"docker123\",\"first_name\":\"mindi mobile developer\"}"
curl -skX POST "https://${UCP}/api/accounts" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -H "Authorization: Bearer $token" -d "{\"role\":1,\"username\":\"peter\",\"password\":\"docker123\",\"first_name\":\"peter payments developer\"}"
curl -skX POST "https://${UCP}/api/accounts" -H 'Accept: application/json, text/plain, */*' -H 'Accept-Language: en-US,en;q=0.5' --compressed -H 'Content-Type: application/json;charset=utf-8' -H "Authorization: Bearer $token" -d "{\"role\":1,\"username\":\"omar\",\"password\":\"docker123\",\"first_name\":\"omar ops engineer\"}"
echo "$GREEN" "[ok]" "$NORMAL"
echo -n "Adding Users to Teams"
token=$(curl -sk -d "{\"username\":\"$USER\",\"password\":\"$PASS\"}" https://${UCP}/auth/login | jq -r .auth_token) > /dev/null 2>&1
curl -skX PUT "https://${UCP}/accounts/orcabank/teams/ops/members/tim-ops" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{}" > /dev/null 2>&1
curl -skX PUT "https://${UCP}/accounts/orcabank/teams/security/members/angela-security" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{}" > /dev/null 2>&1
curl -skX PUT "https://${UCP}/accounts/orcabank/teams/mobile/members/sri-mobile" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{}" > /dev/null 2>&1
curl -skX PUT "https://${UCP}/accounts/orcabank/teams/payments/members/ashley-payments" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{}" > /dev/null 2>&1
echo "$GREEN" "[ok]" "$NORMAL"
#Create /Shared/mobile and /Shared/payments collections
token=$(curl -sk -d "{\"username\":\"$USER\",\"password\":\"$PASS\"}" https://${UCP}/auth/login | jq -r .auth_token) > /dev/null 2>&1
shared_mobile_id=$(curl -skX POST "https://${UCP}/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"mobile\",\"path\":\"/\",\"parent_id\": \"shared\"}" | jq -r .id)
shared_payments_id=$(curl -skX POST "https://${UCP}/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"payments\",\"path\":\"/\",\"parent_id\": \"shared\"}" | jq -r .id)
}
prod_col_id=$(curl -skX POST "https://${UCP}/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"prod\",\"path\":\"/\",\"parent_id\": \"swarm\"}" | jq -r .id)
mobile_id=$(curl -skX POST "https://${UCP}/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"mobile\",\"path\":\"/prod\",\"parent_id\": \"$prod_col_id\"}" | jq -r .id)
payments_id=$(curl -skX POST "https://${UCP}/collections" -H "accept: application/json" -H "Authorization: Bearer $token" -H "content-type: application/json" -d "{\"name\":\"payments\",\"path\":\"/prod\",\"parent_id\": \"$prod_col_id\"}" | jq -r .id)
echo $payments_id >> col_tmp.txt
echo $mobile_id >> col_tmp.txt
echo $prod_col_id >> col_tmp.txt