Refactor S3 argument parsing
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Lauri Võsandi 2022-08-25 08:31:08 +03:00
parent ec59a423bb
commit 2908a0bed0

View File

@ -8,8 +8,12 @@ const mongoCollection = process.env.MONGO_COLLECTION || 'eventlog';
const mongoUri = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/default?replicaSet=rs0'; const mongoUri = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/default?replicaSet=rs0';
// Minio set-up variables // Minio set-up variables
const minioURI = new URL(process.env.MINIO_URI || 'http://kspace-mugshot:2mSI6HdbJ8@127.0.0.1:9000/kspace-mugshot'); const minioAccessKey = process.env.MINIO_ACCESS_KEY || 'kspace-mugshot';
const minioBucket = minioURI.pathname.substring(1); const minioSecretKey = process.env.MINIO_SECRET_KEY || '2mSI6HdbJ8';
const minioHostname = process.env.MINIO_HOSTNAME || '127.0.0.1';
const minioPort = process.env.MINIO_PORT || 9000;
const minioScheme = process.env.MINIO_SCHEME || 'http';
const minioBucket = process.env.MINIO_BUCKET || 'kspace-mugshot';
console.info("Using bucket:", minioBucket); console.info("Using bucket:", minioBucket);
const historyNumber = parseInt(process.env.HISTORY_AMOUNT) || 10; const historyNumber = parseInt(process.env.HISTORY_AMOUNT) || 10;
@ -34,15 +38,18 @@ async function run() {
changeStream = collection.watch(pipeline, options); changeStream = collection.watch(pipeline, options);
console.log("Started watching changes in database"); console.log("Started watching changes in database");
console.log("Minio hostname:", minioHostname);
console.log("Minio port:", minioPort);
console.log("Minio protocol:", minioScheme);
// Triggers on GET at /event route // Triggers on GET at /event route
app.get('/events', async function (request, response) { app.get('/events', async function (request, response) {
let minioClient = new minio.Client({ let minioClient = new minio.Client({
endPoint: minioURI.hostname, endPoint: minioHostname,
port: parseInt(minioURI.port) || (minioURI.protocol == 'https:' ? 443 : 80), port: parseInt(minioPort),
useSSL: minioURI.protocol == 'https:', useSSL: minioScheme == 'https',
accessKey: minioURI.username, accessKey: minioAccessKey,
secretKey: minioURI.password secretKey: minioSecretKey
}); });
async function wrapEvent(doc) { async function wrapEvent(doc) {