-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_token.sh
executable file
·55 lines (47 loc) · 1.47 KB
/
gen_token.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
#!/bin/bash
# This script allows external users to generate a temporary Github access token
# that allows them to download Lekko's developer tools.
# This script should be executed in the following context:
#
# export LEKKO_API_KEY=lekko_************
# export HOMEBREW_GITHUB_API_TOKEN=$(./gen_token.sh)
# brew tap lekkodev/lekko
# brew install lekko
#
# The script depends on the LEKKO_API_KEY environment variable. This apikey should be
# generated within the Lekko app for a specific team. The script also depends on the
# following tools: brew, curl, jq
# For upgrades, the following sequence of commands should be run:
#
# export LEKKO_API_KEY=lekko_************
# export HOMEBREW_GITHUB_API_TOKEN=$(./gen_token.sh)
# brew upgrade lekko
#
abort() {
printf "%s\n" "$@" >&2
exit 1
}
check_tool_exists() {
if ! command -v "$@" &> /dev/null
then
abort "tool $@ could not be found"
fi
}
if [ -z $LEKKO_API_KEY ]
then
abort "env LEKKO_API_KEY could not be found"
fi
# Fail fast with a concise message when not using bash
if [ -z "${BASH_VERSION:-}" ]
then
abort "Bash is required to interpret this script."
fi
check_tool_exists brew # brew is needed to install lekko in later steps
check_tool_exists curl
check_tool_exists jq
token=$(curl -s \
-H "apikey: $LEKKO_API_KEY" \
-H "Content-Type: application/json" \
-X POST -d '{}' \
https://web.api.lekko.dev/lekko.backend.v1beta1.DistributionService/GetDeveloperAccessToken | jq -r .token)
echo $token