Skip to content

Commit

Permalink
Added envrc back into git tracking with chamber modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
cameroncaci committed Oct 5, 2023
1 parent da269a3 commit 9d7b338
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 2 deletions.
96 changes: 96 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#! /usr/bin/env bash

# DO NOT WRITE SECRETS IN HERE

# Apache variables
export PROVIDER="org.apache.ws.security.components.crypto.Merlin"
export CLIENT_PROPS_FILE_PATH="src/main/resources/client_sign.properties"

required_vars=()
var_docs=()

# Declare an environment variable as required.
#
# require VAR_NAME "Documentation about how to define valid values"
require() {
required_vars+=("$1")
var_docs+=("$2")
}
# Check all variables declared as required. If any are missing, print a message and
# exit with a non-zero status.
check_required_variables() {
missing_var=false

for i in "${!required_vars[@]}"; do
var=${required_vars[i]}
if [[ -z "${!var:-}" ]]; then
log_status "${var} is not set: ${var_docs[i]}"
missing_var=true
fi
done

if [[ $missing_var == "true" ]]; then
log_error "Your environment is missing some variables!"
log_error "Set the above variables in .envrc.local and try again."
fi
}



#############################
# AWS VAULT SETTINGS #
#############################

export AWS_VAULT_KEYCHAIN_NAME=login

#############################
# Load Secrets from Chamber #
#############################

# Make Chamber read ~/.aws/config
export AWS_SDK_LOAD_CONFIG=1
# Make Chamber use the default AWS KMS key
export CHAMBER_KMS_KEY_ALIAS='alias/aws/ssm'
# Make Chamber use path based keys ('/' instead of '.')
export CHAMBER_USE_PATHS=1
# Sets the number of retries for chamber to 20.
export CHAMBER_RETRIES=20

# Loads secrets from chamber instead of requiring them to be listed in .envrc.local

if [ -e .envrc.chamber ]; then
# Loading secrets from Chamber can take a while. Prevent direnv from
# complaining.
export DIRENV_WARN_TIMEOUT="20s"

# Evaluate if the files have drifted
if ! cmp .envrc.chamber .envrc.chamber.template >/dev/null 2>&1; then
log_error "Your .envrc.chamber has drifted from .envrc.chamber.template. Please 'cp .envrc.chamber.template .envrc.chamber'"
fi

source_env .envrc.chamber
else
log_status "Want to load secrets from chamber? 'cp .envrc.chamber.template .envrc.chamber'"
fi

# Load Keypair Secrets
require TRDM_LAMBDA_MILMOVE_KEYPAIR_BASE64 "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_base64'"
require TRDM_LAMBDA_MILMOVE_KEYPAIR_KEY "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_key'"
require TRDM_LAMBDA_MILMOVE_KEYPAIR_ALIAS "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_alias'"
require TRDM_LAMBDA_MILMOVE_KEYPAIR_TYPE "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_type'"
require TRDM_LAMBDA_MILMOVE_KEYPAIR_FILEPATH "See 'DISABLE_AWS_VAULT_WRAPPER=1 AWS_REGION=us-gov-west-1 aws-vault exec transcom-gov-dev -- chamber read trdm-lambda-dev trdm_lambda_milmove_keypair_filepath'"

##############################################
# Load Local Overrides and Check Environment #
##############################################

# Load a local overrides file. Any changes you want to make for your local
# environment should live in that file.

if [ -e .envrc.local ]
then
source_env .envrc.local
fi

# Check that all required environment variables are set
check_required_variables
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
hs_err_pid*
replay_pid*

# Local dev testing
.env
.envrc
*.p12
*.jks
src/main/resources/client_sign.properties
Expand Down

0 comments on commit 9d7b338

Please sign in to comment.