c2f32e50f139c6d4f5ada15eca5a7740ad56ac5e
[akkoma] / scripts / create_metrics_app.sh
1 #!/bin/sh
2
3 read -p "Instance URL (e.g https://example.com): " INSTANCE_URL
4
5 echo "Creating oauth app..."
6
7 RESP=$(curl \
8 -XPOST \
9 $INSTANCE_URL/api/v1/apps \
10 --silent \
11 --data-urlencode 'client_name=fedibash' \
12 --data-urlencode 'redirect_uris=urn:ietf:wg:oauth:2.0:oob' \
13 --data-urlencode 'scopes=admin:metrics' \
14 --header "Content-Type: application/x-www-form-urlencoded"
15 )
16
17 client_id=$(echo $RESP | jq -r .client_id)
18 client_secret=$(echo $RESP | jq -r .client_secret)
19
20 if [ -z "$client_id"]; then
21 echo "Could not create an app"
22 echo "$RESP"
23 exit 1
24 fi
25
26 echo "Please visit the following URL and input the code provided"
27 AUTH_URL="$INSTANCE_URL/oauth/authorize?client_id=$client_id&redirect_uri=urn:ietf:wg:oauth:2.0:oob&scope=admin:metrics&response_type=code"
28 if [ ! -z "$BROWSER" ]; then
29 $BROWSER $AUTH_URL
30 fi;
31
32 echo $AUTH_URL
33
34 read -p "Code: " CODE
35
36 echo "Requesting code..."
37
38 RESP=$(curl \
39 -XPOST \
40 $INSTANCE_URL/oauth/token \
41 --silent \
42 --header "Content-Type: application/x-www-form-urlencoded" \
43 --data-urlencode "client_id=$client_id" \
44 --data-urlencode "client_secret=$client_secret" \
45 --data-urlencode "code=$CODE" \
46 --data-urlencode "grant_type=authorization_code" \
47 --data-urlencode 'redirect_uri=urn:ietf:wg:oauth:2.0:oob' \
48 --data-urlencode "scope=admin:metrics"
49 )
50
51 ACCESS_TOKEN="$(echo $RESP | jq -r .access_token)"
52
53 echo "Token is $ACCESS_TOKEN"
54 DOMAIN=$(echo $INSTANCE_URL | sed -e 's/^https:\/\///')
55
56 echo "Use the following config in your prometheus.yml:
57 - job_name: akkoma
58 scheme: https
59 authorization:
60 credentials: $ACCESS_TOKEN
61 metrics_path: /api/v1/akkoma/metrics
62 static_configs:
63 - targets:
64 - $DOMAIN
65 "