Skip to content

Commit 95b77d8

Browse files
author
Stuart H Jimenez
committed
Simple api key generator
1 parent 608b9d7 commit 95b77d8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

bin/v-generate-api-key

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# info: generate api key
3+
# options: none
4+
#
5+
# The function creates a key file in /usr/local/vesta/data/keys/
6+
7+
8+
#----------------------------------------------------------#
9+
# Variable&Function #
10+
#----------------------------------------------------------#
11+
12+
keygen()
13+
{
14+
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
15+
}
16+
KEYS='/usr/local/vesta/data/keys/'
17+
HASH=$(keygen)
18+
19+
20+
#----------------------------------------------------------#
21+
# Action #
22+
#----------------------------------------------------------#
23+
24+
if [[ -e ${KEYS}${HASH} ]] ; then
25+
while [[ -e ${KEYS}${HASH} ]] ; do
26+
HASH=$(keygen)
27+
done
28+
fi
29+
30+
touch ${KEYS}${HASH}
31+
echo ${HASH}
32+
33+
#----------------------------------------------------------#
34+
# Vesta #
35+
#----------------------------------------------------------#
36+
37+
exit

0 commit comments

Comments
 (0)