From d664245853e3562151a337eaaebc980f7b42f9d1 Mon Sep 17 00:00:00 2001 From: Wenyi Luo Date: Thu, 21 May 2020 23:57:33 +0800 Subject: [PATCH 1/2] send endpointkey to runtime --- .../server/src/models/bot/luPublisher.ts | 19 +++++++++++++++++++ Composer/plugins/localPublish/src/index.ts | 10 ++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Composer/packages/server/src/models/bot/luPublisher.ts b/Composer/packages/server/src/models/bot/luPublisher.ts index 686aff1602..87a3bf04a0 100644 --- a/Composer/packages/server/src/models/bot/luPublisher.ts +++ b/Composer/packages/server/src/models/bot/luPublisher.ts @@ -2,6 +2,8 @@ // Licensed under the MIT License. import { FileInfo } from '@bfc/shared'; +// import * as rp from 'request-promise'; +import axios, { AxiosRequestConfig } from 'axios'; import { Path } from '../../utility/path'; import { IFileStorage } from '../storage/interface'; @@ -167,8 +169,25 @@ export class LuPublisher { loadResult.settings ); await this.builder.writeDialogAssets(buildResult, true, this.generatedFolderPath); + // authoring luis application, make endpointKey can query the application + await this._auth(config.authoringKey, config.region); } + private _auth = async (authoringKey: string, region: string) => { + try { + const luisEndpoint = `https://${region}.api.cognitive.microsoft.com`; + // Assign a LUIS key to the endpoint of each app + const getAccountUri = `${luisEndpoint}/luis/api/v2.0/azureaccounts`; + const options = { + headers: { Authorization: `Bearer ${token}`, 'Ocp-Apim-Subscription-Key': authoringKey }, + } as AxiosRequestConfig; + const response = await axios.get(getAccountUri, options); + console.log(response); + } catch (err) { + console.log(err); + } + }; + //delete files in generated folder private async _deleteDir(path: string) { if (await this.storage.exists(path)) { diff --git a/Composer/plugins/localPublish/src/index.ts b/Composer/plugins/localPublish/src/index.ts index 8c997e4f97..ca5fde39c8 100644 --- a/Composer/plugins/localPublish/src/index.ts +++ b/Composer/plugins/localPublish/src/index.ts @@ -289,14 +289,8 @@ class LocalPublisher implements PublishPlugin { configList.push(config.MicrosoftAppPassword); } if (config.luis) { - if (config.luis.authoringKey) { - configList.push('--luis:endpointKey'); - configList.push(config.luis.authoringKey); - } - if (config.luis.authoringRegion) { - configList.push('--luis:endpoint'); - configList.push(`https://${config.luis.authoringRegion}.api.cognitive.microsoft.com`); - } + configList.push('--luis:endpointKey'); + configList.push(config.luis.endpointKey || config.luis.authoringKey); } return configList; }; From 79c5733ffaf3efbb9ce3e83fa549d2c18a63c7c0 Mon Sep 17 00:00:00 2001 From: Wenyi Luo Date: Fri, 22 May 2020 18:08:18 +0800 Subject: [PATCH 2/2] remove auth --- .../server/src/models/bot/luPublisher.ts | 19 ------------------- Composer/plugins/localPublish/src/index.ts | 8 ++++---- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/Composer/packages/server/src/models/bot/luPublisher.ts b/Composer/packages/server/src/models/bot/luPublisher.ts index 85de5c360a..e1dcb51641 100644 --- a/Composer/packages/server/src/models/bot/luPublisher.ts +++ b/Composer/packages/server/src/models/bot/luPublisher.ts @@ -2,8 +2,6 @@ // Licensed under the MIT License. import { FileInfo } from '@bfc/shared'; -// import * as rp from 'request-promise'; -import axios, { AxiosRequestConfig } from 'axios'; import { Path } from '../../utility/path'; import { IFileStorage } from '../storage/interface'; @@ -169,25 +167,8 @@ export class LuPublisher { loadResult.settings ); await this.builder.writeDialogAssets(buildResult, true, this.generatedFolderPath); - // authoring luis application, make endpointKey can query the application - await this._auth(config.authoringKey, config.region); } - private _auth = async (authoringKey: string, region: string) => { - try { - const luisEndpoint = `https://${region}.api.cognitive.microsoft.com`; - // Assign a LUIS key to the endpoint of each app - const getAccountUri = `${luisEndpoint}/luis/api/v2.0/azureaccounts`; - const options = { - headers: { Authorization: `Bearer ${token}`, 'Ocp-Apim-Subscription-Key': authoringKey }, - } as AxiosRequestConfig; - const response = await axios.get(getAccountUri, options); - console.log(response); - } catch (err) { - console.log(err); - } - }; - //delete files in generated folder private async _deleteDir(path: string) { if (await this.storage.exists(path)) { diff --git a/Composer/plugins/localPublish/src/index.ts b/Composer/plugins/localPublish/src/index.ts index ca5fde39c8..c6ebb1f002 100644 --- a/Composer/plugins/localPublish/src/index.ts +++ b/Composer/plugins/localPublish/src/index.ts @@ -314,18 +314,18 @@ class LocalPublisher implements PublishPlugin { erroutput += err.toString(); }); - child.on('exit', code => { + child.on('exit', (code) => { if (code !== 0) { reject(erroutput); } }); - child.on('error', err => { + child.on('error', (err) => { logger('error: %s', err.message); reject(`Could not launch bot runtime process: ${err.message}`); }); - child.on('message', msg => { + child.on('message', (msg) => { logger('%s', msg); }); }; @@ -352,7 +352,7 @@ class LocalPublisher implements PublishPlugin { } archive.finalize(); output.on('close', () => resolve(dstPath)); - output.on('error', err => { + output.on('error', (err) => { reject(err); }); });