-
-
Notifications
You must be signed in to change notification settings - Fork 132
/
Copy pathbackend.sh
80 lines (60 loc) · 1.8 KB
/
backend.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env sh
set -euf
# Define the allowed secret backends
ALLOWED_BACKENDS="${HELM_SECRETS_ALLOWED_BACKENDS:-}"
# shellcheck source=scripts/lib/backends/noop.sh
. "${SCRIPT_DIR}/lib/backends/noop.sh"
# shellcheck source=scripts/lib/backends/sops.sh
. "${SCRIPT_DIR}/lib/backends/sops.sh"
# shellcheck source=scripts/lib/backends/vals.sh
. "${SCRIPT_DIR}/lib/backends/vals.sh"
is_secret_backend() {
[ -f "${SCRIPT_DIR}/lib/backends/${1}.sh" ] || [ -f "${1}" ]
}
load_secret_backend() {
backend="${1}"
if [ "${backend}" = "" ]; then
return
fi
if [ "${ALLOWED_BACKENDS}" != "" ]; then
case "${ALLOWED_BACKENDS}" in
"${backend}" | "${backend},"* | *",${backend}" | *",${backend},"*) ;;
*)
fatal "secret backend '%s' not allowed" "${1}"
;;
esac
fi
if [ -f "${SCRIPT_DIR}/lib/backends/${backend}.sh" ]; then
# shellcheck disable=SC2034
SECRET_BACKEND="${backend}"
return
fi
# Allow to load out of tree backends.
if [ ! -f "${backend}" ]; then
fatal "Can't find secret backend: %s" "${backend}"
fi
# shellcheck disable=SC2034
SECRET_BACKEND="custom"
# shellcheck disable=SC2034
HELM_SECRETS_SCRIPT_DIR="${SCRIPT_DIR}"
# shellcheck source=tests/assets/custom-backend.sh
. "${1}"
}
backend_is_file_encrypted() {
_"${SECRET_BACKEND}"_backend_is_file_encrypted "$@"
}
backend_is_encrypted() {
_"${SECRET_BACKEND}"_backend_is_encrypted "$@"
}
backend_encrypt_file() {
_"${SECRET_BACKEND}"_backend_encrypt_file "$@"
}
backend_decrypt_file() {
_"${SECRET_BACKEND}"_backend_decrypt_file "$@"
}
backend_decrypt_literal() {
_"${SECRET_BACKEND}"_backend_decrypt_literal "$@"
}
backend_edit_file() {
_"${SECRET_BACKEND}"_backend_edit_file "$@"
}