pull/11/head
Dan Gowans 2025-04-03 15:30:06 -04:00
parent 7f32d0a14a
commit a5a1c9f793
6 changed files with 31 additions and 31 deletions

View File

@ -14,7 +14,8 @@ const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`);
await initializeDatabase();
const directoryName = path.dirname(fileURLToPath(import.meta.url));
const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length);
process.title = `${getConfigProperty('application.applicationName')} (Primary)`;
const applicationName = getConfigProperty('application.applicationName');
process.title = `${applicationName} (Primary)`;
debug(`Primary pid: ${process.pid}`);
debug(`Primary title: ${process.title}`);
debug(`Launching ${processCount} processes`);
@ -48,16 +49,16 @@ if (ntfyStartupConfig !== undefined) {
const topic = ntfyStartupConfig.topic;
const server = ntfyStartupConfig.server;
const ntfyStartupMessage = {
topic,
title: getConfigProperty('application.applicationName'),
message: 'Application Started',
tags: ['arrow_up']
tags: ['arrow_up'],
title: applicationName,
topic
};
const ntfyShutdownMessage = {
topic,
title: getConfigProperty('application.applicationName'),
message: 'Application Shut Down',
tags: ['arrow_down']
tags: ['arrow_down'],
title: applicationName,
topic
};
if (server !== undefined) {
ntfyStartupMessage.server = server;

View File

@ -25,7 +25,9 @@ const processCount = Math.min(
os.cpus().length
)
process.title = `${getConfigProperty('application.applicationName')} (Primary)`
const applicationName = getConfigProperty('application.applicationName')
process.title = `${applicationName} (Primary)`
debug(`Primary pid: ${process.pid}`)
debug(`Primary title: ${process.title}`)
@ -71,17 +73,17 @@ if (ntfyStartupConfig !== undefined) {
const server = ntfyStartupConfig.server
const ntfyStartupMessage: NtfyMessageOptions = {
topic,
title: getConfigProperty('application.applicationName'),
message: 'Application Started',
tags: ['arrow_up']
tags: ['arrow_up'],
title: applicationName,
topic
}
const ntfyShutdownMessage: NtfyMessageOptions = {
topic,
title: getConfigProperty('application.applicationName'),
message: 'Application Shut Down',
tags: ['arrow_down']
tags: ['arrow_down'],
title: applicationName,
topic
}
if (server !== undefined) {

View File

@ -3,10 +3,10 @@ export const config = { ...cemeteryConfig };
config.application.useTestDatabases = true;
config.session.doKeepAlive = true;
config.users = {
testing: ['*testView', '*testUpdate', '*testAdmin'],
canLogin: ['*testView', '*testUpdate', '*testAdmin'],
canUpdate: ['*testUpdate'],
isAdmin: ['*testAdmin']
isAdmin: ['*testAdmin'],
testing: ['*testView', '*testUpdate', '*testAdmin']
};
config.settings.publicInternalPath = 'public-internal';
config.settings.dynamicsGP.integrationIsEnabled = false;

View File

@ -9,10 +9,10 @@ config.application.useTestDatabases = true
config.session.doKeepAlive = true
config.users = {
testing: ['*testView', '*testUpdate', '*testAdmin'],
canLogin: ['*testView', '*testUpdate', '*testAdmin'],
canUpdate: ['*testUpdate'],
isAdmin: ['*testAdmin']
isAdmin: ['*testAdmin'],
testing: ['*testView', '*testUpdate', '*testAdmin']
}
config.settings.publicInternalPath = 'public-internal'

View File

@ -6,9 +6,7 @@ const debug = Debug(`${DEBUG_NAMESPACE}:functions.api`);
const apiKeyPath = 'data/apiKeys.json';
let apiKeys;
export async function getApiKey(userName) {
if (apiKeys === undefined) {
await loadApiKeys();
}
apiKeys ??= await loadApiKeys();
if (!Object.hasOwn(apiKeys, userName)) {
await regenerateApiKey(userName);
}
@ -18,9 +16,7 @@ export async function getApiKeyFromUser(user) {
return await getApiKey(user.userName);
}
export async function getUserNameFromApiKey(apiKey) {
if (apiKeys === undefined) {
await loadApiKeys();
}
apiKeys ??= await loadApiKeys();
for (const [userName, currentApiKey] of Object.entries(apiKeys)) {
if (apiKey === currentApiKey) {
return userName;
@ -29,6 +25,7 @@ export async function getUserNameFromApiKey(apiKey) {
return undefined;
}
export async function regenerateApiKey(userName) {
apiKeys ??= await loadApiKeys();
apiKeys[userName] = generateApiKey(userName);
await saveApiKeys();
}
@ -44,6 +41,7 @@ async function loadApiKeys() {
debug(error);
apiKeys = {};
}
return apiKeys;
}
async function saveApiKeys() {
try {

View File

@ -11,9 +11,7 @@ const apiKeyPath = 'data/apiKeys.json'
let apiKeys: Record<string, string> | undefined
export async function getApiKey(userName: string): Promise<string> {
if (apiKeys === undefined) {
await loadApiKeys()
}
apiKeys ??= await loadApiKeys()
if (!Object.hasOwn(apiKeys, userName)) {
await regenerateApiKey(userName)
@ -29,9 +27,7 @@ export async function getApiKeyFromUser(user: User): Promise<string> {
export async function getUserNameFromApiKey(
apiKey: string
): Promise<string | undefined> {
if (apiKeys === undefined) {
await loadApiKeys()
}
apiKeys ??= await loadApiKeys()
for (const [userName, currentApiKey] of Object.entries(apiKeys)) {
if (apiKey === currentApiKey) {
@ -43,6 +39,7 @@ export async function getUserNameFromApiKey(
}
export async function regenerateApiKey(userName: string): Promise<void> {
apiKeys ??= await loadApiKeys()
apiKeys[userName] = generateApiKey(userName)
await saveApiKeys()
}
@ -51,7 +48,7 @@ function generateApiKey(apiKeyPrefix: string): string {
return `${apiKeyPrefix}-${randomUUID()}-${Date.now().toString()}`
}
async function loadApiKeys(): Promise<void> {
async function loadApiKeys(): Promise<Record<string, string>> {
try {
const fileData = await fs.readFile(apiKeyPath, 'utf8')
apiKeys = JSON.parse(fileData) as Record<string, string>
@ -59,6 +56,8 @@ async function loadApiKeys(): Promise<void> {
debug(error)
apiKeys = {}
}
return apiKeys
}
async function saveApiKeys(): Promise<void> {