From fc24743c978907918c82b27af055107576e80ea7 Mon Sep 17 00:00:00 2001
From: Adar Nimrod <nimrod@shore.co.il>
Date: Thu, 10 Feb 2022 11:37:23 +0200
Subject: [PATCH] smile-exec fixes.

- Run `bundle show smile-cli` correctly in directories that have a
  Gemfile.
- The AWS profile for the security is not in the format of
  smile-$ENV-admin (the only one, I might add). Deal with that.
---
 Documents/bin/smile-exec | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/Documents/bin/smile-exec b/Documents/bin/smile-exec
index 671b388..647a1c6 100755
--- a/Documents/bin/smile-exec
+++ b/Documents/bin/smile-exec
@@ -30,6 +30,13 @@ aws_account() {
     esac
 }
 
+aws_profile() {
+    case "$1" in
+        security) echo "smile-security";;
+        *) echo "smile-$1-admin";;
+    esac
+}
+
 if [ "$#" -eq 0 ]
 then
     usage
@@ -66,7 +73,8 @@ then
 fi
 
 export AWS_CONFIG_FILE="$HOME/.smile/aws/config"
-export AWS_PROFILE="smile-$SMILE_ENV-admin"
+# shellcheck disable=SC2155
+export AWS_PROFILE="$(aws_profile "$SMILE_ENV")"
 export AWS_DEFAULT_PROFILE="$AWS_PROFILE"
 export AWS_DEFAULT_REGION=us-east-1
 export HELM_HOME="$HOME/.smile/helm/$SMILE_ENV-sre"
@@ -79,7 +87,7 @@ export KUBECONFIG="$HOME/.smile/kube/$SMILE_ENV/config"
 export TILLER_NAMESPACE="applications-tiller"
 # shellcheck disable=SC2155
 export VAULT_ADDR="$(vault_addr "$SMILE_ENV")"
-VAULT_CAPATH="$(bundle show smile-cli)/lib/vault_ca"
+VAULT_CAPATH="$(BUNDLE_GEMFILE="$HOME/Repositories/Smile/Gemfile" bundle show smile-cli)/lib/vault_ca"
 export VAULT_CAPATH
 
 connected_vpn="$(dig env.smile.config TXT | xargs)"
@@ -92,9 +100,9 @@ then
     fi
     if [ -n "$VAULT_ADDR" ]
     then
-        aws-vault exec "smile-$SMILE_ENV-admin" -- \
+        aws-vault exec "$AWS_PROFILE" -- \
                 vault login -method aws -no-print role=smile-ops
     fi
 fi
 
-eval exec aws-vault exec "smile-$SMILE_ENV-admin" -- "$@"
+eval exec aws-vault exec "$AWS_PROFILE" -- "$@"
-- 
GitLab