Skip to content

Commit

Permalink
Merge pull request #196 from elastic-coders/handle-entry-detection-fo…
Browse files Browse the repository at this point in the history
…r-malformed-handlers

Ignore handlers that do not follow a path pattern
  • Loading branch information
HyperBrain authored Aug 21, 2017
2 parents cf51110 + 5916a90 commit 247b649
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 36 deletions.
20 changes: 13 additions & 7 deletions lib/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ module.exports = {
return path.extname(_.first(sortedFiles));
}

const getEntryForFunction = serverlessFunction => {
const getEntryForFunction = (name, serverlessFunction) => {
const handler = serverlessFunction.handler;
const handlerFile = /(.*)\..*?$/.exec(handler)[1];

// Check if handler is a well-formed path based handler.
const handlerEntry = /(.*)\..*?$/.exec(handler);
if (!handlerEntry) {
_.get(this.serverless, 'service.provider.name') !== 'google' &&
this.serverless.cli.log(`\nWARNING: Entry for ${name}@${handler} could not be retrieved.\nPlease check your service config if you want to use lib.entries.`);
return {};
}
const handlerFile = handlerEntry[1];
const ext = getEntryExtension(handlerFile);

// Create a valid entry key
Expand All @@ -70,12 +76,12 @@ module.exports = {
const entries = {};
const functions = this.serverless.service.getAllFunctions();
if (this.options.function) {
const serverlessFunction = this.serverless.service.getFunction(this.options.function);
const entry = getEntryForFunction(serverlessFunction);
const serverlessFunction = this.serverless.service.getFunction(this.options.function);
const entry = getEntryForFunction.call(this, this.options.function, serverlessFunction);
_.merge(entries, entry);
} else {
_.forEach(functions, func => {
const entry = getEntryForFunction(this.serverless.service.getFunction(func));
_.forEach(functions, (func, index) => {
const entry = getEntryForFunction.call(this, functions[index], this.serverless.service.getFunction(func));
_.merge(entries, entry);
});
}
Expand Down
58 changes: 29 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 247b649

Please sign in to comment.