Skip to content

Commit

Permalink
Linting/prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Nov 30, 2019
1 parent 0be8ad1 commit c058fa6
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 80 deletions.
111 changes: 53 additions & 58 deletions src/ApiGateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -638,76 +638,71 @@ module.exports = class ApiGateway {
);

// responseParameters use the following shape: "key": "value"
Object.entries(responseParameters).forEach(
([key, value]) => {
const keyArray = key.split('.'); // eg: "method.response.header.location"
const valueArray = value.split('.'); // eg: "integration.response.body.redirect.url"

debugLog(
`Processing responseParameter "${key}": "${value}"`,
);

// For now the plugin only supports modifying headers
if (
key.startsWith('method.response.header') &&
keyArray[3]
) {
const headerName = keyArray.slice(3).join('.');
let headerValue;
debugLog('Found header in left-hand:', headerName);

if (value.startsWith('integration.response')) {
if (valueArray[2] === 'body') {
debugLog('Found body in right-hand');
headerValue = (valueArray[3]
? jsonPath(result, valueArray.slice(3).join('.'))
: result
);
if(typeof headerValue === 'undefined' || headerValue === null) {
headerValue = '';
} else {
headerValue = headerValue.toString();
}
Object.entries(responseParameters).forEach(([key, value]) => {
const keyArray = key.split('.'); // eg: "method.response.header.location"
const valueArray = value.split('.'); // eg: "integration.response.body.redirect.url"

debugLog(`Processing responseParameter "${key}": "${value}"`);

// For now the plugin only supports modifying headers
if (key.startsWith('method.response.header') && keyArray[3]) {
const headerName = keyArray.slice(3).join('.');
let headerValue;
debugLog('Found header in left-hand:', headerName);

if (value.startsWith('integration.response')) {
if (valueArray[2] === 'body') {
debugLog('Found body in right-hand');
headerValue = valueArray[3]
? jsonPath(result, valueArray.slice(3).join('.'))
: result;
if (
typeof headerValue === 'undefined' ||
headerValue === null
) {
headerValue = '';
} else {
this.printBlankLine();
this.serverlessLog(
`Warning: while processing responseParameter "${key}": "${value}"`,
);
this.serverlessLog(
`Offline plugin only supports "integration.response.body[.JSON_path]" right-hand responseParameter. Found "${value}" instead. Skipping.`,
);
this.logPluginIssue();
this.printBlankLine();
headerValue = headerValue.toString();
}
} else {
headerValue = value.match(/^'.*'$/)
? value.slice(1, -1)
: value; // See #34
}
// Applies the header;
if (headerValue === '') {
this.printBlankLine();
this.serverlessLog(
`Warning: empty value for responseParameter "${key}": "${value}", it won't be set`,
`Warning: while processing responseParameter "${key}": "${value}"`,
);
} else {
debugLog(
`Will assign "${headerValue}" to header "${headerName}"`,
this.serverlessLog(
`Offline plugin only supports "integration.response.body[.JSON_path]" right-hand responseParameter. Found "${value}" instead. Skipping.`,
);
response.header(headerName, headerValue);
this.logPluginIssue();
this.printBlankLine();
}
} else {
this.printBlankLine();
headerValue = value.match(/^'.*'$/)
? value.slice(1, -1)
: value; // See #34
}
// Applies the header;
if (headerValue === '') {
this.serverlessLog(
`Warning: while processing responseParameter "${key}": "${value}"`,
`Warning: empty value for responseParameter "${key}": "${value}", it won't be set`,
);
this.serverlessLog(
`Offline plugin only supports "method.response.header.PARAM_NAME" left-hand responseParameter. Found "${key}" instead. Skipping.`,
} else {
debugLog(
`Will assign "${headerValue}" to header "${headerName}"`,
);
this.logPluginIssue();
this.printBlankLine();
response.header(headerName, headerValue);
}
},
);
} else {
this.printBlankLine();
this.serverlessLog(
`Warning: while processing responseParameter "${key}": "${value}"`,
);
this.serverlessLog(
`Offline plugin only supports "method.response.header.PARAM_NAME" left-hand responseParameter. Found "${key}" instead. Skipping.`,
);
this.logPluginIssue();
this.printBlankLine();
}
});
}

let statusCode = 200;
Expand Down
12 changes: 6 additions & 6 deletions src/ServerlessOffline.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ module.exports = class ServerlessOffline {
return;
}

const hasPrivateHttpEvent = Object.values(functions || [])
.some(func => (func.events || [])
.filter(e => e.http)
.map(e => e.http)
.some(e => e.private)
);
const hasPrivateHttpEvent = Object.values(functions || []).some((func) =>
(func.events || [])
.filter((e) => e.http)
.map((e) => e.http)
.some((e) => e.private),
);

// for simple API Key authentication model
if (hasPrivateHttpEvent) {
Expand Down
4 changes: 3 additions & 1 deletion src/createLambdaProxyEvent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ module.exports = function createLambdaProxyEvent(
stageVariables,
) {
const authPrincipalId =
request.auth && request.auth.credentials && request.auth.credentials.principalId;
request.auth &&
request.auth.credentials &&
request.auth.credentials.principalId;
const authContext =
(request.auth &&
request.auth.credentials &&
Expand Down
30 changes: 17 additions & 13 deletions src/createVelocityContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function escapeJavaScript(x) {
*/
module.exports = function createVelocityContext(request, options, payload) {
const path = (x) => jsonPath(payload || {}, x);
const authPrincipalId = request.auth && request.auth.credentials && request.auth.credentials.principalId;
const authPrincipalId =
request.auth &&
request.auth.credentials &&
request.auth.credentials.principalId;

let authorizer;

Expand All @@ -39,9 +42,10 @@ module.exports = function createVelocityContext(request, options, payload) {
);
}
} else {
authorizer = request.auth
&& request.auth.credentials
&& request.auth.credentials.authorizer;
authorizer =
request.auth &&
request.auth.credentials &&
request.auth.credentials.authorizer;
}

const headers = request.unprocessedHeaders;
Expand All @@ -53,11 +57,11 @@ module.exports = function createVelocityContext(request, options, payload) {
}

if (!authorizer) authorizer = {};
authorizer.principalId = authorizer.principalId
|| authPrincipalId
|| process.env.PRINCIPAL_ID
|| 'offlineContext_authorizer_principalId'; // See #24

authorizer.principalId =
authorizer.principalId ||
authPrincipalId ||
process.env.PRINCIPAL_ID ||
'offlineContext_authorizer_principalId'; // See #24

if (token) {
try {
Expand Down Expand Up @@ -100,10 +104,10 @@ module.exports = function createVelocityContext(request, options, payload) {
typeof x === 'string'
? request.params[x] || request.query[x] || headers[x]
: {
header: headers,
path: Object.assign({}, request.params),
querystring: Object.assign({}, request.query),
},
header: headers,
path: Object.assign({}, request.params),
querystring: Object.assign({}, request.query),
},
},
stageVariables: options.stageVariables,
util: {
Expand Down
4 changes: 2 additions & 2 deletions src/functionHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ function runProxyHandler(funOptions, options) {
}
});

process.stderr.on('data', data => {
process.stderr.on('data', (data) => {
context.fail(data);
});

process.on('close', code => {
process.on('close', (code) => {
if (code.toString() === '0') {
try {
context.succeed(JSON.parse(results));
Expand Down

0 comments on commit c058fa6

Please sign in to comment.