forked from cloud-gov/cg-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3-secret
executable file
·73 lines (57 loc) · 1.47 KB
/
s3-secret
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
#!/usr/bin/env bash
set -euo pipefail
shopt -s inherit_errexit
main() {
[[ $# -ge 2 ]] || usage "Expected at least two arguments, got $#"
[[ -v SECRETS_BUCKET ]] || usage "Must set $SECRETS_BUCKET variable first."
command=$1; shift
case $command in
upload)
upload "$@"
;;
download)
download "$@"
;;
*)
usage "Unknown command: $command"
;;
esac
}
upload() {
[[ $# -ge 1 ]] || usage "Wrong number of arguments to upload"
for file in "$@"; do
echo "$file"
aws s3 cp --only-show-errors --sse=AES256 "$file" "$SECRETS_BUCKET"
done
}
download() {
[[ $# -eq 2 ]] || usage "Wrong number of arguments to download"
file="$1"; shift
directory="$1"; shift
mkdir -p "$directory"
case $file in
all)
aws s3 cp --only-show-errors --recursive "$SECRETS_BUCKET" "$directory"
;;
*)
aws s3 cp --only-show-errors "$SECRETS_BUCKET/$file" "$directory/$file"
;;
esac
}
usage() {
[[ $# -gt 0 ]] && (echo "ERROR: $*"; echo)
cat <<EOF
USAGE:
$(basename "$0") upload file1 file2 ...
$(basename "$0") download remote_file directory
$(basename "$0") download all directory
Uploads and downloads cloud.gov secrets to/from the S3 buckets. "download all"
will get all files, recursively. Requires SECRETS_BUCKET to be set.
Examples:
$(basename "$0") upload path/to/secrets.yml
$(basename "$0") download secret.yml secrets_dir
$(basename "$0") download all secrets_dir
EOF
exit 1
}
main "$@"