linting
parent
7f32d0a14a
commit
a5a1c9f793
15
bin/www.js
15
bin/www.js
|
|
@ -14,7 +14,8 @@ const debug = Debug(`${DEBUG_NAMESPACE}:www:${process.pid}`);
|
||||||
await initializeDatabase();
|
await initializeDatabase();
|
||||||
const directoryName = path.dirname(fileURLToPath(import.meta.url));
|
const directoryName = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const processCount = Math.min(getConfigProperty('application.maximumProcesses'), os.cpus().length);
|
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 pid: ${process.pid}`);
|
||||||
debug(`Primary title: ${process.title}`);
|
debug(`Primary title: ${process.title}`);
|
||||||
debug(`Launching ${processCount} processes`);
|
debug(`Launching ${processCount} processes`);
|
||||||
|
|
@ -48,16 +49,16 @@ if (ntfyStartupConfig !== undefined) {
|
||||||
const topic = ntfyStartupConfig.topic;
|
const topic = ntfyStartupConfig.topic;
|
||||||
const server = ntfyStartupConfig.server;
|
const server = ntfyStartupConfig.server;
|
||||||
const ntfyStartupMessage = {
|
const ntfyStartupMessage = {
|
||||||
topic,
|
|
||||||
title: getConfigProperty('application.applicationName'),
|
|
||||||
message: 'Application Started',
|
message: 'Application Started',
|
||||||
tags: ['arrow_up']
|
tags: ['arrow_up'],
|
||||||
|
title: applicationName,
|
||||||
|
topic
|
||||||
};
|
};
|
||||||
const ntfyShutdownMessage = {
|
const ntfyShutdownMessage = {
|
||||||
topic,
|
|
||||||
title: getConfigProperty('application.applicationName'),
|
|
||||||
message: 'Application Shut Down',
|
message: 'Application Shut Down',
|
||||||
tags: ['arrow_down']
|
tags: ['arrow_down'],
|
||||||
|
title: applicationName,
|
||||||
|
topic
|
||||||
};
|
};
|
||||||
if (server !== undefined) {
|
if (server !== undefined) {
|
||||||
ntfyStartupMessage.server = server;
|
ntfyStartupMessage.server = server;
|
||||||
|
|
|
||||||
16
bin/www.ts
16
bin/www.ts
|
|
@ -25,7 +25,9 @@ const processCount = Math.min(
|
||||||
os.cpus().length
|
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 pid: ${process.pid}`)
|
||||||
debug(`Primary title: ${process.title}`)
|
debug(`Primary title: ${process.title}`)
|
||||||
|
|
@ -71,17 +73,17 @@ if (ntfyStartupConfig !== undefined) {
|
||||||
const server = ntfyStartupConfig.server
|
const server = ntfyStartupConfig.server
|
||||||
|
|
||||||
const ntfyStartupMessage: NtfyMessageOptions = {
|
const ntfyStartupMessage: NtfyMessageOptions = {
|
||||||
topic,
|
|
||||||
title: getConfigProperty('application.applicationName'),
|
|
||||||
message: 'Application Started',
|
message: 'Application Started',
|
||||||
tags: ['arrow_up']
|
tags: ['arrow_up'],
|
||||||
|
title: applicationName,
|
||||||
|
topic
|
||||||
}
|
}
|
||||||
|
|
||||||
const ntfyShutdownMessage: NtfyMessageOptions = {
|
const ntfyShutdownMessage: NtfyMessageOptions = {
|
||||||
topic,
|
|
||||||
title: getConfigProperty('application.applicationName'),
|
|
||||||
message: 'Application Shut Down',
|
message: 'Application Shut Down',
|
||||||
tags: ['arrow_down']
|
tags: ['arrow_down'],
|
||||||
|
title: applicationName,
|
||||||
|
topic
|
||||||
}
|
}
|
||||||
|
|
||||||
if (server !== undefined) {
|
if (server !== undefined) {
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ export const config = { ...cemeteryConfig };
|
||||||
config.application.useTestDatabases = true;
|
config.application.useTestDatabases = true;
|
||||||
config.session.doKeepAlive = true;
|
config.session.doKeepAlive = true;
|
||||||
config.users = {
|
config.users = {
|
||||||
testing: ['*testView', '*testUpdate', '*testAdmin'],
|
|
||||||
canLogin: ['*testView', '*testUpdate', '*testAdmin'],
|
canLogin: ['*testView', '*testUpdate', '*testAdmin'],
|
||||||
canUpdate: ['*testUpdate'],
|
canUpdate: ['*testUpdate'],
|
||||||
isAdmin: ['*testAdmin']
|
isAdmin: ['*testAdmin'],
|
||||||
|
testing: ['*testView', '*testUpdate', '*testAdmin']
|
||||||
};
|
};
|
||||||
config.settings.publicInternalPath = 'public-internal';
|
config.settings.publicInternalPath = 'public-internal';
|
||||||
config.settings.dynamicsGP.integrationIsEnabled = false;
|
config.settings.dynamicsGP.integrationIsEnabled = false;
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,10 @@ config.application.useTestDatabases = true
|
||||||
config.session.doKeepAlive = true
|
config.session.doKeepAlive = true
|
||||||
|
|
||||||
config.users = {
|
config.users = {
|
||||||
testing: ['*testView', '*testUpdate', '*testAdmin'],
|
|
||||||
canLogin: ['*testView', '*testUpdate', '*testAdmin'],
|
canLogin: ['*testView', '*testUpdate', '*testAdmin'],
|
||||||
canUpdate: ['*testUpdate'],
|
canUpdate: ['*testUpdate'],
|
||||||
isAdmin: ['*testAdmin']
|
isAdmin: ['*testAdmin'],
|
||||||
|
testing: ['*testView', '*testUpdate', '*testAdmin']
|
||||||
}
|
}
|
||||||
|
|
||||||
config.settings.publicInternalPath = 'public-internal'
|
config.settings.publicInternalPath = 'public-internal'
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,7 @@ const debug = Debug(`${DEBUG_NAMESPACE}:functions.api`);
|
||||||
const apiKeyPath = 'data/apiKeys.json';
|
const apiKeyPath = 'data/apiKeys.json';
|
||||||
let apiKeys;
|
let apiKeys;
|
||||||
export async function getApiKey(userName) {
|
export async function getApiKey(userName) {
|
||||||
if (apiKeys === undefined) {
|
apiKeys ??= await loadApiKeys();
|
||||||
await loadApiKeys();
|
|
||||||
}
|
|
||||||
if (!Object.hasOwn(apiKeys, userName)) {
|
if (!Object.hasOwn(apiKeys, userName)) {
|
||||||
await regenerateApiKey(userName);
|
await regenerateApiKey(userName);
|
||||||
}
|
}
|
||||||
|
|
@ -18,9 +16,7 @@ export async function getApiKeyFromUser(user) {
|
||||||
return await getApiKey(user.userName);
|
return await getApiKey(user.userName);
|
||||||
}
|
}
|
||||||
export async function getUserNameFromApiKey(apiKey) {
|
export async function getUserNameFromApiKey(apiKey) {
|
||||||
if (apiKeys === undefined) {
|
apiKeys ??= await loadApiKeys();
|
||||||
await loadApiKeys();
|
|
||||||
}
|
|
||||||
for (const [userName, currentApiKey] of Object.entries(apiKeys)) {
|
for (const [userName, currentApiKey] of Object.entries(apiKeys)) {
|
||||||
if (apiKey === currentApiKey) {
|
if (apiKey === currentApiKey) {
|
||||||
return userName;
|
return userName;
|
||||||
|
|
@ -29,6 +25,7 @@ export async function getUserNameFromApiKey(apiKey) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
export async function regenerateApiKey(userName) {
|
export async function regenerateApiKey(userName) {
|
||||||
|
apiKeys ??= await loadApiKeys();
|
||||||
apiKeys[userName] = generateApiKey(userName);
|
apiKeys[userName] = generateApiKey(userName);
|
||||||
await saveApiKeys();
|
await saveApiKeys();
|
||||||
}
|
}
|
||||||
|
|
@ -44,6 +41,7 @@ async function loadApiKeys() {
|
||||||
debug(error);
|
debug(error);
|
||||||
apiKeys = {};
|
apiKeys = {};
|
||||||
}
|
}
|
||||||
|
return apiKeys;
|
||||||
}
|
}
|
||||||
async function saveApiKeys() {
|
async function saveApiKeys() {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,7 @@ const apiKeyPath = 'data/apiKeys.json'
|
||||||
let apiKeys: Record<string, string> | undefined
|
let apiKeys: Record<string, string> | undefined
|
||||||
|
|
||||||
export async function getApiKey(userName: string): Promise<string> {
|
export async function getApiKey(userName: string): Promise<string> {
|
||||||
if (apiKeys === undefined) {
|
apiKeys ??= await loadApiKeys()
|
||||||
await loadApiKeys()
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Object.hasOwn(apiKeys, userName)) {
|
if (!Object.hasOwn(apiKeys, userName)) {
|
||||||
await regenerateApiKey(userName)
|
await regenerateApiKey(userName)
|
||||||
|
|
@ -29,9 +27,7 @@ export async function getApiKeyFromUser(user: User): Promise<string> {
|
||||||
export async function getUserNameFromApiKey(
|
export async function getUserNameFromApiKey(
|
||||||
apiKey: string
|
apiKey: string
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
if (apiKeys === undefined) {
|
apiKeys ??= await loadApiKeys()
|
||||||
await loadApiKeys()
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const [userName, currentApiKey] of Object.entries(apiKeys)) {
|
for (const [userName, currentApiKey] of Object.entries(apiKeys)) {
|
||||||
if (apiKey === currentApiKey) {
|
if (apiKey === currentApiKey) {
|
||||||
|
|
@ -43,6 +39,7 @@ export async function getUserNameFromApiKey(
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function regenerateApiKey(userName: string): Promise<void> {
|
export async function regenerateApiKey(userName: string): Promise<void> {
|
||||||
|
apiKeys ??= await loadApiKeys()
|
||||||
apiKeys[userName] = generateApiKey(userName)
|
apiKeys[userName] = generateApiKey(userName)
|
||||||
await saveApiKeys()
|
await saveApiKeys()
|
||||||
}
|
}
|
||||||
|
|
@ -51,7 +48,7 @@ function generateApiKey(apiKeyPrefix: string): string {
|
||||||
return `${apiKeyPrefix}-${randomUUID()}-${Date.now().toString()}`
|
return `${apiKeyPrefix}-${randomUUID()}-${Date.now().toString()}`
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadApiKeys(): Promise<void> {
|
async function loadApiKeys(): Promise<Record<string, string>> {
|
||||||
try {
|
try {
|
||||||
const fileData = await fs.readFile(apiKeyPath, 'utf8')
|
const fileData = await fs.readFile(apiKeyPath, 'utf8')
|
||||||
apiKeys = JSON.parse(fileData) as Record<string, string>
|
apiKeys = JSON.parse(fileData) as Record<string, string>
|
||||||
|
|
@ -59,6 +56,8 @@ async function loadApiKeys(): Promise<void> {
|
||||||
debug(error)
|
debug(error)
|
||||||
apiKeys = {}
|
apiKeys = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return apiKeys
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveApiKeys(): Promise<void> {
|
async function saveApiKeys(): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue