Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export Via Key Functionality #155

Merged
merged 10 commits into from
Sep 30, 2017
Merged

Export Via Key Functionality #155

merged 10 commits into from
Sep 30, 2017

Conversation

mjkaufer
Copy link
Contributor

To prepare for the integration between checkin and registration, I've added a configurable exportKey parameter and a route at /api/user/all/export/:exportKey. Since we don't have CAS hooked up right now, we need some alternate way to tell registration that checkin is allowed to fetch data from it. You can configure the key from the registration admin settings.

After this is merged, I'll add functionality in checkin to request this endpoint with a configurable key, so we can programmatically import the zip file into checkin.

@hackgbot
Copy link

Hey y'all! A deployment of this PR can be found here:
https://registration-export-to-checkin.pr.hack.gt

@petschekr petschekr added this to the HackGT 4 milestone Sep 20, 2017
Copy link
Member

@petschekr petschekr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, I like this. There are just 1 or 2 minor code issues. Also, I think it would make more sense for the key to be set randomly using crypto.randomBytes() by default or always rather than being blank or set by the user.

server/common.ts Outdated
});
} else {
let userKey = request.params.exportKey;
console.log("Yasss", userKey, exportKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please remove this console.log?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awkward

@@ -133,7 +133,8 @@ templateRoutes.route("/").get(authenticateWithRedirect, async (request, response
user: request.user,
settings: {
teamsEnabled: await getSetting<boolean>("teamsEnabled"),
qrEnabled: await getSetting<boolean>("qrEnabled")
qrEnabled: await getSetting<boolean>("qrEnabled"),
exportKey: await getSetting<string>("exportKey")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the export key being sent to the template engine for routes that don't need it?

@petschekr petschekr added enhancement Adds or suggests a new feature, rewrite, or other enhancement to the codebase medium priority labels Sep 20, 2017
@mjkaufer
Copy link
Contributor Author

@petschekr implemented your changes, lmk if I need anything else. There are some conflicts with master; I'll resolve those once everything looks good to you

server/common.ts Outdated
@@ -306,7 +306,7 @@ export async function setDefaultSettings() {
"confirmationClose": new Date(),
"teamsEnabled": true,
"qrEnabled": true,
"exportKey": "",
"exportKey": crypto.randomBytes(16).toString('hex'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double quotes plz

@petschekr
Copy link
Member

Other than that this looks ready to merge once Andrew's dumpster fire is extinguished and you can fix any merge conflicts that probably cropped up

@mjkaufer
Copy link
Contributor Author

@petschekr just added double quotes

@illegalprime can you take a look over this when you're free

Lmk when Andrew's stuff gets sorted out and I'll fix merge conflicts.

Copy link
Member

@illegalprime illegalprime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andrew's stuff should be done, you can rebase. Looks good save for just two comments.

@@ -473,6 +473,9 @@ settingsUpdateButton.addEventListener("click", e => {
let qrEnabledData = new FormData();
qrEnabledData.append("enabled", (document.getElementById("qr-enabled") as HTMLInputElement).checked ? "true" : "false");

let exportKeyData = new FormData();
exportKeyData.append("key", (document.getElementById("export-key") as HTMLInputElement).value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trim whitespace

server/common.ts Outdated
@@ -306,6 +306,7 @@ export async function setDefaultSettings() {
"confirmationClose": new Date(),
"teamsEnabled": true,
"qrEnabled": true,
"exportKey": crypto.randomBytes(16).toString("hex"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best expressed as a configuration option (so you can set an env var or file with this key on multiple instances).
I think we should eventually merge settings + configuration, what do you think @petschekr ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@illegalprime I figured this might be better as a setting, since we wouldn't have to restart the server to change the key

@mjkaufer
Copy link
Contributor Author

@illegalprime @petschekr just merged with Andrew's code

@illegalprime
Copy link
Member

@mjkaufer didn't read the summary of your PR, but we have cas auth hooked up right now! We can communicate in a better way than pushing CSVs back n' forth.

@illegalprime
Copy link
Member

I also think that the right way to do this is to provide APIs that check-in can use to:

  1. Text search the name and email of the user
  2. Find a user by his or her ID
  3. Pull up some registration question data (like t-shirt size) for the user

@illegalprime
Copy link
Member

BTW: We're thinking of doing it through GraphQL for all our services, but now these patent issues have made me uneasy: graphql/graphql-spec#351 ...

@illegalprime illegalprime force-pushed the export-to-checkin branch 2 times, most recently from b02f404 to 8f6175c Compare September 26, 2017 05:29
@illegalprime illegalprime mentioned this pull request Sep 26, 2017
@illegalprime
Copy link
Member

I changed it to just be a config.

@@ -73,7 +73,10 @@ export function isUserOrAdmin(request: express.Request, response: express.Respon
export function isAdmin(request: express.Request, response: express.Response, next: express.NextFunction) {
response.setHeader("Cache-Control", "private");
let user = request.user as IUser;
if (!request.isAuthenticated()) {
if (request.query.adminKey === config.secrets.adminKey) {
Copy link
Member

@petschekr petschekr Sep 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you want this admin-level access information in a query string? It may be behind HTTPS but will probably appear in server logs / history logs. A cookie or Authorization header might be better.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call

@illegalprime
Copy link
Member

@petschekr changed it to a header

const auth = request.headers.authorization;

if (auth && typeof auth === "string") {
const key = new Buffer(auth.split(" ")[1], "base64").toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will crash the server if the Authorization header doesn't have a space in it due to it indexing an array of length 0 or 1

@petschekr petschekr merged commit 83ebc11 into master Sep 30, 2017
@petschekr petschekr deleted the export-to-checkin branch October 7, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adds or suggests a new feature, rewrite, or other enhancement to the codebase medium priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants