Skip to content

Commit

Permalink
Merge pull request #293 from smartdevicelink/develop
Browse files Browse the repository at this point in the history
Policy Server 3.0.0 Release
  • Loading branch information
crokita authored Apr 13, 2022
2 parents 05576a8 + 9cc260b commit 560181c
Show file tree
Hide file tree
Showing 104 changed files with 8,752 additions and 8,101 deletions.
97 changes: 47 additions & 50 deletions app/v1/about/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,56 +6,53 @@ const semver = require('semver');
const certificateController = require('../certificates/controller.js');

exports.getInfo = function (req, res, next) {
var data = {
"current_version": packageJson.version,
"latest_version": packageJson.version,
"is_update_available": false,
"ssl_port": config.ssl.policyServerPort,
"cache_module": config.cacheModule,
"auth_type": config.authType,
"auto_approve_all_apps": config.autoApproveAllApps,
"encryption_required": config.autoApproveSetRPCEncryption,
"base_url": app.locals.baseUrl,
"notification": {
"appsPendingReview": {
"email": {
"enabled": (
config.smtp.host
&& config.smtp.from
&& ["REALTIME"].includes(config.notification.appsPendingReview.email.frequency)
&& config.notification.appsPendingReview.email.to.split(",").length
),
"frequency": config.notification.appsPendingReview.email.frequency,
"to_count": config.notification.appsPendingReview.email.to.split(",").length
}
}
},
"certificate_authority": certificateController.openSSLEnabled
};
var data = {
"current_version": packageJson.version,
"latest_version": packageJson.version,
"is_update_available": false,
"ssl_port": config.ssl.policyServerPort,
"cache_module": config.cacheModule,
"auth_type": config.authType,
"auto_approve_all_apps": config.autoApproveAllApps,
"encryption_required": config.autoApproveSetRPCEncryption,
"base_url": app.locals.baseUrl,
"notification": {
"appsPendingReview": {
"email": {
"enabled": (
config.smtp.host
&& config.smtp.from
&& ["REALTIME"].includes(config.notification.appsPendingReview.email.frequency)
&& config.notification.appsPendingReview.email.to.split(",").length
),
"frequency": config.notification.appsPendingReview.email.frequency,
"to_count": config.notification.appsPendingReview.email.to.split(",").length
}
}
},
"certificate_authority": certificateController.openSSLEnabled
};

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){
// 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();
})
}
// 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
}, 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) {
const isAuthorityValid = await certificateController.checkAuthorityValidity();
data.is_authority_valid = isAuthorityValid && data.certificate_authority;
}

res.parcel.setStatus(200)
.setData(data)
.deliver();
});
res.parcel.setStatus(200)
.setData(data)
.deliver();
});
}
201 changes: 97 additions & 104 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 @@ -58,115 +55,111 @@ const certificates = require('./certificates/controller.js');
const vehicleData = require('./vehicle-data/controller.js');

