fix(basic.gblib): Allow MERGE keyword in storage #380. @othonlima
This commit is contained in:
parent
f2da1f8810
commit
84cc7b85cb
2 changed files with 69 additions and 21 deletions
|
@ -546,6 +546,7 @@ export class GBVMService extends GBService {
|
||||||
global[i] = this.variables[i];
|
global[i] = this.variables[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Defines local utility BASIC functions.
|
// Defines local utility BASIC functions.
|
||||||
|
|
||||||
const ubound = (gbarray) => {return gbarray ? gbarray.length - 1: 0};
|
const ubound = (gbarray) => {return gbarray ? gbarray.length - 1: 0};
|
||||||
|
@ -582,6 +583,34 @@ export class GBVMService extends GBService {
|
||||||
url = 'http://localhost:${GBVMService.API_PORT}/${min.botId}/img';
|
url = 'http://localhost:${GBVMService.API_PORT}/${min.botId}/img';
|
||||||
const img = (await createRpcClient(() => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
const img = (await createRpcClient(() => createHttpClient(url, {agent: agent}), optsRPC)).remote;
|
||||||
|
|
||||||
|
const timeout = (ms)=> {
|
||||||
|
return new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
const tokenStops = {};
|
||||||
|
|
||||||
|
// Setups refresh token mechanism.
|
||||||
|
|
||||||
|
const tokens = this.variables['tokens'];
|
||||||
|
const interval = 60; // 1 hour.
|
||||||
|
|
||||||
|
for(i in tokens) {
|
||||||
|
|
||||||
|
const token = tokens[i];
|
||||||
|
tokenStops[token] = false;
|
||||||
|
|
||||||
|
const waitAndRefreshToken = async (token) => {
|
||||||
|
await timeout(interval);
|
||||||
|
global[i] = await sys.getCustomToken({pid, token});
|
||||||
|
|
||||||
|
if (!tokenStops[token]) {
|
||||||
|
await waitAndRefreshToken(token);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
await waitAndRefreshToken(token);
|
||||||
|
}
|
||||||
|
|
||||||
${code}
|
${code}
|
||||||
|
|
||||||
// Closes handles if any.
|
// Closes handles if any.
|
||||||
|
@ -589,6 +618,15 @@ export class GBVMService extends GBService {
|
||||||
await wa.closeHandles({pid: pid});
|
await wa.closeHandles({pid: pid});
|
||||||
await sys.closeHandles({pid: pid});
|
await sys.closeHandles({pid: pid});
|
||||||
|
|
||||||
|
// Signals token refresh job to stop.
|
||||||
|
|
||||||
|
for(i in tokens) {
|
||||||
|
const token = tokens[i];
|
||||||
|
tokenStops[token] = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})();
|
})();
|
||||||
`;
|
`;
|
||||||
Fs.writeFileSync(jsfile, code);
|
Fs.writeFileSync(jsfile, code);
|
||||||
|
@ -846,26 +884,6 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
let variables = [];
|
let variables = [];
|
||||||
|
|
||||||
// Find all tokens in .gbot Config.
|
|
||||||
|
|
||||||
const strFind = ' Client ID';
|
|
||||||
const tokens = await min.core['findParam'](min.instance, strFind);
|
|
||||||
await CollectionUtil.asyncForEach(tokens, async t => {
|
|
||||||
const tokenName = t.replace(strFind, '');
|
|
||||||
try {
|
|
||||||
variables[tokenName] = await (min.adminService as any)['acquireElevatedToken']
|
|
||||||
(min.instance.instanceId, false,
|
|
||||||
tokenName,
|
|
||||||
min.core.getParam<string>(min.instance, `${tokenName} Client ID`, null),
|
|
||||||
min.core.getParam<string>(min.instance, `${tokenName} Client Secret`, null),
|
|
||||||
min.core.getParam<string>(min.instance, `${tokenName} Host`, null),
|
|
||||||
min.core.getParam<string>(min.instance, `${tokenName} Tenant`, null)
|
|
||||||
|
|
||||||
);
|
|
||||||
} catch (error) {
|
|
||||||
variables[t] = 'ERROR: Configure /setupSecurity before using token variables.';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// These variables will be automatically be available as normal BASIC variables.
|
// These variables will be automatically be available as normal BASIC variables.
|
||||||
|
|
||||||
|
@ -916,6 +934,21 @@ export class GBVMService extends GBService {
|
||||||
const sys = new SystemKeywords();
|
const sys = new SystemKeywords();
|
||||||
await dk.setFilter({ pid: pid, value: null });
|
await dk.setFilter({ pid: pid, value: null });
|
||||||
|
|
||||||
|
|
||||||
|
// Find all tokens in .gbot Config.
|
||||||
|
|
||||||
|
const strFind = ' Client ID';
|
||||||
|
const tokens = await min.core['findParam'](min.instance, strFind);
|
||||||
|
await CollectionUtil.asyncForEach(tokens, async t => {
|
||||||
|
const tokenName = t.replace(strFind, '');
|
||||||
|
try {
|
||||||
|
variables[tokenName] = await sys.getCustomToken({pid, tokenName});
|
||||||
|
} catch (error) {
|
||||||
|
variables[t] = 'ERROR: Configure /setupSecurity before using token variables.';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
sandbox['tokens'] = tokens;
|
||||||
sandbox['variables'] = variables;
|
sandbox['variables'] = variables;
|
||||||
sandbox['id'] = sys.getRandomId();
|
sandbox['id'] = sys.getRandomId();
|
||||||
sandbox['username'] = await dk.userName({ pid });
|
sandbox['username'] = await dk.userName({ pid });
|
||||||
|
|
|
@ -1594,6 +1594,21 @@ export class SystemKeywords {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getCustomToken({pid, tokenName}) :Promise<string>{
|
||||||
|
|
||||||
|
const { min, user, params, proc } = await DialogKeywords.getProcessInfo(pid);
|
||||||
|
GBLogEx.info(min, `GET TOKEN: ${tokenName}`);
|
||||||
|
|
||||||
|
return await (min.adminService as any)['acquireElevatedToken']
|
||||||
|
(min.instance.instanceId, false,
|
||||||
|
tokenName,
|
||||||
|
min.core.getParam(min.instance, `${tokenName} Client ID`, null),
|
||||||
|
min.core.getParam(min.instance, `${tokenName} Client Secret`, null),
|
||||||
|
min.core.getParam(min.instance, `${tokenName} Host`, null),
|
||||||
|
min.core.getParam(min.instance, `${tokenName} Tenant`, null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static aa;
|
static aa;
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue