From 15d4e06a0fe3e7e40806fe8330b8fad5984a4f54 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Nov 2018 09:04:11 +0100 Subject: [PATCH 1/6] Email and Profile Config files now inside AACloud Folder Structure --- .gitignore | 3 +++ Run.js | 6 +++--- this.config.json | 10 +++++----- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 402b59b95..54bc08006 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ bin/* *.cache node_modules/* exchange/Auth0.js +Email-Config/Email.Config.json +Execution.Config.json +User-Profile/User.Profile.json diff --git a/Run.js b/Run.js index 937991c36..c0c86ad7c 100644 --- a/Run.js +++ b/Run.js @@ -49,7 +49,7 @@ function readStoragePermissions() { console.log( "[INFO] Run -> readStoragePermissions -> Entering function. "); let fs = require('fs'); - filePath = '../' + 'User-Profile' + '/' + 'User.Profile.json'; + filePath = './' + 'User-Profile' + '/' + 'User.Profile.json'; global.USER_PROFILE = JSON.parse(fs.readFileSync(filePath, 'utf8')); @@ -83,7 +83,7 @@ function readEmailConfiguration() { console.log( "Run : [INFO] readEmailConfiguration -> Entering function. "); let fs = require('fs'); - filePath = '../' + 'Email-Config' + '/' + 'Email.Config.json'; + filePath = './' + 'Email-Config' + '/' + 'Email.Config.json'; global.EMAIL_CONFIG = JSON.parse(fs.readFileSync(filePath, 'utf8')); readExecutionConfiguration(); @@ -98,7 +98,7 @@ function readExecutionConfiguration() { let filePath; try { let fs = require('fs'); - filePath = '../Execution-Config/Execution.Config.json'; + filePath = 'Execution.Config.json'; let executionProperties = JSON.parse(fs.readFileSync(filePath, 'utf8')); global.DEV_TEAM = executionProperties.devTeam; global.EXCHANGE_NAME = executionProperties.exchangeName; diff --git a/this.config.json b/this.config.json index 3a23977c8..d4a37b864 100644 --- a/this.config.json +++ b/this.config.json @@ -14,35 +14,35 @@ "repo": "AAMariam-Trading-Bot" }, { - "enabled": "true", + "enabled": "false", "devTeam": "AAMasters", "bot": "AACharly", "process": "Poloniex-Live-Trades", "repo": "AACharly-Extraction-Bot" }, { - "enabled": "true", + "enabled": "false", "devTeam": "AAMasters", "bot": "AACharly", "process": "Poloniex-Hole-Fixing", "repo": "AACharly-Extraction-Bot" }, { - "enabled": "true", + "enabled": "false", "devTeam": "AAMasters", "bot": "AABruce", "process": "One-Min-Daily-Candles-Volumes", "repo": "AABruce-Indicator-Bot" }, { - "enabled": "true", + "enabled": "false", "devTeam": "AAMasters", "bot": "AAOlivia", "process": "Multi-Period-Daily", "repo": "AAOlivia-Indicator-Bot" }, { - "enabled": "true", + "enabled": "false", "devTeam": "AAMasters", "bot": "AAOlivia", "process": "Multi-Period-Market", From 7dc099cbdf218a0baf4654b82ddfe9371fe0ad2e Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Nov 2018 09:09:51 +0100 Subject: [PATCH 2/6] One folder for all configs --- .gitignore | 7 ++++--- Run.js | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 54bc08006..52053745f 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ bin/* *.cache node_modules/* exchange/Auth0.js -Email-Config/Email.Config.json -Execution.Config.json -User-Profile/User.Profile.json +configs/Email.Config.json + +configs/User.Profile.json +configs/Execution.Config.json diff --git a/Run.js b/Run.js index c0c86ad7c..03e0ffdfc 100644 --- a/Run.js +++ b/Run.js @@ -49,7 +49,7 @@ function readStoragePermissions() { console.log( "[INFO] Run -> readStoragePermissions -> Entering function. "); let fs = require('fs'); - filePath = './' + 'User-Profile' + '/' + 'User.Profile.json'; + filePath = './' + 'configs' + '/' + 'User.Profile.json'; global.USER_PROFILE = JSON.parse(fs.readFileSync(filePath, 'utf8')); @@ -83,7 +83,7 @@ function readEmailConfiguration() { console.log( "Run : [INFO] readEmailConfiguration -> Entering function. "); let fs = require('fs'); - filePath = './' + 'Email-Config' + '/' + 'Email.Config.json'; + filePath = './' + 'configs' + '/' + 'Email.Config.json'; global.EMAIL_CONFIG = JSON.parse(fs.readFileSync(filePath, 'utf8')); readExecutionConfiguration(); @@ -98,7 +98,7 @@ function readExecutionConfiguration() { let filePath; try { let fs = require('fs'); - filePath = 'Execution.Config.json'; + filePath = './configs/Execution.Config.json'; let executionProperties = JSON.parse(fs.readFileSync(filePath, 'utf8')); global.DEV_TEAM = executionProperties.devTeam; global.EXCHANGE_NAME = executionProperties.exchangeName; From 0a406e7ad32f0f743417618e640ab47f866c479b Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Nov 2018 09:23:55 +0100 Subject: [PATCH 3/6] Keys also read from the same config folder --- .gitignore | 1 + Run.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 52053745f..d9043d22a 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ configs/Email.Config.json configs/User.Profile.json configs/Execution.Config.json +configs/Secret.Keys.json diff --git a/Run.js b/Run.js index 03e0ffdfc..56f3bfd7f 100644 --- a/Run.js +++ b/Run.js @@ -123,7 +123,7 @@ function readExchangeAPIKey() { console.log( "[INFO] Run -> readExchangeAPIKey -> Entering function. "); let fs = require('fs'); - let filePath = '../' + 'Exchange-Keys' + '/' + 'Secret.Keys' + '.json'; + let filePath = './configs/Secret.Keys' + '.json'; global.EXCHANGE_KEYS = JSON.parse(fs.readFileSync(filePath, 'utf8')); startRoot(); From 68e4a0011469a0c0908412deb3b29e6bc73590c6 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Nov 2018 11:08:06 +0100 Subject: [PATCH 4/6] LOGGED IN USER taken from Execution Config File --- Run.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Run.js b/Run.js index 56f3bfd7f..3a49cb7fc 100644 --- a/Run.js +++ b/Run.js @@ -2,8 +2,6 @@ global.CURRENT_ENVIRONMENT = "Develop"; global.CURRENT_EXECUTION_AT = "Browser"; global.SHALL_BOT_STOP = false; -global.USER_LOGGED_IN = "Ciencias"; -global.DEV_TEAM = "AAMasters"; global.AT_BREAKPOINT = false; // This is used only when running at the browser. /* Default parameters can be changed by the execution configuration */ @@ -101,6 +99,7 @@ function readExecutionConfiguration() { filePath = './configs/Execution.Config.json'; let executionProperties = JSON.parse(fs.readFileSync(filePath, 'utf8')); global.DEV_TEAM = executionProperties.devTeam; + global.USER_LOGGED_IN = executionProperties.userName; global.EXCHANGE_NAME = executionProperties.exchangeName; global.MARKET = executionProperties.market; global.EXECUTION_CONFIG = { From f2e042e7a3d2c34888fcd643d754a04249d8299a Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Nov 2018 11:35:57 +0100 Subject: [PATCH 5/6] By default it should run at the CLOUD --- Run.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Run.js b/Run.js index 3a49cb7fc..6b2399998 100644 --- a/Run.js +++ b/Run.js @@ -1,6 +1,6 @@  global.CURRENT_ENVIRONMENT = "Develop"; -global.CURRENT_EXECUTION_AT = "Browser"; +global.CURRENT_EXECUTION_AT = "Cloud"; global.SHALL_BOT_STOP = false; global.AT_BREAKPOINT = false; // This is used only when running at the browser. From 9725ec52db0469da81c6924a804b1f91610c3cc8 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sat, 17 Nov 2018 16:14:42 +0100 Subject: [PATCH 6/6] Generate Dinamically Storage Permissions --- Project.njsproj | 1 + Run.js | 46 ++++++++++++++++++++++++------ StorageAccessManager.js | 63 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+), 9 deletions(-) create mode 100644 StorageAccessManager.js diff --git a/Project.njsproj b/Project.njsproj index 516525a6d..c6a345349 100644 --- a/Project.njsproj +++ b/Project.njsproj @@ -68,6 +68,7 @@ Code + Code diff --git a/Run.js b/Run.js index 6b2399998..f930cb063 100644 --- a/Run.js +++ b/Run.js @@ -50,22 +50,50 @@ function readStoragePermissions() { filePath = './' + 'configs' + '/' + 'User.Profile.json'; global.USER_PROFILE = JSON.parse(fs.readFileSync(filePath, 'utf8')); + /* Dinamically generating the azure storage permissions for the bot to run */ - /* Here we will rearrange the storage permissions array into a map, so that it can be easily consumed when needed. */ + const MAX_STORAGE_PERMISSION_DAYS = 10; + const STORAGE_ACCESS_MANAGER = require('./StorageAccessManager'); + storageAccessManager = STORAGE_ACCESS_MANAGER.newStorageAccessManager(); - let permissionsMap = new Map; + storageAccessManager.initialize(global.USER_PROFILE.connectionString, onInitialized); - for (i = 0; i < global.USER_PROFILE.storagePermissions.length; i++) { + function onInitialized() { - let permission = global.USER_PROFILE.storagePermissions[i]; + /* Here we will rearrange the storage permissions array into a map, so that it can be easily consumed when needed. */ - permissionsMap.set(permission[0], permission[1]); + let permissionsMap = new Map; + + let containers = ["AAPlatform", "AAVikings", global.USER_PROFILE.teamName] + let container; + let key; + let value; + + for (let i = 0; i < containers.length; i++) { + + container = containers[i]; + let readPermission = storageAccessManager.getPermission(container.toLowerCase(), "READ", MAX_STORAGE_PERMISSION_DAYS); + + key = container + ".READ"; + value = readPermission; + + permissionsMap.set(key, value); + + } + + let writePermission = storageAccessManager.getPermission(container.toLowerCase(), "WRITE", MAX_STORAGE_PERMISSION_DAYS); + + key = container + ".WRITE"; + value = writePermission; + + permissionsMap.set(key, value); + + global.USER_PROFILE.storagePermissions = permissionsMap; + global.USER_PROFILE.connectionString = ""; + + readEmailConfiguration(); } - - global.USER_PROFILE.storagePermissions = permissionsMap; - - readEmailConfiguration(); } catch (err) { console.log("[ERROR] Run -> readStoragePermissions -> err = " + err.message); diff --git a/StorageAccessManager.js b/StorageAccessManager.js new file mode 100644 index 000000000..ae4ad9a67 --- /dev/null +++ b/StorageAccessManager.js @@ -0,0 +1,63 @@ +exports.newStorageAccessManager = function newStorageAccessManager() { + + let thisObject = { + getPermission: getPermission, + initialize: initialize + } + + let connectionString; + + return thisObject; + + function initialize(pConnectionString, callBackFunction) { + + connectionString = pConnectionString; + + callBackFunction(); + } + + function getPermission(pContainer, pType, pDays) { + + let azure = require('azure-storage'); + let blobService = azure.createBlobService(connectionString); + + let startDate = new Date(); + startDate.setDate(startDate.getDate() - 1); + + let expiryDate = new Date(startDate); + expiryDate.setDate(startDate.getDate() + pDays); + + let azurePermissions; + + switch (pType) { + case "READ": { + azurePermissions = azure.BlobUtilities.SharedAccessPermissions.READ; + break; + } + case "WRITE": { + azurePermissions = azure.BlobUtilities.SharedAccessPermissions.WRITE; + break; + } + case "DELETE": { + azurePermissions = azure.BlobUtilities.SharedAccessPermissions.DELETE; + break; + } + } + + let blobName = undefined; + + let sharedAccessPolicy = { + AccessPolicy: { + Permissions: azurePermissions, + Start: startDate, + Expiry: expiryDate + } + }; + + let sasToken = blobService.generateSharedAccessSignature(pContainer, blobName, sharedAccessPolicy); + + return "BlobEndpoint=https://aadevelop.blob.core.windows.net;SharedAccessSignature=" + sasToken + ""; + + } +} +