From 7a148aafaa4260928ba0cd79fd38114c8d5fcf36 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Fri, 25 Aug 2023 19:09:03 -0300 Subject: [PATCH] new (basic.gbapp): ALLOW ROLE keyword. --- packages/core.gbapp/services/GBDeployer.ts | 49 ++++++++++++---------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 1e43697b..431a2f9c 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -104,18 +104,25 @@ export class GBDeployer implements IGBDeployer { * Retrives token and initialize drive client API. */ public static async internalGetDriveClient(min: GBMinInstance) { - const token = await (min.adminService as any) - ['acquireElevatedToken'](min.instance.instanceId, true); - const siteId = process.env.STORAGE_SITE_ID; - const libraryId = process.env.STORAGE_LIBRARY; + let token; + if (min['cacheToken']) { + return min['cacheToken']; + } else { + token = await (min.adminService as any)['acquireElevatedToken'](min.instance.instanceId, true); - const client = MicrosoftGraph.Client.init({ - authProvider: done => { - done(null, token); - } - }); - const baseUrl = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}`; - return { baseUrl, client }; + const siteId = process.env.STORAGE_SITE_ID; + const libraryId = process.env.STORAGE_LIBRARY; + + const client = MicrosoftGraph.Client.init({ + authProvider: done => { + done(null, token); + } + }); + const baseUrl = `https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${libraryId}`; + 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. */ public async deployBlankBot(botId: string, mobile: string, email: string) { - // Creates a new row on the GuaribasInstance table. const instance = await this.importer.createBotInstance(botId); const bootInstance = GBServer.globals.bootInstance; // Gets the access token to perform service operations. - const accessToken = await - (GBServer.globals.minBoot.adminService as any)['acquireElevatedToken'] - (bootInstance.instanceId, true); + const accessToken = await (GBServer.globals.minBoot.adminService as any)['acquireElevatedToken']( + bootInstance.instanceId, + true + ); // Creates the MSFT application that will be associated to the bot. @@ -385,9 +392,7 @@ export class GBDeployer implements IGBDeployer { // Connects to MSFT storage. - const token = await - (min.adminService as any)['acquireElevatedToken'] - (min.instance.instanceId, true); + const token = await (min.adminService as any)['acquireElevatedToken'](min.instance.instanceId, true); const client = MicrosoftGraph.Client.init({ authProvider: done => { @@ -401,17 +406,16 @@ export class GBDeployer implements IGBDeployer { const path = DialogKeywords.getGBAIPath(botId, 'gbot'); 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(); // Finds Config.xlsx. - const document = res.value.filter(m => { return m.name === 'Config.xlsx'; }); 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; } @@ -446,7 +450,7 @@ export class GBDeployer implements IGBDeployer { baseUrl: string = null, client = null ): Promise { - GBLogEx.info(min ,`downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`); + GBLogEx.info(min, `downloadFolder: localPath=${localPath}, remotePath=${remotePath}, baseUrl=${baseUrl}`); if (!baseUrl) { let { baseUrl, client } = await GBDeployer.internalGetDriveClient(min); @@ -470,7 +474,6 @@ export class GBDeployer implements IGBDeployer { // Retrieves all files in remote folder. - let path = DialogKeywords.getGBAIPath(min.botId); path = urlJoin(path, remotePath); let url = `${baseUrl}/drive/root:/${path}:/children`;