From 53e4da070aba4e24adc03de3996d1690e460ab22 Mon Sep 17 00:00:00 2001 From: Martin Marwad <44274319+MartinMarwad@users.noreply.github.com> Date: Sat, 17 May 2025 19:34:49 +0000 Subject: [PATCH 01/13] chore: Refactor environment variable handling and add utility functions for local development --- src/components/Auth/index.js | 12 +++++++++-- src/config/cognito-auth-config.js | 14 ++++++++----- src/config/cognito-configure.js | 12 +++++++++++ src/utils/env.js | 35 +++++++++++++++++++++++++++++++ src/utils/utils.js | 11 ++++++++-- 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 src/utils/env.js diff --git a/src/components/Auth/index.js b/src/components/Auth/index.js index 52793b4c3..ad29a4488 100644 --- a/src/components/Auth/index.js +++ b/src/components/Auth/index.js @@ -5,6 +5,7 @@ import React from "react"; import { useAuth } from "react-oidc-context"; import { Redirect, useLocation } from "@docusaurus/router"; import ReactLoading from 'react-loading'; +import { isEnvLocalLoaded } from '../../utils/env'; import { // AUTHENTICATED, @@ -20,8 +21,15 @@ export function AuthCheck({ children }) { let from = location.pathname; const auth = useAuth(); - const [local_logout_uri, prod_logout_uri] = process.env.OAUTH_REDIRECT_SIGN_OUT.split(","); - + // If .env.local is missing, skip all auth logic and just render children + if (!isEnvLocalLoaded()) { + return <>{children}; + } + + // Defensive: Only split if OAUTH_REDIRECT_SIGN_OUT is defined + const signOutUris = process.env.OAUTH_REDIRECT_SIGN_OUT ? process.env.OAUTH_REDIRECT_SIGN_OUT.split(",") : ["", ""]; + const [local_logout_uri, prod_logout_uri] = signOutUris; + const signOutRedirect = () => { const clientId = process.env.CLIENT_ID; const logoutUri = process.env.ENV === "localhost" diff --git a/src/config/cognito-auth-config.js b/src/config/cognito-auth-config.js index 22b8be6b1..1dfacb64c 100644 --- a/src/config/cognito-auth-config.js +++ b/src/config/cognito-auth-config.js @@ -1,11 +1,15 @@ // src/config/cognito-auth-config.js +import { isEnvLocalLoaded, getEnvVar } from '../utils/env'; + const cognitoAuthConfig = { - authority: process.env.AUTHORITY, - client_id: process.env.CLIENT_ID, - redirect_uri: process.env.REDIRECT_URI, - response_type: process.env.OAUTH_REDIRECT_SIGN_RESPONSE_TYPE, - scope: process.env.SCOPE, + authority: getEnvVar('AUTHORITY'), + client_id: getEnvVar('CLIENT_ID'), + redirect_uri: getEnvVar('REDIRECT_URI'), + response_type: getEnvVar('OAUTH_REDIRECT_SIGN_RESPONSE_TYPE', 'code'), + scope: getEnvVar('SCOPE', 'email openid phone'), + // Add a flag for local mode + isLocalDev: !isEnvLocalLoaded(), }; export default cognitoAuthConfig; diff --git a/src/config/cognito-configure.js b/src/config/cognito-configure.js index ca0291722..119384ed2 100644 --- a/src/config/cognito-configure.js +++ b/src/config/cognito-configure.js @@ -1,8 +1,20 @@ // src/config/cognito-config.js import cognitoAuthConfig from "./cognito-auth-config"; +import { isEnvLocalLoaded } from '../utils/env'; export function configure() { + // If .env.local is missing, fallback to local dev mode and skip config + if (!isEnvLocalLoaded()) { + return { + ...cognitoAuthConfig, + // Optionally, set all sensitive/remote fields to undefined + authority: undefined, + client_id: undefined, + redirect_uri: undefined, + isLocalDev: true, + }; + } // Assuming you have two redirect URIs, and the first is for localhost and // second is for production const [localRedirectURI, prodRedirectURI] = diff --git a/src/utils/env.js b/src/utils/env.js new file mode 100644 index 000000000..8c0d15292 --- /dev/null +++ b/src/utils/env.js @@ -0,0 +1,35 @@ +// src/utils/env.js + +// This utility checks for required env vars and provides fallbacks for local dev + +const REQUIRED_ENV_VARS = [ + 'AUTHORITY', + 'CLIENT_ID', + 'REDIRECT_URI', + 'OAUTH_REDIRECT_SIGN_RESPONSE_TYPE', + 'SCOPE', + 'REGION', + 'USER_POOL_ID', + 'USER_POOL_WEB_CLIENT_ID', + 'OAUTH_DOMAIN', + 'OAUTH_REDIRECT_SIGN_OUT', + 'ENV', +]; + +function isEnvLocalLoaded() { + // If any required env var is missing, assume .env.local is not loaded + return REQUIRED_ENV_VARS.every((key) => typeof process.env[key] === 'string' && process.env[key] !== ''); +} + +function getEnvVar(key, fallback = undefined) { + if (typeof process.env[key] === 'string' && process.env[key] !== '') { + return process.env[key]; + } + // Fallback for local dev + if (fallback !== undefined) return fallback; + // Some defaults for local dev + if (key === 'ENV') return 'localhost'; + return undefined; +} + +export { isEnvLocalLoaded, getEnvVar }; diff --git a/src/utils/utils.js b/src/utils/utils.js index b4c2a9901..fc357c728 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -11,9 +11,13 @@ import { LOGOUT_BUTTON, LOGOUT_PATH, } from "./constants"; +import { isEnvLocalLoaded } from './env'; export function useNavbarItemsMobile() { - // const { route } = useAuthenticator((context) => [context.route]); + if (!isEnvLocalLoaded()) { + // If .env.local is missing, do not render auth-related navbar items + return useThemeConfig().navbar.items; + } const auth = useAuth(); let authElement; @@ -61,7 +65,10 @@ export function useNavbarItemsMobile() { } export function useNavbarItemsDesktop() { - // const { route } = useAuthenticator((context) => [context.route]); + if (!isEnvLocalLoaded()) { + // If .env.local is missing, do not render auth-related navbar items + return useThemeConfig().navbar.items; + } const auth = useAuth(); let authElement; From 5934e483181a26512b411534e921d2cb474ae3ff Mon Sep 17 00:00:00 2001 From: Martin Marwad <44274319+MartinMarwad@users.noreply.github.com> Date: Sat, 17 May 2025 20:04:29 +0000 Subject: [PATCH 02/13] chore: Fix link to the latest schedule in Fall 2024 documentation --- docs/schedule/2024Fall/2024Fall.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/schedule/2024Fall/2024Fall.md b/docs/schedule/2024Fall/2024Fall.md index a4185a2fb..70e4fef76 100644 --- a/docs/schedule/2024Fall/2024Fall.md +++ b/docs/schedule/2024Fall/2024Fall.md @@ -8,7 +8,7 @@ ogDescription: Explore the Fall 2024 meeting schedule for the UMass Lowell Cloud --- :::danger -This schedule is outdated and refers to a past semester. Please check the [latest schedule](../current-schedule) for current information. +This schedule is outdated and refers to a past semester. Please check the [latest schedule](../docs/current-schedule) for current information. ::: From 634c770c6607ee4f7a7ad3203e1d0ff8a8643f71 Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Thu, 22 May 2025 15:52:36 -0400 Subject: [PATCH 03/13] 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. --- .gitignore | 15 ++++++++------- .gt/dev.gt | 11 +++++++++++ .gt/local.gt | 1 + package.json | 2 +- 4 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .gt/dev.gt create mode 100644 .gt/local.gt diff --git a/.gitignore b/.gitignore index fce2cec75..cce39c460 100644 --- a/.gitignore +++ b/.gitignore @@ -10,20 +10,21 @@ .docusaurus .cache-loader +# Generated env files +.env.local +.env.dev + # Misc .DS_Store -.env.local -.env.development.local -.env.test.local -.env.production.local +# .env.local +# .env.development.local +# .env.test.local +# .env.production.local npm-debug.log* yarn-debug.log* yarn-error.log* -# AWS Secrets -IAM_Automation/aws_creds.py - # Terraform Stack build files .terraform .terraform.lock.hcl diff --git a/.gt/dev.gt b/.gt/dev.gt new file mode 100644 index 000000000..6a9740490 --- /dev/null +++ b/.gt/dev.gt @@ -0,0 +1,11 @@ +ENV +REGION +USER_POOL_ID +USER_POOL_WEB_CLIENT_ID +OAUTH_DOMAIN +OAUTH_REDIRECT_SIGN_OUT +OAUTH_REDIRECT_SIGN_RESPONSE_TYPE +AUTHORITY +CLIENT_ID +REDIRECT_URI +SCOPE \ No newline at end of file diff --git a/.gt/local.gt b/.gt/local.gt new file mode 100644 index 000000000..95497050a --- /dev/null +++ b/.gt/local.gt @@ -0,0 +1 @@ +ENV \ No newline at end of file diff --git a/package.json b/package.json index 362e66978..11b90ffab 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "import": "node stream.js && rm -rf temp_resources && rm -rf temp_activity && rm -rf temp_projects", "docusaurus": "docusaurus", - "start": "docusaurus start", + "start": "./configure_dev && docusaurus start", "build": "docusaurus build && cp CNAME build/", "swizzle": "docusaurus swizzle", "deploy": "gh-pages -d build", From 16dbd3a5655e7fb0f1e46eed8635e13ff2444aec Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Sat, 24 May 2025 12:27:26 -0400 Subject: [PATCH 04/13] feat: Added gt processing script to prompt and create env file from gt specs --- process_gt.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 process_gt.sh diff --git a/process_gt.sh b/process_gt.sh new file mode 100755 index 000000000..bf827faad --- /dev/null +++ b/process_gt.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Prompts environment variables as per ground truth file +# Exports environment variables to environment file + +# Define the file which needs to be read as ground truth +gt_file=$1 +env_file=$2 + +declare -A env_vars + +prompt_for_env_var() { + local var_name=$1 + echo "$var_name: " + read -r value + env_vars[$var_name]=$value +} + +# Read env vars from gt file +while IFS=read -r line; do + # Skip preprocessing, input is assumed to be in the correct format + variable_name=$line + + # Check if variable name has not been asked for before (avoid duplicates) + if [[ ! ${env_vars[$variable_name]} ]]; then + prompt_for_env_var "$variable_name" + fi + + # Uncomment if implementing custom `gt` file format validation + # else + # echo "Error: Invalid format. Expected ..., found '$line'". Skipping..." + #fi +done < "$gt_file" + +# Export environment variables to destination file +for key in "${!env_vars[@]}"; do + echo -e "$key=${env_vars[$key]}\n" >> "$env_file" +done + +echo -e "\tEnvironment variables exported to $env_file\n" +echo -e "---------------------------------------------\n" \ No newline at end of file From 6e97203218fd3ec39e0bd40817c4e8f47f941818 Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Sat, 24 May 2025 15:34:46 -0400 Subject: [PATCH 05/13] feat: Variable validation against `.gt` file functional to spec --- validate_vars.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 validate_vars.sh diff --git a/validate_vars.sh b/validate_vars.sh new file mode 100755 index 000000000..ed4dd48f1 --- /dev/null +++ b/validate_vars.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Validates environment variables against ground truth file + +# Args +# 1: Ground truth file +# 2: Environment file to source +gt_file=$1 +env_file=$2 +is_invalid=false + +declare -A env_vars +source "$env_file" + +validate_var() { + local var_name=$1 + # Return non-zero value if variable name is invalid + if [[ -z "$var_name" ]] || [[ -z "${!var_name}" ]]; then + return 1 + fi + return 0; +} + +# Read env vars from gt file +while IFS= read -r line; do + # Skip preprocessing, input is assumed to be in the correct format + variable_name=$line + + # Check if variable name has not been checked before (avoid duplicates) + if [[ ! ${env_vars[$variable_name]} ]]; then + if validate_var "$variable_name"; then + echo -e "+ $variable_name configured!" + else + echo -e "- $variable_name is not configured!" + is_invalid=true + fi + + fi +done < "$gt_file" + +# Conditionally set exit status +if [ "$is_invalid" = true ]; then + exit 0 +else + echo -e "\nEnvironment variables validated against $gt_file" + echo -e "----------------------------------------------\n"; + exit 2 +fi \ No newline at end of file From f34a8ab195ddccf928a0df375c30564667de6967 Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Sat, 24 May 2025 18:28:09 -0400 Subject: [PATCH 06/13] feat: Bash based environment configuration implemented --- configure_dev.sh | 39 ++++++++++++++++++++++++++++++++++++ process_gt.sh | 52 ++++++++++++++++++++++++++++-------------------- validate_vars.sh | 6 +++--- 3 files changed, 72 insertions(+), 25 deletions(-) create mode 100755 configure_dev.sh diff --git a/configure_dev.sh b/configure_dev.sh new file mode 100755 index 000000000..2cba8fb14 --- /dev/null +++ b/configure_dev.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# Prompt and read +clear +echo "Select an environment type:" +echo "--------------------------------" +echo "1: Local (default)" +echo "2: Dev" + +read -p "Choose a number (1 or 2): " choice + +case $choice in + 1) ENV="local" ;; + 2) ENV="dev" ;; + *) echo "Invalid choice. Exiting..." + exit 1;; +esac +echo "----------------------------------------------" +# Determine file type based on choice +env_file=".env.$ENV" # Determines file name to source/create +gt_file=".gt/$ENV.gt" # Determines the ground truth (gt) file to validate against + +declare -A env_vars + +# Check if the file exists +if [ -f "$env_file" ]; then + # If the file exists, source it and validate the contents + . validate_vars.sh "$gt_file" "$env_file" + if ![ $? -eq 0 ]; then + echo -e "Invalid configuration, please check if variables are configured as per $gt_file!\n" + exit 1 + fi + +else + # If the file does not exist, prompt for and create it + . process_gt.sh "$gt_file" "$env_file" +fi +export +echo -e "Environment variables set successfully!\n" diff --git a/process_gt.sh b/process_gt.sh index bf827faad..bad735d14 100755 --- a/process_gt.sh +++ b/process_gt.sh @@ -3,39 +3,47 @@ # Prompts environment variables as per ground truth file # Exports environment variables to environment file -# Define the file which needs to be read as ground truth +# WARNING: Flushes env file before writing! + +# Args: +# 1: Ground truth file +# 2: Environment file to source gt_file=$1 env_file=$2 declare -A env_vars -prompt_for_env_var() { - local var_name=$1 - echo "$var_name: " - read -r value - env_vars[$var_name]=$value +read_and_prompt() { + local line + # Read env vars from gt file + while IFS= read -r line; do + # Skip preprocessing, input is assumed to be in the correct format + local var_name="$line" + + # Check if variable name has not been asked for before (avoid duplicates) + if [[ ! ${env_vars[$var_name]} ]]; then + echo -n "$var_name: " + read value < /dev/tty + env_vars[$var_name]=$value + fi + + # Uncomment if implementing custom `gt` file format validation + # else + # echo "Error: Invalid format. Expected ..., found '$line'". Skipping..." + #fi + done } -# Read env vars from gt file -while IFS=read -r line; do - # Skip preprocessing, input is assumed to be in the correct format - variable_name=$line - - # Check if variable name has not been asked for before (avoid duplicates) - if [[ ! ${env_vars[$variable_name]} ]]; then - prompt_for_env_var "$variable_name" - fi +# Read and prompt for env vars +read_and_prompt < "$gt_file" - # Uncomment if implementing custom `gt` file format validation - # else - # echo "Error: Invalid format. Expected ..., found '$line'". Skipping..." - #fi -done < "$gt_file" +# Flush file +:> "$env_file" # Export environment variables to destination file for key in "${!env_vars[@]}"; do - echo -e "$key=${env_vars[$key]}\n" >> "$env_file" + echo "$key=\"${env_vars[$key]}\"" >> "$env_file" done -echo -e "\tEnvironment variables exported to $env_file\n" +echo -e "\nEnvironment variables exported to $env_file" echo -e "---------------------------------------------\n" \ No newline at end of file diff --git a/validate_vars.sh b/validate_vars.sh index ed4dd48f1..a44adde2d 100755 --- a/validate_vars.sh +++ b/validate_vars.sh @@ -40,9 +40,9 @@ done < "$gt_file" # Conditionally set exit status if [ "$is_invalid" = true ]; then - exit 0 + exit 3 else - echo -e "\nEnvironment variables validated against $gt_file" + echo -e "Environment variables validated against $gt_file" echo -e "----------------------------------------------\n"; - exit 2 + exit 0 fi \ No newline at end of file From 22e336eeddf064f0fbbb1173b37e66d2c800bdf8 Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Sat, 24 May 2025 18:28:28 -0400 Subject: [PATCH 07/13] chore: Updates to gt files --- .gt/dev.gt | 2 +- .gt/local.gt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gt/dev.gt b/.gt/dev.gt index 6a9740490..43eb978e1 100644 --- a/.gt/dev.gt +++ b/.gt/dev.gt @@ -8,4 +8,4 @@ OAUTH_REDIRECT_SIGN_RESPONSE_TYPE AUTHORITY CLIENT_ID REDIRECT_URI -SCOPE \ No newline at end of file +SCOPE diff --git a/.gt/local.gt b/.gt/local.gt index 95497050a..fffbb8241 100644 --- a/.gt/local.gt +++ b/.gt/local.gt @@ -1 +1 @@ -ENV \ No newline at end of file +ENV From 93b6f8146299fe75d137bb30cf3cd55e2f0e6e5f Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Sat, 24 May 2025 18:40:36 -0400 Subject: [PATCH 08/13] chore: Reconfigured file structure of dev configuration scripts --- env.template | 34 ------------------- {.gt => env_config/.gt}/dev.gt | 0 {.gt => env_config/.gt}/local.gt | 0 .../configure_dev.sh | 6 +--- process_gt.sh => env_config/process_gt.sh | 0 .../validate_vars.sh | 4 +-- package.json | 2 +- 7 files changed, 4 insertions(+), 42 deletions(-) delete mode 100644 env.template rename {.gt => env_config/.gt}/dev.gt (100%) rename {.gt => env_config/.gt}/local.gt (100%) rename configure_dev.sh => env_config/configure_dev.sh (85%) rename process_gt.sh => env_config/process_gt.sh (100%) rename validate_vars.sh => env_config/validate_vars.sh (87%) diff --git a/env.template b/env.template deleted file mode 100644 index c59d71845..000000000 --- a/env.template +++ /dev/null @@ -1,34 +0,0 @@ -## .env.local - -## i.e: localhost, dev, prod -ENV="localhost" - -## AWS Cognito Region -REGION="us-east-1" - -## AWS Cognito User Pool ID -USER_POOL_ID="" - -## AWS Cognito User Pool App Client ID -USER_POOL_WEB_CLIENT_ID="" - -## AWS Cognito Domain -OAUTH_DOMAIN="" - -## Cognito redirect url after a successful sign-out -OAUTH_REDIRECT_SIGN_OUT="https://localhost:3000,https://umlcloudcomputing.org" - -## Cognito setup, no need to change it! -OAUTH_REDIRECT_SIGN_RESPONSE_TYPE="code" - -## OIDC Authority -AUTHORITY="" - -## Client ID -CLIENT_ID="" - -## Redirect URI -REDIRECT_URI="" - -## Scope -SCOPE="email openid phone" \ No newline at end of file diff --git a/.gt/dev.gt b/env_config/.gt/dev.gt similarity index 100% rename from .gt/dev.gt rename to env_config/.gt/dev.gt diff --git a/.gt/local.gt b/env_config/.gt/local.gt similarity index 100% rename from .gt/local.gt rename to env_config/.gt/local.gt diff --git a/configure_dev.sh b/env_config/configure_dev.sh similarity index 85% rename from configure_dev.sh rename to env_config/configure_dev.sh index 2cba8fb14..314cc8458 100755 --- a/configure_dev.sh +++ b/env_config/configure_dev.sh @@ -26,14 +26,10 @@ declare -A env_vars if [ -f "$env_file" ]; then # If the file exists, source it and validate the contents . validate_vars.sh "$gt_file" "$env_file" - if ![ $? -eq 0 ]; then - echo -e "Invalid configuration, please check if variables are configured as per $gt_file!\n" - exit 1 - fi else # If the file does not exist, prompt for and create it . process_gt.sh "$gt_file" "$env_file" fi -export +export ENV=$ENV echo -e "Environment variables set successfully!\n" diff --git a/process_gt.sh b/env_config/process_gt.sh similarity index 100% rename from process_gt.sh rename to env_config/process_gt.sh diff --git a/validate_vars.sh b/env_config/validate_vars.sh similarity index 87% rename from validate_vars.sh rename to env_config/validate_vars.sh index a44adde2d..7395a5014 100755 --- a/validate_vars.sh +++ b/env_config/validate_vars.sh @@ -40,9 +40,9 @@ done < "$gt_file" # Conditionally set exit status if [ "$is_invalid" = true ]; then + echo -e "Invalid configuration, please check if variables are configured as per $gt_file!\n" exit 3 else echo -e "Environment variables validated against $gt_file" - echo -e "----------------------------------------------\n"; - exit 0 + echo -e "----------------------------------------------"; fi \ No newline at end of file diff --git a/package.json b/package.json index 11b90ffab..8029447cb 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "scripts": { "import": "node stream.js && rm -rf temp_resources && rm -rf temp_activity && rm -rf temp_projects", "docusaurus": "docusaurus", - "start": "./configure_dev && docusaurus start", + "start": "./env_config/configure_dev.sh && docusaurus start", "build": "docusaurus build && cp CNAME build/", "swizzle": "docusaurus swizzle", "deploy": "gh-pages -d build", From e7f29bedfd3054cf4bd4b7102891ee76d23ccb3c Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Mon, 2 Jun 2025 09:16:48 -0400 Subject: [PATCH 09/13] chore: Remove Immersion iFrame until it gets developed further --- src/pages/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/index.js b/src/pages/index.js index 1b3e1d73b..3b93f4aac 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -179,12 +179,12 @@ const LandingPageImmersion = () => (
Dashboard GitHub
-
+ {/*
-
+
*/} ); From ad33d55f0f4daa53888e0af6eb7823d4a559bbb9 Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Fri, 6 Jun 2025 14:00:33 -0400 Subject: [PATCH 10/13] 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 --- docusaurus.config.js | 20 +++++++------ env_config/configure_dev.sh | 47 ++++++++++++++++++------------- env_config/validate_vars.sh | 2 +- package-lock.json | 6 ++-- package.json | 3 +- src/components/Auth/index.js | 19 +++++++------ src/config/cognito-auth-config.js | 14 ++++----- src/config/cognito-configure.js | 29 ++++++++++--------- src/pages/index.js | 4 +-- src/utils/constants.js | 14 +++++++++ src/utils/env.js | 35 ----------------------- src/utils/utils.js | 34 ++++++++++++++++++++-- 12 files changed, 123 insertions(+), 104 deletions(-) delete mode 100644 src/utils/env.js diff --git a/docusaurus.config.js b/docusaurus.config.js index f2238e80b..0d54ce928 100644 --- a/docusaurus.config.js +++ b/docusaurus.config.js @@ -9,6 +9,7 @@ import remarkMath from 'remark-math'; import rehypeKatex from 'rehype-katex'; const process = require('node:process'); +const env_type = process.env.ENV; /** @type {import('@docusaurus/types').Config} */ const config = { @@ -85,7 +86,8 @@ const config = { [ "docusaurus-plugin-dotenv", { - path: "./.env.local", + default: "./.env.local", + path: "./.env.dev", systemvars: true, }, // '@docusaurus/plugin-content-docs', @@ -118,14 +120,14 @@ const config = { disableSwitch: false, respectPrefersColorScheme: true, }, - announcementBar: { - id: 'announcement-bar', - content: - '☀️ Summer Meetings start Virtually on May 17th! ✍️', - backgroundColor: '#48a0ff', - textColor: '#fff', - isCloseable: false - }, + // announcementBar: { + // id: 'announcement-bar', + // content: + // '☀️ Summer Meetings start Virtually on May 17th! ✍️', + // backgroundColor: '#48a0ff', + // textColor: '#fff', + // isCloseable: false + // }, navbar: { title: 'UML Cloud Computing Club', logo: { diff --git a/env_config/configure_dev.sh b/env_config/configure_dev.sh index 314cc8458..ce4a50913 100755 --- a/env_config/configure_dev.sh +++ b/env_config/configure_dev.sh @@ -2,34 +2,41 @@ # Prompt and read clear -echo "Select an environment type:" -echo "--------------------------------" -echo "1: Local (default)" -echo "2: Dev" - -read -p "Choose a number (1 or 2): " choice - -case $choice in - 1) ENV="local" ;; - 2) ENV="dev" ;; - *) echo "Invalid choice. Exiting..." - exit 1;; -esac -echo "----------------------------------------------" +# echo "Select an environment type:" +# echo "--------------------------------" +# echo "1: Local (default)" +# echo "2: Dev" + +# read -p "Choose a number (1 or 2): " choice + +# case $choice in +# 1) ENV="local" ;; +# 2) ENV="dev" ;; +# *) echo "Invalid choice. Exiting..." +# exit 1;; +# esac +# echo "----------------------------------------------" + # Determine file type based on choice -env_file=".env.$ENV" # Determines file name to source/create -gt_file=".gt/$ENV.gt" # Determines the ground truth (gt) file to validate against + +# NEW: Changed to be exclusively for dev session with authentication +env_file=".env.dev" # Determines file name to source/create +gt_file="./env_config/.gt/dev.gt" # Determines the ground truth (gt) file to validate against declare -A env_vars # Check if the file exists if [ -f "$env_file" ]; then # If the file exists, source it and validate the contents - . validate_vars.sh "$gt_file" "$env_file" + . ./env_config/validate_vars.sh "$gt_file" "$env_file" else # If the file does not exist, prompt for and create it - . process_gt.sh "$gt_file" "$env_file" + . ./env_config/process_gt.sh "$gt_file" "$env_file" fi -export ENV=$ENV -echo -e "Environment variables set successfully!\n" + +set -a +source $env_file +export ENV + +echo -e "Environment variables set successfully!\n" diff --git a/env_config/validate_vars.sh b/env_config/validate_vars.sh index 7395a5014..54a02a6c1 100755 --- a/env_config/validate_vars.sh +++ b/env_config/validate_vars.sh @@ -10,7 +10,7 @@ env_file=$2 is_invalid=false declare -A env_vars -source "$env_file" +source $env_file validate_var() { local var_name=$1 diff --git a/package-lock.json b/package-lock.json index 2f53d1be3..ef34f857a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11162,9 +11162,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001690", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001690.tgz", - "integrity": "sha512-5ExiE3qQN6oF8Clf8ifIDcMRCRE/dMGcETG/XGMD8/XiXm6HXQgQTh1yZYLXXpSOsEUlJm1Xr7kGULZTuGtP/w==", + "version": "1.0.30001721", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001721.tgz", + "integrity": "sha512-cOuvmUVtKrtEaoKiO0rSc29jcjwMwX5tOHDy4MgVFEWiUXj4uBMJkwI8MDySkgXidpMiHUcviogAvFi4pA2hDQ==", "funding": [ { "type": "opencollective", diff --git a/package.json b/package.json index 8029447cb..00438c5de 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,13 @@ "scripts": { "import": "node stream.js && rm -rf temp_resources && rm -rf temp_activity && rm -rf temp_projects", "docusaurus": "docusaurus", + "local": "export NODE_ENV=test && docusaurus start", "start": "./env_config/configure_dev.sh && docusaurus start", "build": "docusaurus build && cp CNAME build/", "swizzle": "docusaurus swizzle", "deploy": "gh-pages -d build", "clear": "docusaurus clear", - "serve": "docusaurus serve", + "serve": "export NODE_ENV=prod docusaurus serve", "write-translations": "docusaurus write-translations", "write-heading-ids": "docusaurus write-heading-ids", "predeploy": "npm run build" diff --git a/src/components/Auth/index.js b/src/components/Auth/index.js index ad29a4488..b3234c2f5 100644 --- a/src/components/Auth/index.js +++ b/src/components/Auth/index.js @@ -1,11 +1,10 @@ // src/components/Auth/index.js import React from "react"; - import { useAuth } from "react-oidc-context"; import { Redirect, useLocation } from "@docusaurus/router"; import ReactLoading from 'react-loading'; -import { isEnvLocalLoaded } from '../../utils/env'; +import { envType, getEnvVar } from "../../utils/utils.js"; import { // AUTHENTICATED, @@ -22,17 +21,18 @@ export function AuthCheck({ children }) { const auth = useAuth(); // If .env.local is missing, skip all auth logic and just render children - if (!isEnvLocalLoaded()) { - return <>{children}; + if (envType() === 'local') { + // If the path is protected, redirect to sign in + if (PROTECTED_PATHS.filter((x) => from.includes(x)).length) + return ; + return children; } - // Defensive: Only split if OAUTH_REDIRECT_SIGN_OUT is defined - const signOutUris = process.env.OAUTH_REDIRECT_SIGN_OUT ? process.env.OAUTH_REDIRECT_SIGN_OUT.split(",") : ["", ""]; - const [local_logout_uri, prod_logout_uri] = signOutUris; + const [local_logout_uri, prod_logout_uri] = process.env.OAUTH_REDIRECT_SIGN_OUT.split(","); const signOutRedirect = () => { const clientId = process.env.CLIENT_ID; - const logoutUri = process.env.ENV === "localhost" + const logoutUri = process.env.ENV === "local" ? local_logout_uri : prod_logout_uri; const cognitoDomain = process.env.OAUTH_DOMAIN; @@ -74,4 +74,5 @@ export function AuthCheck({ children }) { else if (from === LOGIN_PATH) auth.signinRedirect(); return children; } -} \ No newline at end of file +} + diff --git a/src/config/cognito-auth-config.js b/src/config/cognito-auth-config.js index 1dfacb64c..b5947c9c8 100644 --- a/src/config/cognito-auth-config.js +++ b/src/config/cognito-auth-config.js @@ -1,15 +1,13 @@ // src/config/cognito-auth-config.js -import { isEnvLocalLoaded, getEnvVar } from '../utils/env'; +import { envType, getEnvVar } from '../utils/utils'; const cognitoAuthConfig = { - authority: getEnvVar('AUTHORITY'), - client_id: getEnvVar('CLIENT_ID'), - redirect_uri: getEnvVar('REDIRECT_URI'), - response_type: getEnvVar('OAUTH_REDIRECT_SIGN_RESPONSE_TYPE', 'code'), - scope: getEnvVar('SCOPE', 'email openid phone'), - // Add a flag for local mode - isLocalDev: !isEnvLocalLoaded(), + authority: process.env.AUTHORITY, + client_id: process.env.CLIENT_ID, + redirect_uri: process.env.REDIRECT_URI, + response_type: process.env.OAUTH_REDIRECT_SIGN_RESPONSE_TYPE, + scope: process.env.SCOPE }; export default cognitoAuthConfig; diff --git a/src/config/cognito-configure.js b/src/config/cognito-configure.js index 119384ed2..a8bff8eae 100644 --- a/src/config/cognito-configure.js +++ b/src/config/cognito-configure.js @@ -1,20 +1,14 @@ // src/config/cognito-config.js import cognitoAuthConfig from "./cognito-auth-config"; -import { isEnvLocalLoaded } from '../utils/env'; +import { envType } from '../utils/utils'; export function configure() { - // If .env.local is missing, fallback to local dev mode and skip config - if (!isEnvLocalLoaded()) { - return { - ...cognitoAuthConfig, - // Optionally, set all sensitive/remote fields to undefined - authority: undefined, - client_id: undefined, - redirect_uri: undefined, - isLocalDev: true, - }; + if (envType() === 'local') { + console.log("Local mode detected, skipping authentication config"); + return {}; } + // Assuming you have two redirect URIs, and the first is for localhost and // second is for production const [localRedirectURI, prodRedirectURI] = @@ -23,10 +17,19 @@ export function configure() { const updatedCognitoConfig = { ...cognitoAuthConfig, redirect_uri: - process.env.ENV === "localhost" + envType() === "dev" ? localRedirectURI : prodRedirectURI }; - return updatedCognitoConfig; + + if (envType() === 'dev') { + console.log("Dev mode detected, configuring for local development with authentication enabled"); + return updatedCognitoConfig; + } + + // Running in production + else { + return updatedCognitoConfig; + } } \ No newline at end of file diff --git a/src/pages/index.js b/src/pages/index.js index 3b93f4aac..7da183cb7 100644 --- a/src/pages/index.js +++ b/src/pages/index.js @@ -158,12 +158,12 @@ const LandingPageUniBotiFrame = () => (
GitHub
-
+ {/*
-
+
*/} ); diff --git a/src/utils/constants.js b/src/utils/constants.js index 7d1788860..419279b89 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -8,5 +8,19 @@ export const BASE = "/"; export const LOGOUT_BUTTON = "Logout"; export const LOGIN_BUTTON = "Login"; +export const REQUIRED_ENV_VARS = [ + 'AUTHORITY', + 'CLIENT_ID', + 'REDIRECT_URI', + 'OAUTH_REDIRECT_SIGN_RESPONSE_TYPE', + 'SCOPE', + 'REGION', + 'USER_POOL_ID', + 'USER_POOL_WEB_CLIENT_ID', + 'OAUTH_DOMAIN', + 'OAUTH_REDIRECT_SIGN_OUT', + 'ENV', +]; + // Add the protected paths here export const PROTECTED_PATHS = ["docs/resources", "docs/activities", "/accountSettings"]; \ No newline at end of file diff --git a/src/utils/env.js b/src/utils/env.js deleted file mode 100644 index 8c0d15292..000000000 --- a/src/utils/env.js +++ /dev/null @@ -1,35 +0,0 @@ -// src/utils/env.js - -// This utility checks for required env vars and provides fallbacks for local dev - -const REQUIRED_ENV_VARS = [ - 'AUTHORITY', - 'CLIENT_ID', - 'REDIRECT_URI', - 'OAUTH_REDIRECT_SIGN_RESPONSE_TYPE', - 'SCOPE', - 'REGION', - 'USER_POOL_ID', - 'USER_POOL_WEB_CLIENT_ID', - 'OAUTH_DOMAIN', - 'OAUTH_REDIRECT_SIGN_OUT', - 'ENV', -]; - -function isEnvLocalLoaded() { - // If any required env var is missing, assume .env.local is not loaded - return REQUIRED_ENV_VARS.every((key) => typeof process.env[key] === 'string' && process.env[key] !== ''); -} - -function getEnvVar(key, fallback = undefined) { - if (typeof process.env[key] === 'string' && process.env[key] !== '') { - return process.env[key]; - } - // Fallback for local dev - if (fallback !== undefined) return fallback; - // Some defaults for local dev - if (key === 'ENV') return 'localhost'; - return undefined; -} - -export { isEnvLocalLoaded, getEnvVar }; diff --git a/src/utils/utils.js b/src/utils/utils.js index fc357c728..174d09b7d 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -10,11 +10,39 @@ import { LOGIN_PATH, LOGOUT_BUTTON, LOGOUT_PATH, + REQUIRED_ENV_VARS, } from "./constants"; -import { isEnvLocalLoaded } from './env'; + +export function envType() { + // Local, authentication disabled + if (process.env.NODE_ENV === "test") { + return 'local'; + } + + // Dev, authentication enabled, locally developed + else if (process.env.NODE_ENV === "development") { + return 'dev'; + } + + // Prod, authentication enabled, deployed on server + else { + if (! REQUIRED_ENV_VARS.every((key) => (typeof process.env[key] === 'string') && (process.env[key] !== '')) && process.env.NODE_ENV === "production") { + throw new Error('FATAL: Missing required environment variables for AUTHENTICATION\nENV: ' + process.env.ENV); + } else { + return 'prod'; + } + } + // If any required env var is missing, assume .env.* is not loaded +} + +export function getEnvVar(key) { + if (typeof process.env[key] === 'string' && process.env[key] !== '') { + return process.env[key]; + } +} export function useNavbarItemsMobile() { - if (!isEnvLocalLoaded()) { + if (envType() === 'local') { // If .env.local is missing, do not render auth-related navbar items return useThemeConfig().navbar.items; } @@ -65,7 +93,7 @@ export function useNavbarItemsMobile() { } export function useNavbarItemsDesktop() { - if (!isEnvLocalLoaded()) { + if (envType() === 'local') { // If .env.local is missing, do not render auth-related navbar items return useThemeConfig().navbar.items; } From 88d28cbcfdabcf1782201e8ad9c849ff06ac834b Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Fri, 6 Jun 2025 14:11:10 -0400 Subject: [PATCH 11/13] chore: Updated readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 73ff9858e..cef503285 100644 --- a/README.md +++ b/README.md @@ -217,10 +217,10 @@ Here are the steps: > 2. `sudo apt install mkcert` > 3. Confirm your installation: `mkcert --version` -Similarly, some local environment variables must be specified in order to ensure functionality: -1. Create a copy of the file called `env.template` -2. Within this file populate the provided variables using information available on the AWS Console for Cognito. -3. Once populated with the correct information, authentication should work correctly +Similarly, some local environment variables must be specified in order to ensure functionality with authenication: +- Use `npm run local` to develop locally **without** authentication enabled +- Use `npm start` to develop locally **with** authentication + - If environment variables are not configured, you will be prompted to provide them ## 🎉Acknowledgements 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. From 6b14392301455535c9953822072267fb71feca41 Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Fri, 6 Jun 2025 14:12:42 -0400 Subject: [PATCH 12/13] fix: Attempted fix for production CI/CD pipeline workflow --- src/utils/utils.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 174d09b7d..4343cf0e8 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -26,8 +26,8 @@ export function envType() { // Prod, authentication enabled, deployed on server else { - if (! REQUIRED_ENV_VARS.every((key) => (typeof process.env[key] === 'string') && (process.env[key] !== '')) && process.env.NODE_ENV === "production") { - throw new Error('FATAL: Missing required environment variables for AUTHENTICATION\nENV: ' + process.env.ENV); + if (! REQUIRED_ENV_VARS.every((key) => (typeof process.env[key] === 'string') && (process.env[key] !== ''))) { + throw new Error('FATAL: Missing required environment variables for AUTHENTICATION\nENV: ' + process.env.ENV) } else { return 'prod'; } From d607e26b360708c30269a56aa500c87cad44f728 Mon Sep 17 00:00:00 2001 From: Gurpranked Date: Fri, 6 Jun 2025 14:18:04 -0400 Subject: [PATCH 13/13] fix: New attempted fix for CI/CD --- src/utils/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index 4343cf0e8..69f932723 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -26,7 +26,7 @@ export function envType() { // Prod, authentication enabled, deployed on server else { - if (! REQUIRED_ENV_VARS.every((key) => (typeof process.env[key] === 'string') && (process.env[key] !== ''))) { + if (REQUIRED_ENV_VARS.every((key) => (typeof process.env[key] === 'string') && (process.env[key] !== ''))) { throw new Error('FATAL: Missing required environment variables for AUTHENTICATION\nENV: ' + process.env.ENV) } else { return 'prod';