-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-user-and-token
executable file
·50 lines (43 loc) · 1.05 KB
/
create-user-and-token
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
#! /usr/bin/env bash
# Usage: ./create_user.sh <username> [--api-url <api-url>] [--org <salad-org>] [--project <salad-project>]
api_url="http://localhost:8787"
org_name="salad-benchmarking"
project_name="kelpie"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--api-url)
api_url="$2"
shift
shift
;;
--org)
org_name="$2"
shift
shift
;;
--project)
project_name="$2"
shift
shift
;;
*)
username="$1"
shift
;;
esac
done
# Create user
resp=$(curl -X POST $api_url/users \
-H "X-Kelpie-Key: $KELPIE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"username\": \"$username\"}")
user_id=$(echo $resp | jq -r '.id')
resp=$(curl -X POST $api_url/users/$user_id/token \
-H "X-Kelpie-Key: $KELPIE_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"org_name\": \"$org_name\", \"project_name\": \"$project_name\"}")
echo $resp
echo "User ID: $user_id"
echo "Token: "
echo $resp | jq -r '.token'