diff --git a/Assistant.js b/Assistant.js index 232e61610..f5e86c857 100644 --- a/Assistant.js +++ b/Assistant.js @@ -1358,45 +1358,8 @@ } function sendEmail(pTitle, pBody, pTo) { - try { - - /** - Email configuration is not available when running the bot on the browser. - */ - if (global.CURRENT_EXECUTION_AT === "Browser") { - logger.write(MODULE_NAME, "[WARN] sendEmail -> Send emails is disabled from the browser."); - return; - } - - let emailList = pTo; //TODO Pending to add spam controller - let runIndex = context.statusReport.runs.length - 1; - - let transporter = nodemailer.createTransport({ - service: global.EMAIL_CONFIG.service, - auth: { - user: global.EMAIL_CONFIG.user, - pass: global.EMAIL_CONFIG.pass - } - }); - - let mailOptions = { - from: global.EMAIL_CONFIG.from, - bcc: emailList, - subject: bot.startMode + "." + runIndex + ' - ' + pTitle, - text: pBody - }; - - transporter.sendMail(mailOptions, function (error, info) { - if (error) { - logger.write(MODULE_NAME, "[ERROR] sendEmail -> err = " + error); - } else { - logger.write(MODULE_NAME, "[INFO] sendEmail -> Email sent = " + info.response); - } - }); - - } catch (err) { - logger.write(MODULE_NAME, "[ERROR] sendEmail -> err = " + err.message); - } + logger.write(MODULE_NAME, "[WARN] sendEmail -> Send emails is currently disabled."); + return; } function truncDecimals(pFloatValue, pDecimals) { diff --git a/Integrations/OperationsModuleIntegration.js b/Integrations/OperationsModuleIntegration.js index 41c4642c7..b8de71616 100644 --- a/Integrations/OperationsModuleIntegration.js +++ b/Integrations/OperationsModuleIntegration.js @@ -10,7 +10,7 @@ exports.updateExecutionResults = async function (summaryDate, buyAverage, sellAv try { - const authResponse = await auth.authenticate() + const accessToken = await auth.authenticate() const operationsResponse = await axios({ url: process.env.GATEWAY_ENDPOINT, @@ -46,11 +46,13 @@ exports.updateExecutionResults = async function (summaryDate, buyAverage, sellAv }, }, headers: { - authorization: 'Bearer ' + authResponse.data.access_token + authorization: 'Bearer ' + accessToken } }) - logger.debug('updateExecutionResults -> Operations Module Response: %s', operationsResponse.data.data.operations_UpdateExecutionSummary) + if (!operationsResponse.data.errors) + logger.debug('updateExecutionResults -> Operations Module Response: %s', operationsResponse.data.data.operations_UpdateExecutionSummary) + else throw new Error(operationsResponse.data.errors[0].message) } catch (error) { logger.error('updateExecutionResults -> Error: ' + error.stack) diff --git a/Project.njsproj b/Project.njsproj index c8f20791c..fe4d8f923 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -85,13 +85,11 @@ - - diff --git a/Root.js b/Root.js index d07ebb858..86486ae54 100644 --- a/Root.js +++ b/Root.js @@ -841,11 +841,11 @@ exports.newRoot = function newRoot() { } - let clonName = "Clon" + clonKey; + let clonName = botConfig.codeName + "-" + "Clon" + clonKey + "-" + process.env.CLONE_ID; - botConfig.filePathRoot = botConfig.devTeam + "/" + botConfig.codeName + "-" + clonName + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; + botConfig.filePathRoot = botConfig.devTeam + "/" + clonName + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; - botConfig.instance = "Clon" + clonKey; + botConfig.instance = clonName; botConfig.instanceIndex = i; setTimeout(execute, i * Math.random() * 10 * 1000); @@ -861,7 +861,11 @@ exports.newRoot = function newRoot() { /* If the bot does not have any genes at all */ let genes = {}; - pBotConfig.instance = "Master"; + let clonName = botConfig.codeName + "-" + process.env.CLONE_ID; + + botConfig.filePathRoot = botConfig.devTeam + "/" + clonName + "/" + global.PLATFORM_CONFIG.codeName + "." + global.PLATFORM_CONFIG.version.major + "." + global.PLATFORM_CONFIG.version.minor + "/" + global.EXCHANGE_NAME + "/" + botConfig.dataSetVersion; + + pBotConfig.instance = clonName; pBotConfig.instanceIndex = 0; createBotInstance(genes, 1, pBotConfig); diff --git a/Run.js b/Run.js index 1dd32de50..2abe7cb4c 100644 --- a/Run.js +++ b/Run.js @@ -47,7 +47,6 @@ function readExecutionConfiguration() { // Environment Configuration global.CURRENT_ENVIRONMENT = process.env.PLATFORM_ENVIRONMENT global.GATEWAY_ENDPOINT = process.env.GATEWAY_ENDPOINT - global.STORAGE_URL = process.env.STORAGE_URL // General Financial Being Configuration global.DEV_TEAM = process.env.DEV_TEAM @@ -182,8 +181,9 @@ function readStoragePermissions() { global.USER_PROFILE.storagePermissions = permissionsMap; global.USER_PROFILE.connectionString = ""; + process.env.STORAGE_CONNECTION_STRING = ""; - readEmailConfiguration(); + startRoot(); } } @@ -193,25 +193,6 @@ function readStoragePermissions() { } } -function readEmailConfiguration() { - - let filePath; - - try { - console.log( "Run : [INFO] readEmailConfiguration -> Entering function. "); - - let fs = require('fs'); - filePath = './' + 'configs' + '/' + 'Email.Config.json'; - global.EMAIL_CONFIG = JSON.parse(fs.readFileSync(filePath, 'utf8')); - - startRoot(); - } - catch (err) { - console.log("[ERROR] Run -> readEmailConfiguration -> err = " + err.message); - console.log("[HINT] Run -> You need to have a file at this path -> " + filePath); - } -} - function startRoot() { console.log( "[INFO] Run -> startRoot -> Entering function. "); diff --git a/exchange/ExchangeAPI.js b/exchange/ExchangeAPI.js index a2d728c97..2ad5eddfd 100644 --- a/exchange/ExchangeAPI.js +++ b/exchange/ExchangeAPI.js @@ -39,9 +39,9 @@ let exchange = botExchange.toLowerCase() + 'Client.js'; let api = require('./wrappers/' + exchange); - const authResponse = await auth.authenticate() + const accessToken = await auth.authenticate() - let keyVaultAPI = createKeyVaultAPIClient(authResponse.data.access_token) + let keyVaultAPI = createKeyVaultAPIClient(accessToken) apiClient = api.newAPIClient(keyVaultAPI, logger); callBackFunction(global.DEFAULT_OK_RESPONSE); diff --git a/utils/auth.js b/utils/auth.js index 114a25e9e..c7f0b8d87 100644 --- a/utils/auth.js +++ b/utils/auth.js @@ -2,22 +2,36 @@ const appRoot = require('app-root-path') const { logger } = require(`${appRoot}/utils/logger`) -exports.authenticate = function () { +exports.authenticate = async function () { try { - logger.debug('authenticate -> Entering Function.') - const authBody = '{"client_id":"' + process.env.AUTH_CLIENT_ID - + '","client_secret": "' + process.env.AUTH_CLIENT_SECRET - + '","audience":"' + process.env.AUTH_AUDIENCE - + '","grant_type":"client_credentials"}' + if (!global.ACCESS_TOKEN) { + logger.debug('authenticate -> Entering Function.') - return axios({ - url: process.env.AUTH_URL, - method: 'post', - data: authBody, - headers: { 'content-type': 'application/json' } - }) + const authBody = '{"client_id":"' + process.env.AUTH_CLIENT_ID + + '","client_secret": "' + process.env.AUTH_CLIENT_SECRET + + '","audience":"' + process.env.AUTH_AUDIENCE + + '","grant_type":"client_credentials"}' + let authResponse = await axios({ + url: process.env.AUTH_URL, + method: 'post', + data: authBody, + headers: { 'content-type': 'application/json' } + }) + + if (!authResponse.data.errors) + global.ACCESS_TOKEN = authResponse.data.access_token + else throw new Error(operationsResponse.data.errors[0].message) + + process.env.AUTH_CLIENT_ID = "" + process.env.AUTH_CLIENT_SECRET = "" + process.env.AUTH_AUDIENCE = "" + process.env.AUTH_URL = "" + } + + return global.ACCESS_TOKEN + } catch (error) { logger.error('authenticate -> Error: ' + error.stack) throw new Error('There has been an error on the authentication: ' + error)