This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"token": "ABCD1234EFGH5678IJKL9012", | |
"team_id": "XXXXXXXXX", | |
"team_domain": "someteamdomain", | |
"channel_id": "YYYYYYYYY", | |
"channel_name": "directmessage", | |
"user_id": "ZZZZZZZZZ", | |
"user_name": "someuser", | |
"command": "/dbreset", | |
"text": "", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function validateUserAgent(event, desiredUserAgent) { | |
return new Promise(function(resolve, reject) { | |
const foundUserAgent = event.requestContext.identity.userAgent.toLowerCase(); | |
if (foundUserAgent.startsWith(desiredUserAgent.toLowerCase())) { | |
resolve(querystring.parse(event.body)); | |
} else { | |
reject(buildError(401, "This endpoint cannot be accessed via the current User Agent.")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.reset = (event, context, callback) => { | |
const targetUserAgent = 'slackbot'; | |
const targetSlackTeam = 'SomeSlackTeam'; | |
validateUserAgent(event, targetUserAgent) | |
.then(requestBody => validateSlackTeam(requestBody, targetSlackTeam)) | |
.then(validatedRequestBody => extractUser(validatedRequestBody)) | |
.then(extractedUser => resetDB(extractedUser)) | |
.then(response => callback(null, response)) | |
.catch(error => callback(error)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: 'AWS::Serverless-2016-10-31' | |
Resources: | |
someTable: | |
Type: 'AWS::DynamoDB::Table' | |
Properties: | |
AttributeDefinitions: | |
- AttributeName: id | |
AttributeType: S | |
- AttributeName: version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service: serverless | |
provider: | |
name: aws | |
runtime: nodejs6.10 | |
functions: | |
someFunction: | |
handler: someFunction.handler | |
description: Lambda Function | |
events: | |
- stream: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
provider "aws" { } | |
resource "aws_iam_role" "iam_for_lambda" { | |
name = "iam_for_lambda" | |
assume_role_policy = <<EOF | |
{ | |
"Version": "2012-10-17", | |
"Statement": [ | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE VIEW ClassesAndRunningInformation AS | |
SELECT | |
ClassGroup.Name AS ClassGroupName, | |
Running.StartDate, | |
Module.Name AS ModuleName, | |
Module.Length AS ModuleLength | |
FROM | |
ClassGroup | |
INNER JOIN | |
Running |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE userType ( | |
id int NOT NULL, | |
description varchar(255) NOT NULL, | |
PRIMARY KEY (`id`) | |
); | |
CREATE TABLE user ( | |
id char(32) NOT NULL, -- use uuid() on INSERT | |
username varchar(24) NOT NULL, -- rob | |
passwordHash char(40) NOT NULL, -- c8fed00eb2e87f1cee8e90ebbe870c190ac3848c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function archetype (request, response) { | |
// Get Data out of the request | |
// Process that data | |
// Build and send the response | |
response.setHeaders(); | |
response.write(); | |
response.end(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function signup (email, password) { | |
const salt = uuid(); | |
const hashedPassword = hash(`${salt}${password}`); | |
// this stores everything in the DB | |
createUser(email, salt, hashedPassword); | |
} | |
function login (request, response) { | |
// get the salt - SELECT salt FROM users | |
// WHERE email = ?, [email] |