new (basic.gbapp): ALLOW ROLE keyword.

This commit is contained in:
Rodrigo Rodriguez 2023-08-25 19:09:03 -03:00
parent c71b616f60
commit 7a148aafaa

View file

@ -104,8 +104,12 @@ export class GBDeployer implements IGBDeployer {
* Retrives token and initialize drive client API. * Retrives token and initialize drive client API.
*/ */
public static async internalGetDriveClient(min: GBMinInstance) { public static async internalGetDriveClient(min: GBMinInstance) {
const token = await (min.adminService as any) let token;
['acquireElevatedToken'](min.instance.instanceId, true); if (min['cacheToken']) {
return min['cacheToken'];
} else {
token = await (min.adminService as any)['acquireElevatedToken'](min.instance.instanceId, true);
const siteId = process.env.STORAGE_SITE_ID; const siteId = process.env.STORAGE_SITE_ID;
const libraryId = process.env.STORAGE_LIBRARY; const libraryId = process.env.STORAGE_LIBRARY;
@ -115,7 +119,10 @@ export class GBDeployer implements IGBDeployer {
} }
}); });
const baseUrl = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}`; const baseUrl = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}`;
return { baseUrl, client }; min['cacheToken'] = { baseUrl, client };
return min['cacheToken'];
}
} }
/** /**
@ -203,16 +210,16 @@ export class GBDeployer implements IGBDeployer {
* Deploys a new blank bot to the database, cognitive services and other services. * Deploys a new blank bot to the database, cognitive services and other services.
*/ */
public async deployBlankBot(botId: string, mobile: string, email: string) { public async deployBlankBot(botId: string, mobile: string, email: string) {
// Creates a new row on the GuaribasInstance table. // Creates a new row on the GuaribasInstance table.
const instance = await this.importer.createBotInstance(botId); const instance = await this.importer.createBotInstance(botId);
const bootInstance = GBServer.globals.bootInstance; const bootInstance = GBServer.globals.bootInstance;
// Gets the access token to perform service operations. // Gets the access token to perform service operations.
const accessToken = await const accessToken = await (GBServer.globals.minBoot.adminService as any)['acquireElevatedToken'](
(GBServer.globals.minBoot.adminService as any)['acquireElevatedToken'] bootInstance.instanceId,
(bootInstance.instanceId, true); true
);
// Creates the MSFT application that will be associated to the bot. // Creates the MSFT application that will be associated to the bot.
@ -385,9 +392,7 @@ export class GBDeployer implements IGBDeployer {
// Connects to MSFT storage. // Connects to MSFT storage.
const token = await const token = await (min.adminService as any)['acquireElevatedToken'](min.instance.instanceId, true);
(min.adminService as any)['acquireElevatedToken']
(min.instance.instanceId, true);
const client = MicrosoftGraph.Client.init({ const client = MicrosoftGraph.Client.init({
authProvider: done => { authProvider: done => {
@ -401,17 +406,16 @@ export class GBDeployer implements IGBDeployer {
const path = DialogKeywords.getGBAIPath(botId, 'gbot'); const path = DialogKeywords.getGBAIPath(botId, 'gbot');
let url = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:/${path}:/children`; let url = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}/drive/root:/${path}:/children`;
GBLogEx.info( min ,`Loading .gbot from Excel: ${url}`); GBLogEx.info(min, `Loading .gbot from Excel: ${url}`);
const res = await client.api(url).get(); const res = await client.api(url).get();
// Finds Config.xlsx. // Finds Config.xlsx.
const document = res.value.filter(m => { const document = res.value.filter(m => {
return m.name === 'Config.xlsx'; return m.name === 'Config.xlsx';
}); });
if (document === undefined || document.length === 0) { if (document === undefined || document.length === 0) {
GBLogEx.info(min,`Config.xlsx not found on .bot folder, check the package.`); GBLogEx.info(min, `Config.xlsx not found on .bot folder, check the package.`);
return null; return null;
} }
@ -446,7 +450,7 @@ export class GBDeployer implements IGBDeployer {
baseUrl: string = null, baseUrl: string = null,
client = null client = null
): Promise<any> { ): Promise<any> {
GBLogEx.info(min ,`downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`); GBLogEx.info(min, `downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`);
if (!baseUrl) { if (!baseUrl) {
let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min); let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min);
@ -470,7 +474,6 @@ export class GBDeployer implements IGBDeployer {
// Retrieves all files in remote folder. // Retrieves all files in remote folder.
let path = DialogKeywords.getGBAIPath(min.botId); let path = DialogKeywords.getGBAIPath(min.botId);
path = urlJoin(path, remotePath); path = urlJoin(path, remotePath);
let url = `${baseUrl}/drive/root:/${path}:/children`; let url = `${baseUrl}/drive/root:/${path}:/children`;