Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/promise server logic #267

Merged
merged 5 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions app/v1/about/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,22 @@ exports.getInfo = function (req, res, next) {
"certificate_authority": certificateController.openSSLEnabled
};

// cannot use promisify: there are two returns we need
requestjs({
"method": "GET",
"uri": "https://raw.githubusercontent.com/smartdevicelink/sdl_server/master/package.json",
"timeout": 5000,
"json": true
}, function(err, response, body){
if(!err && response.statusCode >= 200 && response.statusCode < 300){
}, async function (err, response, body) {
if (!err && response.statusCode >= 200 && response.statusCode < 300) {
// success!
data.latest_version = body.version;
data.is_update_available = semver.lt(data.current_version, data.latest_version);
data.update_type = semver.diff(data.current_version, data.latest_version);
}
if(data.certificate_authority){
return certificateController.checkAuthorityValidity(function(isAuthorityValid){
data.is_authority_valid = isAuthorityValid && data.certificate_authority;
res.parcel.setStatus(200)
.setData(data)
.deliver();
})
if (data.certificate_authority) {
const isAuthorityValid = await certificateController.checkAuthorityValidity();
data.is_authority_valid = isAuthorityValid && data.certificate_authority;
}

res.parcel.setStatus(200)
Expand Down
87 changes: 40 additions & 47 deletions app/v1/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const path = require('path');
const config = require('../../settings'); //configuration module
const log = require(`../../custom/loggers/${config.loggerModule}/index.js`);
const db = require(`../../custom/databases/${config.dbModule}/index.js`)(log); //pass in the logger module that's loaded
const flame = require('../../lib/flame-box');
const hashify = require('../../lib/hashify');
const arrayify = require('../../lib/arrayify');
const emailer = require('../../lib/emailer');
Expand All @@ -19,11 +18,9 @@ const Cron = require('cron').CronJob;
app.locals.config = config;
app.locals.log = log;
app.locals.db = db;
app.locals.flow = flame.flow;
app.locals.hashify = hashify;
app.locals.arrayify = arrayify;
app.locals.emailer = emailer;
app.locals.flame = flame;
app.locals.version = path.basename(__dirname);

// construct base URL, e.g. "http://localhost:3000"
Expand Down Expand Up @@ -117,56 +114,52 @@ function exposeRoutes () {
app.get('/vehicle-data/type', auth.validateAuth, vehicleData.getValidTypes);
}

//do not allow routes to be exposed until these async functions are completed
flame.async.parallel([
//certificate expiration check and renewal for both applications and for the module config
applications.checkAndUpdateCertificates,
moduleConfig.checkAndUpdateCertificate,
//get and store permission info from SHAID on startup
function (next) {
permissions.update(function () {
log.info("Permissions updated");
next();
});
},
function (next) {
async function setup () {
//do not allow routes to be exposed until these async functions are completed
await Promise.all([
//certificate expiration check and renewal for both applications and for the module config
applications.checkAndUpdateCertificates()
.catch(err => {
log.error(err);
}),
moduleConfig.checkAndUpdateCertificate()
.catch(err => {
log.error(err);
}),
//get and store permission info from SHAID on startup
permissions.update()
.catch(err => {
log.error(err);
}),
// get and store app service type info from SHAID on startup
services.upsertTypes(function () {
log.info("App service types updated");
next();
});
},
function (next) {
services.upsertTypes()
.catch(err => {
log.error(err);
}),
//get and store app categories from SHAID on startup
applications.queryAndStoreCategories(function() {
log.info('App categories updated');
next();
});
},
function (next) {
applications.queryAndStoreCategories()
.catch(err => {
log.error(err);
}),
//get and store language code info from the GitHub SDL RPC specification on startup
messages.updateLanguages(function () {
log.info("Language list updated");
next();
});
},
function (next) {
messages.updateLanguages()
.catch(err => {
log.error(err);
}),
//get and store app info from SHAID on startup
applications.queryAndStoreApplicationsFlow({}, false)(function () {
log.info("App information updated");
next();
});
},
function(next) {
vehicleData.updateRpcSpec(function() {
log.info("RPC Spec updated");
next();
});
},
], function () {
applications.queryAndStoreApplications({}, false)
.catch(err => {
log.error(err);
}),
vehicleData.updateRpcSpec()
.catch(err => {
log.error(err);
}),
]);
log.info("Start up complete. Exposing routes.");
exposeRoutes();
});
}
setup();

//cron job for running updates. runs once a day at midnight
new Cron('00 00 00 * * *', permissions.update, null, true);
Expand Down
Loading