fix(all): TRUE multicloud.

This commit is contained in:
Rodrigo Rodriguez 2024-08-28 19:42:12 -03:00
parent c2bdbbe140
commit 21ed20dcf0
3 changed files with 72 additions and 73 deletions

View file

@ -291,7 +291,6 @@ export class GBVMService extends GBService {
}
connections.forEach(async con => {
const connectionName = con['name'];
const dialect = con['storageDriver'];
@ -1124,7 +1123,7 @@ export class GBVMService extends GBService {
let result;
try {
if (GBConfigService.get('GBVM') === 'false') {
if (!GBConfigService.get('GBVM')) {
return await (async () => {
return await new Promise((resolve, reject) => {
sandbox['resolve'] = resolve;
@ -1145,6 +1144,7 @@ export class GBVMService extends GBService {
});
const s = new VMScript(code, { filename: scriptPath });
result = vm1.run(s);
});
})();
} else {
@ -1167,7 +1167,7 @@ export class GBVMService extends GBService {
cpu: 100,
memory: 50000,
time: 60 * 60 * 24 * 14,
cwd: gbdialogPath,
cwd: scriptPath,
script: runnerPath
});

View file

@ -76,7 +76,7 @@ export class GBConfigService {
}
}
public static get(key: string): string | undefined {
public static get(key: string) {
let value = GBConfigService.tryGet(key);
if (!value) {
@ -84,6 +84,9 @@ export class GBConfigService {
case 'PORT':
value = this.getServerPort();
break;
case 'GBVM':
value = false;
break;
case 'STORAGE_NAME':
value = null;
break;

View file

@ -314,7 +314,6 @@ export class GBDeployer implements IGBDeployer {
instance.marketplacePassword,
subscriptionId
);
}
// Saves final instance object and returns it.
@ -424,49 +423,49 @@ export class GBDeployer implements IGBDeployer {
*/
public async loadParamsFromTabular(min: GBMinInstance, filePath: string): Promise<any> {
if (!Fs.existsSync(filePath)) {
return [];
const xls = Path.join(filePath, 'Config.xlsx');
const csv = Path.join(filePath, 'config.csv');
let rows: any[] = [];
let obj: any = {};
const workbook = new Excel.Workbook();
if (Fs.existsSync(xls)) {
await workbook.xlsx.readFile(xls);
let worksheet: any;
for (let t = 0; t < workbook.worksheets.length; t++) {
worksheet = workbook.worksheets[t];
if (worksheet) {
break;
}
}
const ext = Path.extname(filePath).toLowerCase();
let rows: any[] = [];
const workbook = new Excel.Workbook();
if (ext === '.xlsx') {
await workbook.xlsx.readFile(filePath);
let worksheet: any;
for (let t = 0; t < workbook.worksheets.length; t++) {
worksheet = workbook.worksheets[t];
if (worksheet) {
break;
}
}
rows = worksheet.getSheetValues();
} else if (ext === '.csv') {
await workbook.csv.readFile(filePath);
let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet
rows = worksheet.getSheetValues();
} else {
return [];
}
GBLogEx.info(min, `Processing ${rows.length} rows from Config file ${filePath}...`);
rows = worksheet.getSheetValues();
// Skips the header lines.
for (let index = 0; index < 6; index++) {
rows.shift();
rows.shift();
}
} else if (Fs.existsSync(csv)) {
await workbook.csv.readFile(filePath);
let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet
rows = worksheet.getSheetValues();
let obj: any = {};
await asyncPromise.eachSeries(rows, async (line: any) => {
if (line && line._cells[0] && line._cells[1] && line._cells[0].text) {
obj[line._cells[0].text] = line._cells[1].text;
}
});
// Skips the header lines.
GBLogEx.info(min, GBUtil.toYAML(obj));
return obj;
rows.shift();
} else {
return [];
}
await asyncPromise.eachSeries(rows, async (line: any) => {
if (line && line.length > 0) {
obj[line[1]] = line[2];
}
});
GBLogEx.info(min, `Processing ${rows.length} rows from ${filePath}...`);
rows = null;
return obj;
}
/**
@ -624,39 +623,36 @@ export class GBDeployer implements IGBDeployer {
switch (packageType) {
case '.gbot':
// Extracts configuration information from .gbot files.
min.instance.params = await this.loadParamsFromTabular(min, localPath);
if (min.instance.params.length){
if (min.instance.params) {
let connections = [];
let connections = [];
// Find all tokens in .gbot Config.
const strFind = ' Driver';
const conns = await min.core['findParam'](min.instance, strFind);
await CollectionUtil.asyncForEach(conns, async t => {
const connectionName = t.replace(strFind, '');
let con = {};
con['name'] = connectionName;
con['storageServer'] = min.core.getParam<string>(min.instance, `${connectionName} Server`, null);
con['storageUsername'] = min.core.getParam<string>(min.instance, `${connectionName} Username`, null);
con['storageName'] = min.core.getParam<string>(min.instance, `${connectionName} Name`, null);
con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null);
con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null);
con['storageDriver'] = min.core.getParam<string>(min.instance, `${connectionName} Driver`, null);
connections.push(con);
});
// Find all tokens in .gbot Config.
const strFind = ' Driver';
const conns = await min.core['findParam'](min.instance, strFind);
await CollectionUtil.asyncForEach(conns, async t => {
const connectionName = t.replace(strFind, '');
let con = {};
con['name'] = connectionName;
(con['storageServer'] = min.core.getParam<string>(min.instance, `${connectionName} Server`, null)),
(con['storageName'] = min.core.getParam<string>(min.instance, `${connectionName} Name`, null)),
(con['storageUsername'] = min.core.getParam<string>(min.instance, `${connectionName} Username`, null)),
(con['storagePort'] = min.core.getParam<string>(min.instance, `${connectionName} Port`, null)),
(con['storagePassword'] = min.core.getParam<string>(min.instance, `${connectionName} Password`, null)),
(con['storageDriver'] = min.core.getParam<string>(min.instance, `${connectionName} Driver`, null));
connections.push(con);
});
const path = DialogKeywords.getGBAIPath(min.botId, null);
const localFolder = Path.join('work', path, 'connections.json');
Fs.writeFileSync(localFolder, JSON.stringify(connections), { encoding: null });
const path = DialogKeywords.getGBAIPath(min.botId, null);
const localFolder = Path.join('work', path, 'connections.json');
Fs.writeFileSync(localFolder, JSON.stringify(connections), { encoding: null });
// Updates instance object.
// Updates instance object.
await this.core.saveInstance(min.instance);
}
await this.core.saveInstance(min.instance);
}
break;
case '.gbkb':