Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion docs/schedule/2024Fall/2024Fall.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
:::


Expand Down
20 changes: 11 additions & 9 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -85,7 +86,8 @@ const config = {
[
"docusaurus-plugin-dotenv",
{
path: "./.env.local",
default: "./.env.local",
path: "./.env.dev",
systemvars: true,
},
// '@docusaurus/plugin-content-docs',
Expand Down Expand Up @@ -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: {
Expand Down
34 changes: 0 additions & 34 deletions env.template

This file was deleted.

11 changes: 11 additions & 0 deletions env_config/.gt/dev.gt
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions env_config/.gt/local.gt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ENV
42 changes: 42 additions & 0 deletions env_config/configure_dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/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

# 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
. ./env_config/validate_vars.sh "$gt_file" "$env_file"

else
# If the file does not exist, prompt for and create it
. ./env_config/process_gt.sh "$gt_file" "$env_file"
fi

set -a
source $env_file
export ENV

echo -e "Environment variables set successfully!\n"
49 changes: 49 additions & 0 deletions env_config/process_gt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Prompts environment variables as per ground truth file
# Exports environment variables to environment file

# 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

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 and prompt for env vars
read_and_prompt < "$gt_file"

# Flush file
:> "$env_file"

# Export environment variables to destination file
for key in "${!env_vars[@]}"; do
echo "$key=\"${env_vars[$key]}\"" >> "$env_file"
done

echo -e "\nEnvironment variables exported to $env_file"
echo -e "---------------------------------------------\n"
48 changes: 48 additions & 0 deletions env_config/validate_vars.sh
Original file line number Diff line number Diff line change
@@ -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
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 "----------------------------------------------";
fi
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
"scripts": {
"import": "node stream.js && rm -rf temp_resources && rm -rf temp_activity && rm -rf temp_projects",
"docusaurus": "docusaurus",
"start": "docusaurus start",
"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"
Expand Down
17 changes: 13 additions & 4 deletions src/components/Auth/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +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 { envType, getEnvVar } from "../../utils/utils.js";

import {
// AUTHENTICATED,
Expand All @@ -20,11 +20,19 @@ export function AuthCheck({ children }) {
let from = location.pathname;
const auth = useAuth();

// If .env.local is missing, skip all auth logic and just render children
if (envType() === 'local') {
// If the path is protected, redirect to sign in
if (PROTECTED_PATHS.filter((x) => from.includes(x)).length)
return <Redirect to={BASE} from={from}/>;
return children;
}

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;
Expand Down Expand Up @@ -66,4 +74,5 @@ export function AuthCheck({ children }) {
else if (from === LOGIN_PATH) auth.signinRedirect();
return children;
}
}
}

4 changes: 3 additions & 1 deletion src/config/cognito-auth-config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// src/config/cognito-auth-config.js

import { envType, getEnvVar } from '../utils/utils';

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,
scope: process.env.SCOPE
};

export default cognitoAuthConfig;
Expand Down
Loading
Loading