Skip to content

Commit

Permalink
Merge branch 'master' into deploy-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiashay committed Dec 29, 2020
2 parents 8fa8d13 + fd6ffa9 commit e1c790b
Show file tree
Hide file tree
Showing 32 changed files with 9,440 additions and 5,805 deletions.
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"overrides": [
{
"files": [
"tests/unit/*.spec.js"
"tests/unit/**/*.spec.js"
],
"env": {
"jest": true
Expand All @@ -42,7 +42,8 @@
"Vuetify": "readonly",
"VueRouter": "readonly",
"VueCookies": "readonly",
"BrowserSupportPlugin": "readonly"
"BrowserSupportPlugin": "readonly",
"regeneratorRuntime": "readonly"
}
}
]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,6 @@ public

# TernJS port file
.tern-port

# Credentials for the MIT People API
credentials.ini
9 changes: 9 additions & 0 deletions build/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict'
const webpack = require('webpack')
const { VueLoaderPlugin } = require('vue-loader')
const { resolve } = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const cgi = require('cgi')

module.exports = (env) => {
return {
Expand All @@ -15,6 +17,13 @@ module.exports = (env) => {
hot: true,
watchOptions: {
poll: true
},
before: function (app, server, compiler) {
// Before handing all other dev server requests, check if the route is to the People API middleware and pass
// it to the CGI handler.
app.get('/cgi-bin/people.py', function (req, res) {
cgi(resolve(__dirname, '..', 'cgi-bin', 'people.py'))(req, res)
})
}
},
module: {
Expand Down
44 changes: 44 additions & 0 deletions cgi-bin/people.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/python3
from cgi import FieldStorage
from configparser import ConfigParser
from json import dumps, loads
from os import path
from requests import get

args = FieldStorage()

error = 'Status: 400 Bad Request\n'
header = 'Content-Type: application/json\n\n'

if 'kerb' not in args:
output = {"error": "kerb was not specified"}
header = error + header
else:
c = ConfigParser()
try:
with open(path.join(path.dirname(path.realpath(__file__)), 'credentials.ini')) as fp:
c.read_file(fp)
response = get('https://mit-people-v3.cloudhub.io/people/v3/people/{0}'.format(args['kerb'].value), headers={'client_id': c['Credentials']['ID'], 'client_secret': c['Credentials']['Secret']})
if response.status_code != 200:
header = error + header
output = {"error": "could not get user data"}
else:
data = loads(response.text)
if data['item']['affiliations'][0]['type'] != "student":
header = error + header
output = {"error": "user is not a student"}
else:
year = data['item']['affiliations'][0]['classYear']
if year == "G":
header = error + header
output = {"error": "user is a graduate student (currently unhandled)"}
else:
year = int(year)
year = year - 1
output = {"year": year}
except Exception:
header = error + header
output = {"error": "could not read credentials"}

print(header)
print(dumps(output))
4 changes: 2 additions & 2 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if [ "$1" = "prod" ]; then
else
echo "Could not locate AFS, using SSH for deployment"
# this is what happens without any fancy setup
scp -r deploy/production/.htaccess dist/* $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/
scp -r deploy/production/.htaccess dist/* cgi-bin/ $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/
fi
else
echo "Cancelled"
Expand All @@ -54,7 +54,7 @@ elif [ "$1" = "dev" ]; then
else
echo "Could not locate AFS, using SSH for deployment"
# this is what happens without any fancy setup
scp -r deploy/development/.htaccess dist/* $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/dev/
scp -r deploy/development/.htaccess dist/* cgi-bin/ $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/dev/
fi
else
echo "Invalid build location"
Expand Down
Loading

0 comments on commit e1c790b

Please sign in to comment.