Disable datastore if key not set

This commit is contained in:
William Oldham 2024-09-24 11:57:11 +01:00
parent 5c40042796
commit 1768dc4654
2 changed files with 15 additions and 9 deletions

View File

@ -11,7 +11,8 @@ export const disabledFeatures = {
redis: false,
email: false,
captcha: false,
s3: false
s3: false,
datastore: false
};
const hexadecimalStringRegex = /^[0-9a-f]+$/i;
@ -242,14 +243,16 @@ if (!config.stripe?.secret_key) {
}
if (!config.datastore.signature_secret) {
LOG_ERROR('Datastore signature secret key is not set. Set the PN_ACT_CONFIG_DATASTORE_SIGNATURE_SECRET environment variable');
configValid = false;
}
if (config.datastore.signature_secret.length !== 32 || !hexadecimalStringRegex.test(config.datastore.signature_secret)) {
LOG_ERROR('Datastore signature secret key must be a 32-character hexadecimal string.');
configValid = false;
LOG_WARN('Datastore signature secret key is not set. Disabling feature. To enable feature set the PN_ACT_CONFIG_DATASTORE_SIGNATURE_SECRET environment variable');
disabledFeatures.datastore = true;
} else {
if (config.datastore.signature_secret.length !== 32 || !hexadecimalStringRegex.test(config.datastore.signature_secret)) {
LOG_ERROR('Datastore signature secret key must be a 32-character hexadecimal string.');
configValid = false;
}
}
if (!configValid) {
LOG_ERROR('Config is invalid. Exiting');
process.exit(0);

View File

@ -26,7 +26,7 @@ import api from '@/services/api';
import localcdn from '@/services/local-cdn';
import assets from '@/services/assets';
import { config } from '@/config-manager';
import { config, disabledFeatures } from '@/config-manager';
const app = express();
@ -48,11 +48,14 @@ app.use(conntest);
app.use(cbvc);
app.use(nnas);
app.use(nasc);
app.use(datastore);
app.use(api);
app.use(localcdn);
app.use(assets);
if (!disabledFeatures.datastore) {
app.use(datastore);
}
// * 404 handler
LOG_INFO('Creating 404 status handler');
app.use((request: express.Request, response: express.Response): void => {