fix: non user accounts throwing null for id/description and disable silly logging by default

This commit is contained in:
Alexis Tyler
2021-05-12 08:02:50 +09:30
parent e93ae30032
commit 0524c2eb80
3 changed files with 10 additions and 4 deletions
-1
View File
@@ -91,7 +91,6 @@ export class ApiManager extends EventEmitter {
this.replace('upc', apiKey, {
// @todo: fix UPC being root
userId: '0'
});
}
+6 -1
View File
@@ -10,6 +10,11 @@
*/
const isProduction = process.env.NODE_ENV === 'production';
/**
* If we're in silly logging mode.
*/
const isSilly = Boolean(process.env.SILLY);
// eslint-disable-next-line @typescript-eslint/no-empty-function
const noop = () => {};
@@ -32,7 +37,7 @@ export const logger = {
levels: ['error', 'warn', 'info', 'debug', 'trace', 'silly'],
info: isProduction ? noop : console.info,
log: isProduction ? noop : console.info,
silly: isProduction ? noop : console.debug,
silly: isProduction ? noop : (isSilly ? console.debug : noop),
timer: isProduction ? noop : console.debug,
trace: isProduction ? noop : console.debug,
transport: 'console',
+4 -2
View File
@@ -306,9 +306,11 @@ const apiKeyToUser = async (apiKey: string) => {
try {
const keyName = apiManager.getNameFromKey(apiKey);
log.silly('Found key "%s".', keyName);
// Force upc into it's own group that's not a user group
if (keyName && keyName === 'upc') {
return { name: 'upc', role: 'upc' };
return { id: -1, description: 'UPC service account', name: 'upc', role: 'upc' };
}
if (keyName) {
@@ -324,7 +326,7 @@ const apiKeyToUser = async (apiKey: string) => {
log.debug('Failed looking up API key with "%s"', (error as Error).message);
}
return { name: 'guest', role: 'guest' };
return { id: -1, description: 'A guest user', name: 'guest', role: 'guest' };
};
// Update array values when slots change