-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_secret.sh
executable file
·63 lines (57 loc) · 1.47 KB
/
generate_secret.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
59
60
61
62
63
#!/bin/bash
username=""
token=""
function show_help {
echo "Usage: $0 --username USERNAME --token TOKEN"
echo
echo "Options:"
echo " --username Specify the username (required)"
echo " --token Specify the token (required)"
echo " --help Display this help message"
echo
exit 0
}
while [[ $# -gt 0 ]]; do
case $1 in
--username)
if [[ -n "$2" && "$2" != "--"* ]]; then
username="$2"
shift 2
else
echo "Error: '--username' requires a non-empty value."
show_help
fi
;;
--token)
if [[ -n "$2" && "$2" != "--"* ]]; then
token="$2"
shift 2
else
echo "Error: '--token' requires a non-empty value."
show_help
fi
;;
--help)
show_help
;;
*)
echo "Invalid option: $1"
show_help
;;
esac
done
if [[ -z "$username" || -z "$token" ]]; then
echo "Error: Both 'username' and 'token' parameters are required."
exit 1
fi
token_base_64=$(echo -n "${username}":"${token}" | base64)
auths_json=$(echo -n "{\"auths\":{\"ghcr.io\":{\"auth\":\"$token_base_64\"}}}" | base64)
echo "kind: Secret
type: kubernetes.io/dockerconfigjson
apiVersion: v1
metadata:
name: github-registry
labels:
app: coin-board
data:
.dockerconfigjson: ${auths_json}"