Skip to content

Commit e1c790b

Browse files
committed
Merge branch 'master' into deploy-rewrite
2 parents 8fa8d13 + fd6ffa9 commit e1c790b

32 files changed

+9440
-5805
lines changed

.eslintrc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"overrides": [
2929
{
3030
"files": [
31-
"tests/unit/*.spec.js"
31+
"tests/unit/**/*.spec.js"
3232
],
3333
"env": {
3434
"jest": true
@@ -42,7 +42,8 @@
4242
"Vuetify": "readonly",
4343
"VueRouter": "readonly",
4444
"VueCookies": "readonly",
45-
"BrowserSupportPlugin": "readonly"
45+
"BrowserSupportPlugin": "readonly",
46+
"regeneratorRuntime": "readonly"
4647
}
4748
}
4849
]

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,6 @@ public
108108

109109
# TernJS port file
110110
.tern-port
111+
112+
# Credentials for the MIT People API
113+
credentials.ini

build/webpack.config.dev.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict'
22
const webpack = require('webpack')
33
const { VueLoaderPlugin } = require('vue-loader')
4+
const { resolve } = require('path')
45
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
56
const HtmlWebpackPlugin = require('html-webpack-plugin')
7+
const cgi = require('cgi')
68

79
module.exports = (env) => {
810
return {
@@ -15,6 +17,13 @@ module.exports = (env) => {
1517
hot: true,
1618
watchOptions: {
1719
poll: true
20+
},
21+
before: function (app, server, compiler) {
22+
// Before handing all other dev server requests, check if the route is to the People API middleware and pass
23+
// it to the CGI handler.
24+
app.get('/cgi-bin/people.py', function (req, res) {
25+
cgi(resolve(__dirname, '..', 'cgi-bin', 'people.py'))(req, res)
26+
})
1827
}
1928
},
2029
module: {

cgi-bin/people.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/python3
2+
from cgi import FieldStorage
3+
from configparser import ConfigParser
4+
from json import dumps, loads
5+
from os import path
6+
from requests import get
7+
8+
args = FieldStorage()
9+
10+
error = 'Status: 400 Bad Request\n'
11+
header = 'Content-Type: application/json\n\n'
12+
13+
if 'kerb' not in args:
14+
output = {"error": "kerb was not specified"}
15+
header = error + header
16+
else:
17+
c = ConfigParser()
18+
try:
19+
with open(path.join(path.dirname(path.realpath(__file__)), 'credentials.ini')) as fp:
20+
c.read_file(fp)
21+
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']})
22+
if response.status_code != 200:
23+
header = error + header
24+
output = {"error": "could not get user data"}
25+
else:
26+
data = loads(response.text)
27+
if data['item']['affiliations'][0]['type'] != "student":
28+
header = error + header
29+
output = {"error": "user is not a student"}
30+
else:
31+
year = data['item']['affiliations'][0]['classYear']
32+
if year == "G":
33+
header = error + header
34+
output = {"error": "user is a graduate student (currently unhandled)"}
35+
else:
36+
year = int(year)
37+
year = year - 1
38+
output = {"year": year}
39+
except Exception:
40+
header = error + header
41+
output = {"error": "could not read credentials"}
42+
43+
print(header)
44+
print(dumps(output))

deploy.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ if [ "$1" = "prod" ]; then
3434
else
3535
echo "Could not locate AFS, using SSH for deployment"
3636
# this is what happens without any fancy setup
37-
scp -r deploy/production/.htaccess dist/* $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/
37+
scp -r deploy/production/.htaccess dist/* cgi-bin/ $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/
3838
fi
3939
else
4040
echo "Cancelled"
@@ -54,7 +54,7 @@ elif [ "$1" = "dev" ]; then
5454
else
5555
echo "Could not locate AFS, using SSH for deployment"
5656
# this is what happens without any fancy setup
57-
scp -r deploy/development/.htaccess dist/* $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/dev/
57+
scp -r deploy/development/.htaccess dist/* cgi-bin/ $2@athena.dialup.mit.edu:/mit/courseroad/web_scripts/courseroad/dev/
5858
fi
5959
else
6060
echo "Invalid build location"

0 commit comments

Comments
 (0)