From 2360a541e8abd68575e58c58e62566b598c213c2 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Mon, 8 Apr 2019 10:24:17 +0200 Subject: [PATCH] Initialize Minio --- BlobStorage.js | 2 +- MinioBlobStorage.js | 42 ++++++++++++------------------------------ 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/BlobStorage.js b/BlobStorage.js index ca0018573..de0eb1e03 100644 --- a/BlobStorage.js +++ b/BlobStorage.js @@ -26,7 +26,7 @@ exports.newBlobStorage = function newBlobStorage(BOT, logger) { } default: { if (ERROR_LOG === true && logger !== undefined) { - logger.write(MODULE_NAME, "[ERROR] initialize -> Storage Provider not supported -> process.env.STORAGE_PROVIDER = " + process.env.STORAGE_PROVIDER); + logger.write(MODULE_NAME, "[ERROR] newBlobStorage -> Storage Provider not supported -> process.env.STORAGE_PROVIDER = " + process.env.STORAGE_PROVIDER); } return; } diff --git a/MinioBlobStorage.js b/MinioBlobStorage.js index 8f2a2f245..9940db3f6 100644 --- a/MinioBlobStorage.js +++ b/MinioBlobStorage.js @@ -11,9 +11,6 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger) const MODULE_NAME = "Minio Blob Storage"; const SECOND_TRY_WAIT_TIME = 10000; - let MINIO_STORAGE = require('./MinioStorage') - let storage = MINIO_STORAGE.newMinioStorage(bot, logger); - let thisObject = { initialize: initialize, createFolder: createFolder, @@ -26,12 +23,23 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger) let containerName; let environment = global.CURRENT_ENVIRONMENT; + let Minio = require('minio'); + let minioClient; + return thisObject; function initialize(pDataOwner, callBackFunction, disableLogging) { try { + minioClient = new Minio.Client({ + endPoint: process.env.MINIO_END_POINT, + port: JSON.parse(process.env.MINIO_PORT), + useSSL: JSON.parse(process.env.MINIO_USE_SSL), + accessKey: process.env.MINIO_ACCESS_KEY, + secretKey: process.env.MINIO_SECRET_KEY + }) + containerName = pDataOwner.toLowerCase(); if (pDataOwner.environment !== undefined) { // This is use for data migration from one environment to the other. @@ -44,34 +52,8 @@ exports.newMinioBlobBlobStorage = function newMinioBlobBlobStorage(BOT, logger) if (FULL_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[INFO] initialize -> environment = " + environment); } if (FULL_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[INFO] initialize -> containerName = " + containerName); } + callBackFunction(global.DEFAULT_OK_RESPONSE); - - let readConnectionString = global.USER_PROFILE.storagePermissions.get(pDataOwner + "." + "READ"); - - if (readConnectionString !== undefined) { - readOnlyBlobService = storage.createBlobService(readConnectionString); - } - - let writeConnectionString = global.USER_PROFILE.storagePermissions.get(pDataOwner + "." + "WRITE"); - - if (writeConnectionString !== undefined) { - writeOnlyBlobService = storage.createBlobService(writeConnectionString); - } - - if (readOnlyBlobService !== undefined || writeOnlyBlobService !== undefined) { - - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - - } else { - - if (ERROR_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> No READ or WRITE permissions found."); } - if (ERROR_LOG === true && logger !== undefined) { logger.write(MODULE_NAME, "[ERROR] initialize -> pDataOwner = " + pDataOwner); } - - callBackFunction(global.DEFAULT_FAIL_RESPONSE); - return; - - } } catch (err) {