Skip to content

Commit

Permalink
chore: props order
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed May 31, 2022
1 parent 0cdf1b9 commit 0914e7a
Show file tree
Hide file tree
Showing 8 changed files with 148 additions and 96 deletions.
15 changes: 8 additions & 7 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,29 @@ module.exports = {

parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},

rules: {
// overwrite airbnb-base options

// require file extensions
'import/extensions': ['error', 'always', { ignorePackages: true }],

'no-restricted-exports': 'off',
// import buffer explicitly

'no-restricted-globals': [
'error',
{
name: 'Buffer',
message: "Import 'Buffer' from 'node:buffer' module instead",
name: 'Buffer',
},
{
name: 'process',
message: "Import 'process' from 'node:process' module instead",
name: 'process',
},
],
// we use underscores to indicate private fields in classes
'no-underscore-dangle': 'off',

'sort-keys': 'error',

// we turn this off here, for all commonjs modules (e.g. test fixtures etc.)
strict: ['off'],

Expand All @@ -49,5 +49,6 @@ module.exports = {
'lines-between-class-members': 'off',
'no-console': 'off',
'no-restricted-syntax': 'off',
'no-underscore-dangle': 'off',
},
}
22 changes: 12 additions & 10 deletions src/events/websocket/http-routes/connections/connectionsRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ export default function connectionsRoutes(webSocketClients, v3Utils) {

return [
{
method: 'POST',
options: {
payload: {
parse: false,
},
},
path: '/@connections/{connectionId}',
async handler(request, h) {
const {
params: { connectionId },
Expand Down Expand Up @@ -44,16 +37,17 @@ export default function connectionsRoutes(webSocketClients, v3Utils) {

return null
},
},

{
method: 'DELETE',
method: 'POST',
options: {
payload: {
parse: false,
},
},
path: '/@connections/{connectionId}',
},

{
handler(request, h) {
const {
params: { connectionId },
Expand All @@ -80,6 +74,14 @@ export default function connectionsRoutes(webSocketClients, v3Utils) {

return h.response(null).code(204)
},

method: 'DELETE',
options: {
payload: {
parse: false,
},
},
path: '/@connections/{connectionId}',
},
]
}
18 changes: 9 additions & 9 deletions src/lambda/handler-runner/go-runner/GoRunner.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export default class GoRunner {
// Get go env to run this locally
if (!this.#goEnv) {
const goEnvResponse = await execa('go', ['env'], {
stdio: 'pipe',
encoding: 'utf-8',
stdio: 'pipe',
})

const goEnvString = goEnvResponse.stdout || goEnvResponse.stderr
Expand All @@ -129,25 +129,25 @@ export default class GoRunner {
}

const { stdout, stderr } = await execa(`./tmp`, {
stdio: 'pipe',
encoding: 'utf-8',
env: {
...this.#env,
...this.#goEnv,
AWS_LAMBDA_LOG_GROUP_NAME: context.logGroupName,
AWS_LAMBDA_LOG_STREAM_NAME: context.logStreamName,
AWS_LAMBDA_FUNCTION_NAME: context.functionName,
AWS_LAMBDA_FUNCTION_MEMORY_SIZE: context.memoryLimitInMB,
AWS_LAMBDA_FUNCTION_NAME: context.functionName,
AWS_LAMBDA_FUNCTION_VERSION: context.functionVersion,
LAMBDA_EVENT: stringify(event),
LAMBDA_TEST_EVENT: `${event}`,
LAMBDA_CONTEXT: stringify(context),
AWS_LAMBDA_LOG_GROUP_NAME: context.logGroupName,
AWS_LAMBDA_LOG_STREAM_NAME: context.logStreamName,
IS_LAMBDA_AUTHORIZER:
event.type === 'REQUEST' || event.type === 'TOKEN',
IS_LAMBDA_REQUEST_AUTHORIZER: event.type === 'REQUEST',
IS_LAMBDA_TOKEN_AUTHORIZER: event.type === 'TOKEN',
LAMBDA_CONTEXT: stringify(context),
LAMBDA_EVENT: stringify(event),
LAMBDA_TEST_EVENT: `${event}`,
PATH: process.env.PATH,
},
encoding: 'utf-8',
stdio: 'pipe',
})

await this.cleanup()
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/authorizer/authorizer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ describe('authorizer tests', function desc() {
description: 'should return acceptable context object',
expected: {
authorizer: {
booleanKey: 'true',
numberKey: '1',
principalId: 'user123',
stringKey: 'value',
numberKey: '1',
booleanKey: 'true',
},
},
options: {
Expand All @@ -74,10 +74,10 @@ describe('authorizer tests', function desc() {
description: 'should return stringified context objects',
expected: {
authorizer: {
booleanKey: 'true',
numberKey: '1',
principalId: 'user123',
stringKey: 'value',
numberKey: '1',
booleanKey: 'true',
},
},
options: {
Expand All @@ -93,10 +93,10 @@ describe('authorizer tests', function desc() {
description:
'should return 500 error if context contains forbidden types (array, object)',
expected: {
statusCode: 500,
error: 'AuthorizerConfigurationException',
message:
'Authorizer response context values must be of type string, number, or boolean',
statusCode: 500,
},
options: {
headers: {
Expand All @@ -110,9 +110,9 @@ describe('authorizer tests', function desc() {
{
description: 'should return 500 error if context is not an object',
expected: {
statusCode: 500,
error: 'AuthorizerConfigurationException',
message: 'Authorizer response context must be an object',
statusCode: 500,
},
options: {
headers: {
Expand Down
14 changes: 7 additions & 7 deletions tests/integration/authorizer/src/authorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

function generatePolicy(principalId, effect, resource, context) {
const authResponse = {
principalId,
context,
principalId,
}

if (effect && resource) {
const policyDocument = {
Version: '2012-10-17',
Statement: [
{
Action: 'execute-api:Invoke',
Effect: effect,
Resource: resource,
},
],
Version: '2012-10-17',
}

authResponse.policyDocument = policyDocument
Expand Down Expand Up @@ -66,22 +66,22 @@ exports.authorizerAsyncFunction = async function authorizerAsyncFunction(
exports.authorizerWithContext = async function authorizerWithContext(event) {
// Recommended format by AWS: string dictionary
const recommendedContext = {
stringKey: 'value',
numberKey: '1',
booleanKey: 'true',
numberKey: '1',
stringKey: 'value',
}

// Still works, but values are coerced to strings
const stringifiedContext = {
stringKey: 'value',
numberKey: 1,
booleanKey: true,
numberKey: 1,
stringKey: 'value',
}

// Causes AuthorizerConfigurationException
const contextWithObjectKeys = {
objectKey: { a: '1' },
arrayKey: ['a', 'b', 'c'],
objectKey: { a: '1' },
}

// Causes AuthorizerConfigurationException
Expand Down
26 changes: 13 additions & 13 deletions tests/manual/nodejs/src/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ const { stringify } = JSON

exports.hello = function hello(event, context, callback) {
const response = {
statusCode: 200,
body: stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
message: 'Go Serverless v1.0! Your function executed successfully!',
}),
statusCode: 200,
}

callback(null, response)
}

exports.rejectedPromise = function rejectedPromise(event, context, callback) {
const response = {
statusCode: 200,
body: stringify({
message: 'Go Serverless v1.0! Your function executed successfully!',
input: event,
message: 'Go Serverless v1.0! Your function executed successfully!',
}),
statusCode: 200,
}

console.log('About to reject promise')
Expand All @@ -32,28 +32,28 @@ exports.rejectedPromise = function rejectedPromise(event, context, callback) {

exports.authFunction = function authFunction(event, context) {
context.succeed({
principalId: 'xxxxxxx', // the principal user identification associated with the token send by the client
policyDocument: {
// example policy shown below, but this value is any valid policy
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
Action: ['execute-api:Invoke'],
Effect: 'Allow',
Resource: [event.methodArn],
},
],
Version: '2012-10-17',
},
principalId: 'xxxxxxx', // the principal user identification associated with the token send by the client
})
}

exports.hello500 = function hello500(event, context, callback) {
const response = {
statusCode: 500,
body: stringify({
message: 'Fake internal server error.',
input: event,
message: 'Fake internal server error.',
}),
statusCode: 500,
}

callback(null, response)
Expand All @@ -65,8 +65,8 @@ exports.helloLambdaIntegration = function helloLambdaIntegration(
cb,
) {
cb(null, {
message: 'Go Serverless v1.0! Your function executed successfully!',
event,
message: 'Go Serverless v1.0! Your function executed successfully!',
})
}

Expand All @@ -80,32 +80,32 @@ exports.helloLambdaIntegration500 = function helloLambdaIntegration500(

exports.basicAuthentication = function basicAuthentication(event, context, cb) {
const response = {
statusCode: 200,
body: stringify({
message: 'Private Function Executed Correctly',
}),
statusCode: 200,
}

cb(null, response)
}

exports.catchAll = function catchAll(event, context, cb) {
const response = {
statusCode: 200,
body: stringify({
message: 'Catch all route',
}),
statusCode: 200,
}

cb(null, response)
}

exports.pathParams = function pathParams(event, context, cb) {
const response = {
statusCode: 200,
body: stringify({
message: `id is ${event.pathParameters.id}`,
}),
statusCode: 200,
}

cb(null, response)
Expand Down
Loading

0 comments on commit 0914e7a

Please sign in to comment.