-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/mitipi/serverless-iot-off…
- Loading branch information
Showing
7 changed files
with
84 additions
and
37 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,15 @@ | ||
const evalInContext = (js, context) => { | ||
const {clientid, topic, accountid, timestamp} = context | ||
const evalInContext = (expr, context) => { | ||
let [func, fields] = expr.match(/(\w+)\((.*)\)/).slice(1, 3); | ||
fields = fields | ||
? fields.split(",").map((f) => f.trim().replace(/['"]+/g, "")) | ||
: []; | ||
|
||
try { | ||
return eval(js) | ||
return context[func](...fields); | ||
} catch (err) { | ||
debugger | ||
console.log(`failed to evaluate: ${js}`) | ||
throw err | ||
} | ||
} | ||
|
||
const encode = (data, encoding) => { | ||
if (encoding !== 'base64') { | ||
throw new Error('AWS Iot SQL encode() function only supports base64 as an encoding') | ||
debugger; | ||
console.log(`failed to evaluate: ${expr}`); | ||
throw err; | ||
} | ||
|
||
return data.toString(encoding) | ||
} | ||
|
||
module.exports = evalInContext | ||
}; | ||
module.exports = evalInContext; |
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
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
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
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