Skip to content

Commit 53b7b67

Browse files
Feat graceful fail noenv (#209)
* chore: Refactor environment variable handling and add utility functions for local development * chore: Fix link to the latest schedule in Fall 2024 documentation * chore: Added configuration script command to `npm start` command. Update gitignore for local environment files. Defined ground truth files for local and dev environment configurations. * feat: Added gt processing script to prompt and create env file from gt specs * feat: Variable validation against `.gt` file functional to spec * feat: Bash based environment configuration implemented * chore: Updates to gt files * chore: Reconfigured file structure of dev configuration scripts * chore: Remove Immersion iFrame until it gets developed further * feat: Updated local and dev configuration on higher level code, audited dev configuration script to validate with auth config only, added additional runtime config for local in package.json, removed iframes on landing page, removed access to protected routes on local mode * chore: Updated readme * fix: Attempted fix for production CI/CD pipeline workflow --------- Co-authored-by: Martin Marwad <[email protected]>
1 parent dbf905b commit 53b7b67

File tree

18 files changed

+269
-73
lines changed

18 files changed

+269
-73
lines changed

.gitignore

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@
1010
.docusaurus
1111
.cache-loader
1212

13+
# Generated env files
14+
.env.local
15+
.env.dev
16+
1317
# Misc
1418
.DS_Store
15-
.env.local
16-
.env.development.local
17-
.env.test.local
18-
.env.production.local
19+
# .env.local
20+
# .env.development.local
21+
# .env.test.local
22+
# .env.production.local
1923

2024
npm-debug.log*
2125
yarn-debug.log*
2226
yarn-error.log*
2327

24-
# AWS Secrets
25-
IAM_Automation/aws_creds.py
26-
2728
# Terraform Stack build files
2829
.terraform
2930
.terraform.lock.hcl

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,10 @@ Here are the steps:
217217
> 2. `sudo apt install mkcert`
218218
> 3. Confirm your installation: `mkcert --version`
219219

220-
Similarly, some local environment variables must be specified in order to ensure functionality:
221-
1. Create a copy of the file called `env.template`
222-
2. Within this file populate the provided variables using information available on the AWS Console for Cognito.
223-
3. Once populated with the correct information, authentication should work correctly
220+
Similarly, some local environment variables must be specified in order to ensure functionality with authenication:
221+
- Use `npm run local` to develop locally **without** authentication enabled
222+
- Use `npm start` to develop locally **with** authentication
223+
- If environment variables are not configured, you will be prompted to provide them
224224

225225
## 🎉Acknowledgements
226226
Many thanks to the [UMass Lowell Cloud Computing Club](https://umasslowellclubs.campuslabs.com/engage/organization/cloudcomputingclub) members, our faculty advisor [Dr. Johannes Weis](https://www.uml.edu/sciences/computer-science/people/weis-johannes.aspx), and the [UMass Lowell Computer Science Department](https://www.uml.edu/Sciences/computer-science/) for their support and guidance.

docs/schedule/2024Fall/2024Fall.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ogDescription: Explore the Fall 2024 meeting schedule for the UMass Lowell Cloud
88
---
99

1010
:::danger
11-
This schedule is outdated and refers to a past semester. Please check the [latest schedule](../current-schedule) for current information.
11+
This schedule is outdated and refers to a past semester. Please check the [latest schedule](../docs/current-schedule) for current information.
1212
:::
1313

1414

docusaurus.config.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import remarkMath from 'remark-math';
99
import rehypeKatex from 'rehype-katex';
1010

1111
const process = require('node:process');
12+
const env_type = process.env.ENV;
1213

1314
/** @type {import('@docusaurus/types').Config} */
1415
const config = {
@@ -85,7 +86,8 @@ const config = {
8586
[
8687
"docusaurus-plugin-dotenv",
8788
{
88-
path: "./.env.local",
89+
default: "./.env.local",
90+
path: "./.env.dev",
8991
systemvars: true,
9092
},
9193
// '@docusaurus/plugin-content-docs',
@@ -118,14 +120,14 @@ const config = {
118120
disableSwitch: false,
119121
respectPrefersColorScheme: true,
120122
},
121-
announcementBar: {
122-
id: 'announcement-bar',
123-
content:
124-
'☀️ Summer Meetings start Virtually on May 17th! ✍️',
125-
backgroundColor: '#48a0ff',
126-
textColor: '#fff',
127-
isCloseable: false
128-
},
123+
// announcementBar: {
124+
// id: 'announcement-bar',
125+
// content:
126+
// '☀️ Summer Meetings start Virtually on May 17th! ✍️',
127+
// backgroundColor: '#48a0ff',
128+
// textColor: '#fff',
129+
// isCloseable: false
130+
// },
129131
navbar: {
130132
title: 'UML Cloud Computing Club',
131133
logo: {

env.template

Lines changed: 0 additions & 34 deletions
This file was deleted.

env_config/.gt/dev.gt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ENV
2+
REGION
3+
USER_POOL_ID
4+
USER_POOL_WEB_CLIENT_ID
5+
OAUTH_DOMAIN
6+
OAUTH_REDIRECT_SIGN_OUT
7+
OAUTH_REDIRECT_SIGN_RESPONSE_TYPE
8+
AUTHORITY
9+
CLIENT_ID
10+
REDIRECT_URI
11+
SCOPE

env_config/.gt/local.gt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ENV

env_config/configure_dev.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash
2+
3+
# Prompt and read
4+
clear
5+
# echo "Select an environment type:"
6+
# echo "--------------------------------"
7+
# echo "1: Local (default)"
8+
# echo "2: Dev"
9+
10+
# read -p "Choose a number (1 or 2): " choice
11+
12+
# case $choice in
13+
# 1) ENV="local" ;;
14+
# 2) ENV="dev" ;;
15+
# *) echo "Invalid choice. Exiting..."
16+
# exit 1;;
17+
# esac
18+
# echo "----------------------------------------------"
19+
20+
# Determine file type based on choice
21+
22+
# NEW: Changed to be exclusively for dev session with authentication
23+
env_file=".env.dev" # Determines file name to source/create
24+
gt_file="./env_config/.gt/dev.gt" # Determines the ground truth (gt) file to validate against
25+
26+
declare -A env_vars
27+
28+
# Check if the file exists
29+
if [ -f "$env_file" ]; then
30+
# If the file exists, source it and validate the contents
31+
. ./env_config/validate_vars.sh "$gt_file" "$env_file"
32+
33+
else
34+
# If the file does not exist, prompt for and create it
35+
. ./env_config/process_gt.sh "$gt_file" "$env_file"
36+
fi
37+
38+
set -a
39+
source $env_file
40+
export ENV
41+
42+
echo -e "Environment variables set successfully!\n"

env_config/process_gt.sh

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Prompts environment variables as per ground truth file
4+
# Exports environment variables to environment file
5+
6+
# WARNING: Flushes env file before writing!
7+
8+
# Args:
9+
# 1: Ground truth file
10+
# 2: Environment file to source
11+
gt_file=$1
12+
env_file=$2
13+
14+
declare -A env_vars
15+
16+
read_and_prompt() {
17+
local line
18+
# Read env vars from gt file
19+
while IFS= read -r line; do
20+
# Skip preprocessing, input is assumed to be in the correct format
21+
local var_name="$line"
22+
23+
# Check if variable name has not been asked for before (avoid duplicates)
24+
if [[ ! ${env_vars[$var_name]} ]]; then
25+
echo -n "$var_name: "
26+
read value < /dev/tty
27+
env_vars[$var_name]=$value
28+
fi
29+
30+
# Uncomment if implementing custom `gt` file format validation
31+
# else
32+
# echo "Error: Invalid format. Expected ..., found '$line'". Skipping..."
33+
#fi
34+
done
35+
}
36+
37+
# Read and prompt for env vars
38+
read_and_prompt < "$gt_file"
39+
40+
# Flush file
41+
:> "$env_file"
42+
43+
# Export environment variables to destination file
44+
for key in "${!env_vars[@]}"; do
45+
echo "$key=\"${env_vars[$key]}\"" >> "$env_file"
46+
done
47+
48+
echo -e "\nEnvironment variables exported to $env_file"
49+
echo -e "---------------------------------------------\n"

env_config/validate_vars.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Validates environment variables against ground truth file
4+
5+
# Args
6+
# 1: Ground truth file
7+
# 2: Environment file to source
8+
gt_file=$1
9+
env_file=$2
10+
is_invalid=false
11+
12+
declare -A env_vars
13+
source $env_file
14+
15+
validate_var() {
16+
local var_name=$1
17+
# Return non-zero value if variable name is invalid
18+
if [[ -z "$var_name" ]] || [[ -z "${!var_name}" ]]; then
19+
return 1
20+
fi
21+
return 0;
22+
}
23+
24+
# Read env vars from gt file
25+
while IFS= read -r line; do
26+
# Skip preprocessing, input is assumed to be in the correct format
27+
variable_name=$line
28+
29+
# Check if variable name has not been checked before (avoid duplicates)
30+
if [[ ! ${env_vars[$variable_name]} ]]; then
31+
if validate_var "$variable_name"; then
32+
echo -e "+ $variable_name configured!"
33+
else
34+
echo -e "- $variable_name is not configured!"
35+
is_invalid=true
36+
fi
37+
38+
fi
39+
done < "$gt_file"
40+
41+
# Conditionally set exit status
42+
if [ "$is_invalid" = true ]; then
43+
echo -e "Invalid configuration, please check if variables are configured as per $gt_file!\n"
44+
exit 3
45+
else
46+
echo -e "Environment variables validated against $gt_file"
47+
echo -e "----------------------------------------------";
48+
fi

0 commit comments

Comments
 (0)