-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonvault.sh
More file actions
executable file
·40 lines (32 loc) · 900 Bytes
/
onvault.sh
File metadata and controls
executable file
·40 lines (32 loc) · 900 Bytes
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
#!/bin/bash -e
function log {
echo "onvault: $*"
}
function load_secret {
key="${1}"
path="${2}"
# backup file
( test -f "${path}" && mv -f "${path}" "${path}_bck" ) || true
mkdir -p "$(dirname "${path}")"
aws secretsmanager get-secret-value --secret-id ${key} --region us-west-1 --query 'SecretString' --output text > "${path}"
chown "$(whoami)" "${path}"
chmod 700 "${path}"
log "secret created: ${path}"
}
function unload_secret {
key="${1}"
path="${2}"
rm -f "${path}"
# restore backed file
( test -f "${path}_bck" && mv -f "${path}_bck" "${path}") || true
}
# cleanup function (will be executed on exit)
function cleanup {
unload_secret vault/npmrc ${HOME}/.npmrc
unload_secret vault/id_rsa ${HOME}/.ssh/id_rsa
log "secrets removed"
}
trap cleanup EXIT INT
load_secret vault/npmrc ${HOME}/.npmrc
load_secret vault/id_rsa ${HOME}/.ssh/id_rsa
eval "$@"