Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32401068
D4171.1765340639.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D4171.1765340639.diff
View Options
diff --git a/keyserver/src/cron/backups.js b/keyserver/src/cron/backups.js
--- a/keyserver/src/cron/backups.js
+++ b/keyserver/src/cron/backups.js
@@ -18,7 +18,7 @@
async function backupDB() {
const [backupConfig, dbConfig] = await Promise.all([
- importJSON('facts/backups'),
+ importJSON({ folder: 'facts', name: 'backups' }),
getDBConfig(),
]);
@@ -184,7 +184,7 @@
}
async function deleteOldestBackup() {
- const backupConfig = await importJSON('facts/backups');
+ const backupConfig = await importJSON({ folder: 'facts', name: 'backups' });
invariant(backupConfig, 'backupConfig should be non-null');
const files = await readdir(backupConfig.directory);
let oldestFile;
diff --git a/keyserver/src/cron/update-geoip-db.js b/keyserver/src/cron/update-geoip-db.js
--- a/keyserver/src/cron/update-geoip-db.js
+++ b/keyserver/src/cron/update-geoip-db.js
@@ -8,7 +8,10 @@
import { importJSON } from '../utils/import-json';
async function updateGeoipDB(): Promise<void> {
- const geoipLicense = await importJSON('secrets/geoip_license');
+ const geoipLicense = await importJSON({
+ folder: 'secrets',
+ name: 'geoip_license',
+ });
if (!geoipLicense) {
console.log('no keyserver/secrets/geoip_license.json so skipping update');
return;
diff --git a/keyserver/src/database/db-config.js b/keyserver/src/database/db-config.js
--- a/keyserver/src/database/db-config.js
+++ b/keyserver/src/database/db-config.js
@@ -28,7 +28,10 @@
database: process.env.COMM_MYSQL_DATABASE,
};
} else {
- const importedDBConfig = await importJSON('secrets/db_config');
+ const importedDBConfig = await importJSON({
+ folder: 'secrets',
+ name: 'db_config',
+ });
invariant(importedDBConfig, 'DB config missing');
dbConfig = importedDBConfig;
}
diff --git a/keyserver/src/push/providers.js b/keyserver/src/push/providers.js
--- a/keyserver/src/push/providers.js
+++ b/keyserver/src/push/providers.js
@@ -25,7 +25,7 @@
return provider;
}
try {
- const apnConfig = await importJSON(`secrets/${profile}`);
+ const apnConfig = await importJSON({ folder: 'secrets', name: profile });
invariant(apnConfig, `APN config missing for ${profile}`);
if (!cachedAPNProviders.has(profile)) {
cachedAPNProviders.set(profile, new apn.Provider(apnConfig));
@@ -45,7 +45,7 @@
return provider;
}
try {
- const fcmConfig = await importJSON(`secrets/${profile}`);
+ const fcmConfig = await importJSON({ folder: 'secrets', name: profile });
invariant(fcmConfig, `FCM config missed for ${profile}`);
if (!cachedFCMProviders.has(profile)) {
cachedFCMProviders.set(
diff --git a/keyserver/src/utils/import-json.js b/keyserver/src/utils/import-json.js
--- a/keyserver/src/utils/import-json.js
+++ b/keyserver/src/utils/import-json.js
@@ -1,27 +1,46 @@
// @flow
+type ConfigName = {
+ +folder: 'secrets' | 'facts',
+ +name: string,
+};
+
+function getKeyForConfigName(configName: ConfigName): string {
+ return `${configName.folder}_${configName.name}`;
+}
+
+function getPathForConfigName(configName: ConfigName): string {
+ return `${configName.folder}/${configName.name}.json`;
+}
+
const cachedJSON = new Map();
-async function importJSON<T>(path: string): Promise<?T> {
- const cached = cachedJSON.get(path);
+async function importJSON<T>(configName: ConfigName): Promise<?T> {
+ const key = getKeyForConfigName(configName);
+ const cached = cachedJSON.get(key);
if (cached !== undefined) {
return cached;
}
- const json = await getJSON(path);
- if (!cachedJSON.has(path)) {
- cachedJSON.set(path, json);
+ const json = await getJSON(configName);
+ if (!cachedJSON.has(key)) {
+ cachedJSON.set(key, json);
}
- return cachedJSON.get(path);
+ return cachedJSON.get(key);
}
-async function getJSON<T>(path: string): Promise<?T> {
- const fromEnv = process.env[`COMM_JSONCONFIG_${path}`];
+async function getJSON<T>(configName: ConfigName): Promise<?T> {
+ const key = getKeyForConfigName(configName);
+ const fromEnv = process.env[`COMM_JSONCONFIG_${key}`];
if (fromEnv) {
try {
return JSON.parse(fromEnv);
} catch (e) {
- console.log(`failed to parse JSON from env for ${path}`, e);
+ console.log(
+ `failed to parse JSON from env for ${JSON.stringify(configName)}`,
+ e,
+ );
}
}
+ const path = getPathForConfigName(configName);
try {
// $FlowFixMe
const importedJSON = await import(`../../${path}`);
diff --git a/keyserver/src/utils/olm-utils.js b/keyserver/src/utils/olm-utils.js
--- a/keyserver/src/utils/olm-utils.js
+++ b/keyserver/src/utils/olm-utils.js
@@ -10,7 +10,7 @@
};
async function getOlmConfig(): Promise<OlmConfig> {
- const olmConfig = await importJSON('secrets/olm_config');
+ const olmConfig = await importJSON({ folder: 'secrets', name: 'olm_config' });
invariant(olmConfig, 'OLM config missing');
return olmConfig;
}
diff --git a/keyserver/src/utils/urls.js b/keyserver/src/utils/urls.js
--- a/keyserver/src/utils/urls.js
+++ b/keyserver/src/utils/urls.js
@@ -26,7 +26,10 @@
if (existing !== undefined) {
return existing;
}
- const urlFacts: ?AppURLFacts = await importJSON(`facts/${site}_url`);
+ const urlFacts: ?AppURLFacts = await importJSON({
+ folder: 'facts',
+ name: `${site}_url`,
+ });
cachedURLFacts.set(site, urlFacts);
return urlFacts;
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 10, 4:23 AM (15 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5860976
Default Alt Text
D4171.1765340639.diff (5 KB)
Attached To
Mode
D4171: [keyserver] Fix importJSON environmental variables to avoid special chars in name
Attached
Detach File
Event Timeline
Log In to Comment