Skip to content

Commit

Permalink
Create page for Admin Posting
Browse files Browse the repository at this point in the history
  • Loading branch information
MatoPlus committed Jan 23, 2022
1 parent e5de3e9 commit f5118e4
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import SampleContextDispatcherContext from "./contexts/SampleContextDispatcherCo
import EditTeamInfoPage from "./components/pages/EditTeamPage";
import HooksDemo from "./components/pages/HooksDemo";
import VolunteerPostingsPage from "./components/pages/volunteer/posting/VolunteerPostingsPage";
import CreatePostingShiftsPage from "./components/pages/admin/posting/CreatePostingShiftsPage";

import customTheme from "./theme";
import { AuthenticatedUser } from "./types/AuthTypes";
Expand Down Expand Up @@ -109,6 +110,11 @@ const App = (): React.ReactElement => {
path={Routes.VOLUNTEER_POSTINGS_PAGE}
component={VolunteerPostingsPage}
/>
<PrivateRoute
exact
path={Routes.ADMIN_POSTING_CREATE_SHIFTS_PAGE}
component={CreatePostingShiftsPage}
/>
<Route exact path="*" component={NotFound} />
</Switch>
</Router>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

const CreatePostingShiftsPage = (): React.ReactElement => {
return <div />;
};

export default CreatePostingShiftsPage;
2 changes: 2 additions & 0 deletions frontend/src/constants/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ export const UPDATE_ENTITY_PAGE = "/entity/update";
export const HOOKS_PAGE = "/hooks";

export const VOLUNTEER_POSTINGS_PAGE = "/volunteer/postings";

export const ADMIN_POSTING_CREATE_SHIFTS_PAGE = "/admin/posting/create/shifts";
21 changes: 21 additions & 0 deletions update_secrets/hooks/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh
# update secret files if git pull on master resulted in new changes being merged locally

branch=`git symbolic-ref HEAD`
root_dir=`git rev-parse --show-toplevel`
# must replace with actual vault_path and default_branch, can run setup.sh
vault_path=""
default_branch=""

if [ $branch = "refs/heads/${default_branch}" ]; then
if [ -f "${root_dir}/update_secret_files.py" ]; then
vault kv get -format=json $vault_path | python "${root_dir}/update_secret_files.py"
if [ $? -eq 0 ]; then
echo "Successfully pulled secrets from Vault"
else
echo "An error occurred while pulling secrets from Vault"
fi
else
echo "To automatically update secrets after git pull on default branch, place update_secret_files.py in repo root directory"
fi
fi
2 changes: 2 additions & 0 deletions update_secrets/secret.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SECRET_KEY_FROM_VAULT_1=relative/path/to/secret/file1.env
SECRET_KEY_FROM_VAULT_2=relative/path/to/secret/file2.env
14 changes: 14 additions & 0 deletions update_secrets/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

vault_path_replacement_str="s|^vault_path=.*|vault_path=\"$1\"|g"
default_branch_replacement_str="s|^default_branch=.*|default_branch=\"$2\"|g"

# MacOS
if [[ $OSTYPE =~ darwin.* ]]; then
sed -i "" -e $vault_path_replacement_str ./hooks/post-merge
sed -i "" -e $default_branch_replacement_str ./hooks/post-merge
else
sed -i $vault_path_replacement_str ./hooks/post-merge
sed -i $default_branch_replacement_str ./hooks/post-merge
fi
cp ./hooks/post-merge ./.git/hooks/post-merge
56 changes: 56 additions & 0 deletions update_secrets/update_secret_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sys
import json

# Open secret.config file
configFileNotFound = False
try:
configFile = open('secret.config')
except Exception as e:
print("File secret.config could not be opened in current directory.")
print(e)
configFileNotFound = True
# Script will exit after checking if the Vault request is valid

# Decode json result
try:
rawInput = ''.join(sys.stdin.readlines())
decodedJson = json.loads(rawInput)
except Exception as e:
print("Unable to retrieve secrets from Vault and obtain valid json result.")
print("Please ensure you are authenticated and have supplied the correct path argument.")
exit()

# Extract the data field containting the secrets
if "data" in decodedJson and "data" in decodedJson["data"]:
data = decodedJson["data"]["data"]
else:
print("Unable to access the field data:{data:{}} from result which should contain the secrets.")
print("Please ensure you are authenticated and have supplied the correct path argument.")
exit()

# Even if the config file is not found, it is useful to still indicate if the Vault request has any problems before exiting
if configFileNotFound:
exit()

# Read all the secret file locations from secret.config
locations = {}
for line in configFile:
key, val = line.rstrip().partition('=')[::2]
if key in locations:
print("Key <{keyName}> appeared more than once on configuration file. Ignoring second instance of the key.".format(keyName=key))
else:
locations[key] = val
configFile.close()

# Write values to the secret file corresponding to their keys
for key in data:
if key in locations:
try:
f = open(locations[key], 'w')
f.write(data[key])
f.close()
except Exception as e:
print("Could not write the values for key <{keyName}> to location <{locName}>".format(keyName=key, locName=locations[key]))
print(e)
else:
print("File location for key <{keyName}> was not found.".format(keyName=key))
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


0 comments on commit f5118e4

Please sign in to comment.