Merge pull request #26 from AAMasters/develop

Dinamically generate Storage Permissions
This commit is contained in:
Luis Fernando Molina authored and GitHub committed 2018-11-17 16:28:08 +01:00
commit 903f769361
5 files changed
+117 -21

No files matched your search

+5
View File
@@ -9,3 +9,8 @@ bin/*
*.cache
node_modules/*
exchange/Auth0.js
configs/Email.Config.json
configs/User.Profile.json
configs/Execution.Config.json
configs/Secret.Keys.json
+1
View File
@@ -68,6 +68,7 @@
<Compile Include="StatusReport.js">
<SubType>Code</SubType>
</Compile>
<Compile Include="StorageAccessManager.js" />
<Compile Include="TradingBotProcessMainLoop.js">
<SubType>Code</SubType>
</Compile>
+43 -16
View File
@@ -1,9 +1,7 @@
global.CURRENT_ENVIRONMENT = "Develop";
global.CURRENT_EXECUTION_AT = "Browser";
global.CURRENT_EXECUTION_AT = "Cloud";
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 */
@@ -49,25 +47,53 @@ 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'));
/* 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);
@@ -83,7 +109,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,9 +124,10 @@ function readExecutionConfiguration() {
let filePath;
try {
let fs = require('fs');
filePath = '../Execution-Config/Execution.Config.json';
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 = {
@@ -123,7 +150,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();
+63
View File
@@ -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 + "";
}
}
+5 -5
View File
@@ -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",