Readded support for apikey (#6382)

This commit is contained in:
SamTV12345 2024-05-14 22:36:16 +02:00 committed by GitHub
parent 2c1916ac09
commit 556c3c8e5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 74 additions and 14 deletions

View file

@ -0,0 +1,25 @@
const absolutePaths = require('../utils/AbsolutePaths');
import fs from 'fs';
import log4js from 'log4js';
const randomString = require('../utils/randomstring');
const argv = require('../utils/Cli').argv;
const settings = require('../utils/Settings');
const apiHandlerLogger = log4js.getLogger('APIHandler');
// ensure we have an apikey
export let apikey:string|null = null;
const apikeyFilename = absolutePaths.makeAbsolute(argv.apikey || './APIKEY.txt');
if(settings.authenticationMethod === 'apikey') {
try {
apikey = fs.readFileSync(apikeyFilename, 'utf8');
apiHandlerLogger.info(`Api key file read from: "${apikeyFilename}"`);
} catch (e) {
apiHandlerLogger.info(
`Api key file "${apikeyFilename}" not found. Creating with random contents.`);
apikey = randomString(32);
fs.writeFileSync(apikeyFilename, apikey!, 'utf8');
}
}