From 0524c2eb80697b9d3f3008d4d9d12a6829fe8e63 Mon Sep 17 00:00:00 2001 From: Alexis Tyler Date: Wed, 12 May 2021 08:02:50 +0930 Subject: [PATCH] fix: non user accounts throwing null for id/description and disable silly logging by default --- app/core/api-manager.ts | 1 - app/core/log.ts | 7 ++++++- app/graphql/index.ts | 6 ++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/core/api-manager.ts b/app/core/api-manager.ts index 83e74d4c7..a4522240f 100644 --- a/app/core/api-manager.ts +++ b/app/core/api-manager.ts @@ -91,7 +91,6 @@ export class ApiManager extends EventEmitter { this.replace('upc', apiKey, { // @todo: fix UPC being root userId: '0' - }); } diff --git a/app/core/log.ts b/app/core/log.ts index 6361b9e48..68b183c5d 100644 --- a/app/core/log.ts +++ b/app/core/log.ts @@ -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', diff --git a/app/graphql/index.ts b/app/graphql/index.ts index 4460bb12a..fd4d1024d 100644 --- a/app/graphql/index.ts +++ b/app/graphql/index.ts @@ -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