Skip to content

Commit

Permalink
unnecessary express.js return found
Browse files Browse the repository at this point in the history
  • Loading branch information
eercanayar committed Aug 13, 2018
1 parent c62cfd8 commit baf6e98
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions lambda/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ var https = require('https');
const config = require('./config');
// Load the SDK for JavaScript
const AWS = require('aws-sdk');
// Set the region
// Set the region
console.log(config.DynamoDB_TABLE_NAME);
AWS.config.update({region: `${config.DYNAMODB_TABLE_REGION}`});
// Set the Dynamodb Table
Expand All @@ -23,10 +23,7 @@ let findDataBySerialNumber = ( values,callback ) => {
}, (err, data) => {
if (err) {
console.log(err);
res.status(500).json({
message: 'Could not load your device info',
}).end();
callback( err );
callback( null, err );
} else {
//console.log(data.Count);
callback( null, data );
Expand All @@ -36,7 +33,7 @@ let findDataBySerialNumber = ( values,callback ) => {

// Put IoT cert info into Dynamodb
let putCertinfo = ( iotcert, values,callback ) => {

dynamoDb.update({
TableName: Device_TABLE_NAME,
Key:{
Expand All @@ -59,7 +56,7 @@ let putCertinfo = ( iotcert, values,callback ) => {

// Apply cert & Attach thing, policy
let applycert = ( serialNumber, callback ) => {

AWS.config.update({region: config.region});
var iot = new AWS.Iot();
var params = {
Expand All @@ -69,10 +66,10 @@ let applycert = ( serialNumber, callback ) => {
iot.createKeysAndCertificate(params, function(err, certdata) {
console.log("certdata:");
console.log(certdata);

if (err) console.log(err, err.stack); // an error occurred
else{

// Create IoT Policy for above cert
var params = {
policyDocument: config.PILICY_DOCUMENT, /* required */
Expand All @@ -82,7 +79,7 @@ let applycert = ( serialNumber, callback ) => {
if (err) console.log(err, err.stack); // an error occurred
else{
console.log(data);

// Attach policy for cert
var params = {
policyName: serialNumber, /* required */
Expand All @@ -91,7 +88,7 @@ let applycert = ( serialNumber, callback ) => {
iot.attachPolicy(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {

// Create thing for cert
var params = {
thingName: serialNumber, /* required */
Expand All @@ -105,13 +102,13 @@ let applycert = ( serialNumber, callback ) => {
iot.createThing(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else {

// Attach thing for cert
var params = {
principal: certdata.certificateArn, /* required */
thingName: serialNumber /* required */
};

iot.attachThingPrincipal(params, function(err, thingdata) {
if (err) console.log(err, err.stack); // an error occurred
else {
Expand All @@ -124,20 +121,20 @@ let applycert = ( serialNumber, callback ) => {
});
}
});
}
}
});
}

// Get VeriSign Class 3 Public Primary G5 root CA certificate
// Get VeriSign Class 3 Public Primary G5 root CA certificate
let getIoTRootCA = ( callback ) => {
const RootCA_URL = config.RootCA_URL;
https.get(RootCA_URL, ( response ) => {

var body = [];
//console.log(response.statusCode);
//console.log(response.headers);
//console.log(response);

response.on('data', function (chunk) {
body.push(chunk);
});
Expand All @@ -147,12 +144,12 @@ let getIoTRootCA = ( callback ) => {
//console.log(body.toString());
callback( null, body.toString() );
});

})
}

module.exports = {

findDataBySerialNumber,
putCertinfo,
getIoTRootCA,
Expand Down

0 comments on commit baf6e98

Please sign in to comment.