Skip to content

Commit

Permalink
Merge pull request #14 from Magicloud/bootstrap
Browse files Browse the repository at this point in the history
Bootstrap AWS secrets.
  • Loading branch information
snoyberg authored Aug 26, 2021
2 parents 0196830 + 4b73746 commit 9d9be17
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions helper_scripts/bootstrap_aws.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/bin/sh

set -eu -o pipefail

chk_tools () {
ok=true
for i in $@; do
if ! which "${i}" > /dev/null 2>&1; then
ok=false
echo "Tool ${i} does not exist in env PATH. Please install it." >&2
fi
done
${ok}
}

chk_envs () {
ok=true
for i in $@; do
eval "x=\"\${${i}-~~~}\""
if [ "${x}" = '~~~' ]; then
ok=false
echo "Environment variable ${i} needs to be set." >&2
fi
done
${ok}
}

get_envs () {
ok=true
for i in $@; do
if ! (chk_envs "${i}" > /dev/null 2>&1 ||
eval "$(amber print | grep " ${i}=")"); then
ok=false
echo "Environment variable ${i} needs to be set, or in Amber secrets." >&2
fi
done
${ok}
}

### main

# Due to awscli takes value of secret in commandline, and some secrets are in environments, both are easily to be observed. This script must be run in a trusted environment.

chk_tools 'amber' 'jq' 'aws'
chk_envs 'AMBER_SECRET' 'AWS_REGION'
get_envs 'AWS_ACCESS_KEY_ID' 'AWS_SECRET_ACCESS_KEY'

size="$(amber print --style json | jq -r '. | length')"

for i in $(seq "${size}"); do
i="$(( i - 1 ))"
aws secretsmanager create-secret --name "$(amber print --style json | jq -r ".[${i}].key")" --secret-string "$(amber print --style json | jq -r ".[${i}].value")"
done

0 comments on commit 9d9be17

Please sign in to comment.