-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.sh
executable file
·58 lines (44 loc) · 1.36 KB
/
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
56
57
58
#!/usr/bin/env bash
source bashlib.sh
# check openssl is installed
require openssl
algo() { openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 10000 -salt "$@"; }
Target=.token.enc
# nice usage message
usage() {
cat <<EOF
Token management utility, using openssl.
./token.sh <Command> <Args...>
Commands (prompts for encryption password):
set <Token>
Encrypt input token and save as '$Target'.
Prompts for encryption password (do NOT use your sudo password).
get
Echo decrypted token to console.
Prompts for encryption password used with 'set' command.
Information:
To obtain a token for your project, follow these steps:
1. Create a user account on: https://pypi.org/
2. Login and go to: Account Settings > API tokens > Add API token
3. Create a token for your project (only after the first publish)
4. Copy the secret token to clipboard, and call:
./token.sh set <Token>
EOF
exit 0
}
# ------------------------------------------------------------------------
[ $# -lt 1 ] && usage
Command=$1
shift
case $Command in
get|dec*)
[ -f "$Target" ] || echoerr "No token found; did you previously call the 'set' command?"
algo -d -in "$Target"
;;
set|enc*)
echo "$1" | algo -out "$Target"
;;
*)
echoerr "Unknown command: $Command"
;;
esac