function exposeRoutes () {
// use helmet middleware for security
app.use(helmet());
// extend response builder to all routes
app.route("*").all(parcel.extendExpress);
// use helmet middleware for security
app.use(helmet());
// extend response builder to all routes
app.route("*").all(parcel.extendExpress);

//route definitions
//app.post('/forgot', forgot.post);
//app.post('/register', register.post);
app.post('/login', login.validateAuth);
app.get('/applications', auth.validateAuth, applications.get);
app.post('/applications/action', auth.validateAuth, applications.actionPost);
app.post('/applications/auto', auth.validateAuth, applications.autoPost);
app.post('/applications/administrator', auth.validateAuth, applications.administratorPost);
app.post('/applications/passthrough', auth.validateAuth, applications.passthroughPost);
app.post('/applications/hybrid', auth.validateAuth, applications.hybridPost);
app.put('/applications/rpcencryption', auth.validateAuth, applications.rpcEncryptionPut);
app.put('/applications/service/permission', auth.validateAuth, applications.putServicePermission);
app.post('/applications/certificate/get', applications.getAppCertificate);
app.get('/applications/certificate/get', applications.getAppCertificate);
app.post('/applications/certificate', applications.updateAppCertificate);
app.get('/applications/groups', auth.validateAuth, applications.getFunctionalGroups);
app.put('/applications/groups', auth.validateAuth, applications.putFunctionalGroup);
// webengine app store
app.get('/applications/store', cors(), applications.getAppStore);
app.get('/applications/store/staging', cors(), applications.getStagingAppStore);
app.post('/webhook', applications.webhook); //webhook route
//begin policy table routes
app.options('/staging/policy', cors())
app.options('/production/policy', cors())
app.post('/staging/policy', cors(), policy.postFromCoreStaging);
app.post('/production/policy', cors(), policy.postFromCoreProduction);
app.get('/policy/preview', policy.getPreview);
app.post('/policy/apps', policy.postAppPolicy);
//end policy table routes
app.post('/permissions/update', auth.validateAuth, permissions.post);
app.get('/permissions/unmapped', auth.validateAuth, permissions.get);
app.get('/groups', auth.validateAuth, groups.get);
app.get('/groups/names', auth.validateAuth, groups.getNames);
app.post('/groups', auth.validateAuth, groups.postAddGroup);
app.post('/groups/promote', auth.validateAuth, groups.postPromote);
app.get('/messages', auth.validateAuth, messages.getInfo);
app.get('/messages/names', auth.validateAuth, messages.getNames);
app.post('/messages', auth.validateAuth, messages.postAddMessage);
app.post('/messages/promote', auth.validateAuth, messages.postPromoteMessages);
app.post('/messages/update', auth.validateAuth, messages.postUpdate);
app.get('/module', auth.validateAuth, moduleConfig.get);
app.post('/module', auth.validateAuth, moduleConfig.post);
app.post('/module/promote', auth.validateAuth, moduleConfig.promote);
app.post('/module/promoteNoId', auth.validateAuth, moduleConfig.promoteNoId);
app.get('/about', auth.validateAuth, about.getInfo);
app.post('/security/certificate', certificates.createCertificate);
app.post('/security/private', certificates.createPrivateKey);
//route definitions
//app.post('/forgot', forgot.post);
//app.post('/register', register.post);
app.post('/login', login.validateAuth);
app.get('/applications', auth.validateAuth, applications.get);
app.post('/applications/action', auth.validateAuth, applications.actionPost);
app.post('/applications/auto', auth.validateAuth, applications.autoPost);
app.post('/applications/administrator', auth.validateAuth, applications.administratorPost);
app.post('/applications/passthrough', auth.validateAuth, applications.passthroughPost);
app.post('/applications/hybrid', auth.validateAuth, applications.hybridPost);
app.put('/applications/rpcencryption', auth.validateAuth, applications.rpcEncryptionPut);
app.put('/applications/service/permission', auth.validateAuth, applications.putServicePermission);
app.post('/applications/certificate/get', applications.getAppCertificate);
app.get('/applications/certificate/get', applications.getAppCertificate);
app.post('/applications/certificate', applications.updateAppCertificate);
app.get('/applications/groups', auth.validateAuth, applications.getFunctionalGroups);
app.put('/applications/groups', auth.validateAuth, applications.putFunctionalGroup);
// webengine app store
app.get('/applications/store', cors(), applications.getAppStore);
app.get('/applications/store/staging', cors(), applications.getStagingAppStore);
app.post('/webhook', applications.webhook); //webhook route
//begin policy table routes
app.options('/staging/policy', cors())
app.options('/production/policy', cors())
app.post('/staging/policy', cors(), policy.postFromCoreStaging);
app.post('/production/policy', cors(), policy.postFromCoreProduction);
app.get('/policy/preview', policy.getPreview);
app.post('/policy/apps', policy.postAppPolicy);
//end policy table routes
app.post('/permissions/update', auth.validateAuth, permissions.post);
app.get('/permissions/unmapped', auth.validateAuth, permissions.get);
app.get('/groups', auth.validateAuth, groups.get);
app.get('/groups/names', auth.validateAuth, groups.getNames);
app.post('/groups', auth.validateAuth, groups.postAddGroup);
app.post('/groups/promote', auth.validateAuth, groups.postPromote);
app.get('/messages', auth.validateAuth, messages.getInfo);
app.get('/messages/names', auth.validateAuth, messages.getNames);
app.post('/messages', auth.validateAuth, messages.postAddMessage);
app.post('/messages/promote', auth.validateAuth, messages.postPromoteMessages);
app.post('/messages/update', auth.validateAuth, messages.postUpdate);
app.get('/module', auth.validateAuth, moduleConfig.get);
app.post('/module', auth.validateAuth, moduleConfig.post);
app.post('/module/promote', auth.validateAuth, moduleConfig.promote);
app.post('/module/promoteNoId', auth.validateAuth, moduleConfig.promoteNoId);
app.get('/about', auth.validateAuth, about.getInfo);
app.post('/security/certificate', certificates.createCertificate);
app.post('/security/private', certificates.createPrivateKey);
//begin vehicle data routes
app.post('/vehicle-data', auth.validateAuth, vehicleData.post);
app.get('/vehicle-data', auth.validateAuth, vehicleData.get);
app.post('/vehicle-data/promote', auth.validateAuth, vehicleData.promote);
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) {
// get and store app service type info from SHAID on startup
services.upsertTypes(function () {
log.info("App service types updated");
next();
});
},
function (next) {
//get and store app categories from SHAID on startup
applications.queryAndStoreCategories(function() {
log.info('App categories updated');
next();
});
},
function (next) {
//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) {
//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 () {
log.info("Start up complete. Exposing routes.");
exposeRoutes();
});
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()
.catch(err => {
log.error(err);
}),
//get and store app categories from SHAID on startup
applications.queryAndStoreCategories()
.catch(err => {
log.error(err);
}),
//get and store language code info from the GitHub SDL RPC specification on startup
messages.updateLanguages()
.catch(err => {
log.error(err);
}),
//get and store app info from SHAID on startup
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

0 comments on commit 560181c

Please sign in to comment.