summaryrefslogtreecommitdiff
path: root/evergreen
diff options
context:
space:
mode:
authorRichard Samuels <richard.l.samuels@gmail.com>2021-05-12 15:28:03 -0400
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-17 20:06:28 +0000
commit41650132865a2c81a87d35be46b6811cfba6426b (patch)
treeff008a73e384c0e1f128657251a0da54d858affc /evergreen
parentef9f9abf5f1723aea983a5f65c91576f19cfc120 (diff)
downloadmongo-41650132865a2c81a87d35be46b6811cfba6426b.tar.gz
SERVER-55626 Extract set up remote credentials function
Diffstat (limited to 'evergreen')
-rw-r--r--evergreen/functions/remote_credentials_setup.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/evergreen/functions/remote_credentials_setup.sh b/evergreen/functions/remote_credentials_setup.sh
new file mode 100644
index 00000000000..c5547aa2ba8
--- /dev/null
+++ b/evergreen/functions/remote_credentials_setup.sh
@@ -0,0 +1,46 @@
+DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
+. "$DIR/../prelude.sh"
+
+# Since the macros 'private_key_remote' and 'private_key_file' are not always defined
+# we default to /dev/null to avoid syntax errors of an empty expansion.
+if [ -n "$private_key_remote_bash_var" ]; then
+ private_key_remote="$private_key_remote_bash_var"
+fi
+if [ ! -z "${private_key_remote}" ] && [ ! -z "${private_key_file}" ]; then
+ mkdir -p ~/.ssh
+ private_key_file=$(eval echo "$private_key_file")
+ echo -n "${private_key_remote}" >${private_key_file}
+ chmod 0600 ${private_key_file}
+fi
+
+# Ensure a clean aws configuration state
+rm -rf ~/.aws
+mkdir -p ~/.aws
+
+# If ${aws_profile_remote} is not specified then the config & credentials are
+# stored in the 'default' profile.
+aws_profile="${aws_profile_remote}"
+
+# The profile in the config file is specified as [profile <profile>], except
+# for [default], see http://boto3.readthedocs.io/en/latest/guide/configuration.html
+if [ $aws_profile = "default" ]; then
+ aws_profile_config="[default]"
+else
+ aws_profile_config="[profile $aws_profile]"
+fi
+cat <<EOF >>~/.aws/config
+$aws_profile_config
+region = us-east-1
+EOF
+
+# The profile in the credentials file is specified as [<profile>].
+cat <<EOF >>~/.aws/credentials
+[$aws_profile]
+aws_access_key_id = ${aws_key_remote}
+aws_secret_access_key = ${aws_secret_remote}
+EOF
+
+cat <<EOF >~/.boto
+[Boto]
+https_validate_certificates = False
+EOF