Skip to content

Commit

Permalink
use sso profile instead of default
Browse files Browse the repository at this point in the history
  • Loading branch information
atn4z7 committed Feb 26, 2024
1 parent f61cf15 commit 466dffa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 5 additions & 3 deletions packages/core-mobile/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

## Setup dev environment

1. Set up React Native environment (https://reactnative.dev/docs/environment-setup)
1. Set up [React Native environment](https://reactnative.dev/docs/environment-setup)

2. Run `yarn envs` to fetch and create all the necessary .env files
2. Set up [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)

3. Run `yarn install && yarn setup` if you haven't
3. Run `yarn envs` to fetch and create all the necessary .env files

4. Run `yarn install && yarn setup` if you haven't

## Build the app

Expand Down
16 changes: 9 additions & 7 deletions packages/core-mobile/scripts/getEnvs.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash

PROFILE_NAME="sso"

# Retrieve secret by id from AWS Secrets Manager
getSecretFromAWS() {
local secret_id="$1"
sudo aws secretsmanager get-secret-value --secret-id "$secret_id" | grep SecretString | sed 's/.*"SecretString": "\(.*\)".*/\1/'
sudo aws --profile $PROFILE_NAME secretsmanager get-secret-value --secret-id "$secret_id" | grep SecretString | sed 's/.*"SecretString": "\(.*\)".*/\1/'
}

# Check if a AWS profile exists
Expand All @@ -19,18 +21,18 @@ awsConfigurationExists() {
}

# Check if profile "default" exists. If not, ask to create one
if ! $(awsConfigurationExists "default"); then
echo 'Profile "default" does not exist. Please create one first!'
sudo aws configure sso
if ! $(awsConfigurationExists $PROFILE_NAME); then
echo "Profile '$PROFILE_NAME' does not exist. Please create one first!"
sudo aws configure sso --profile $PROFILE_NAME
fi

# Check if the session is still valid. If not, ask to re-login
ACCOUNT=$(sudo aws sts get-caller-identity --query "Account")
ACCOUNT=$(sudo aws --profile $PROFILE_NAME sts get-caller-identity --query "Account")

# Account is valid if account is a 12 digit account number plus surrounding double-quotes
if [ ${#ACCOUNT} -ne 14 ]; then
echo 'logging in with profile "default"'
sudo aws sso login --profile default
echo "logging in with profile '$PROFILE_NAME'"
sudo aws sso login --profile $PROFILE_NAME
fi

# Retrieve all envs from AWS
Expand Down

0 comments on commit 466dffa

Please sign in to comment.