You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.5 KiB
Bash
59 lines
1.5 KiB
Bash
3 years ago
|
#!/usr/bin/env bash
|
||
|
# vim:ts=4:sts=4:sw=4:et
|
||
|
#
|
||
|
# Author: Hari Sekhon
|
||
|
# Date: 2021-11-24 12:40:18 +0000 (Wed, 24 Nov 2021)
|
||
|
#
|
||
2 years ago
|
# https://github.com/HariSekhon/DevOps-Bash-tools
|
||
3 years ago
|
#
|
||
|
# License: see accompanying Hari Sekhon LICENSE file
|
||
|
#
|
||
|
# If you're using my code you're welcome to connect with me on LinkedIn and optionally send me feedback to help steer this or other code I publish
|
||
|
#
|
||
2 years ago
|
# https://www.linkedin.com/in/HariSekhon
|
||
3 years ago
|
#
|
||
|
|
||
|
set -euo pipefail
|
||
|
[ -n "${DEBUG:-}" ] && set -x
|
||
|
srcdir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
||
1 year ago
|
# shellcheck disable=SC1090,SC1091
|
||
3 years ago
|
. "$srcdir/lib/gcp.sh"
|
||
3 years ago
|
|
||
|
# shellcheck disable=SC2034,SC2154
|
||
|
usage_description="
|
||
|
Reads a value from the command line without echo'ing it on the screen and updates the given GCP Secret Manager secret
|
||
|
|
||
|
First argument is used as secret name - if not given prompts for it
|
||
3 years ago
|
Second argument is used as secret string value
|
||
|
- if this argument is a file, such as an SSH key, reads the file content and saves it as the secret value
|
||
|
- if not given prompts for it with a non-echo'ing prompt (recommended for passwords)
|
||
3 years ago
|
Third or more args are passed to 'gcloud secrets'
|
||
|
|
||
|
|
||
3 years ago
|
$usage_gcloud_sdk_required
|
||
3 years ago
|
"
|
||
|
|
||
|
# used by usage() in lib/utils.sh
|
||
|
# shellcheck disable=SC2034
|
||
|
usage_args="<name> [<secret> <gcloud_options>]"
|
||
|
|
||
|
help_usage "$@"
|
||
|
|
||
3 years ago
|
min_args 1 "$@"
|
||
3 years ago
|
|
||
3 years ago
|
name="$1"
|
||
3 years ago
|
secret="${2:-}"
|
||
3 years ago
|
shift || :
|
||
3 years ago
|
shift || :
|
||
3 years ago
|
|
||
3 years ago
|
if [ -z "$secret" ]; then
|
||
|
read_secret
|
||
3 years ago
|
fi
|
||
|
|
||
3 years ago
|
if [ -f "$secret" ]; then
|
||
|
secret="$(cat "$secret")"
|
||
|
fi
|
||
|
|
||
3 years ago
|
gcloud secrets versions add "$name" --data-file - "$@" <<< "$secret"
|