fix(gbminservice.ts): swagger-client migration from 2.0 to 3.0
This commit is contained in:
parent
ba96798c77
commit
552e8b14c4
6 changed files with 208 additions and 610 deletions
File diff suppressed because one or more lines are too long
|
@ -124,7 +124,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
return subscriptionClient.subscriptions.list();
|
return subscriptionClient.subscriptions.list();
|
||||||
}
|
}
|
||||||
|
|
||||||
public getKBSearchSchema (indexName) {
|
public getKBSearchSchema (indexName: any) {
|
||||||
return {
|
return {
|
||||||
name: indexName,
|
name: indexName,
|
||||||
fields: [
|
fields: [
|
||||||
|
@ -235,7 +235,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async botExists (botId) {
|
public async botExists (botId: string) {
|
||||||
const baseUrl = `https://management.azure.com/`;
|
const baseUrl = `https://management.azure.com/`;
|
||||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||||
const password = GBConfigService.get('CLOUD_PASSWORD');
|
const password = GBConfigService.get('CLOUD_PASSWORD');
|
||||||
|
@ -257,7 +257,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
return !res.parsedBody.valid;
|
return !res.parsedBody.valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async updateBotProxy (botId, group, endpoint) {
|
public async updateBotProxy (botId: string, group: string, endpoint: string) {
|
||||||
const baseUrl = `https://management.azure.com/`;
|
const baseUrl = `https://management.azure.com/`;
|
||||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||||
const password = GBConfigService.get('CLOUD_PASSWORD');
|
const password = GBConfigService.get('CLOUD_PASSWORD');
|
||||||
|
@ -316,7 +316,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
GBLog.info(`Bot updated at: ${endpoint}.`);
|
GBLog.info(`Bot updated at: ${endpoint}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async deleteBot (botId: string, group) {
|
public async deleteBot (botId: string, group: string) {
|
||||||
const baseUrl = `https://management.azure.com/`;
|
const baseUrl = `https://management.azure.com/`;
|
||||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||||
const password = GBConfigService.get('CLOUD_PASSWORD');
|
const password = GBConfigService.get('CLOUD_PASSWORD');
|
||||||
|
@ -338,7 +338,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
GBLog.info(`Bot ${botId} was deleted from the provider.`);
|
GBLog.info(`Bot ${botId} was deleted from the provider.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async openStorageFirewall (groupName, serverName) {
|
public async openStorageFirewall (groupName: string, serverName: string) {
|
||||||
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
|
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
|
||||||
|
|
||||||
|
|
||||||
|
@ -353,7 +353,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
public async deployFarm (
|
public async deployFarm (
|
||||||
proxyAddress: string,
|
proxyAddress: string,
|
||||||
instance: IGBInstance,
|
instance: IGBInstance,
|
||||||
credentials,
|
credentials: any,
|
||||||
subscriptionId: string
|
subscriptionId: string
|
||||||
): Promise<IGBInstance> {
|
): Promise<IGBInstance> {
|
||||||
const culture = 'en-us';
|
const culture = 'en-us';
|
||||||
|
@ -580,7 +580,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async syncBotServerRepository (group, name) {
|
public async syncBotServerRepository (group: string, name: string) {
|
||||||
await this.webSiteClient.webApps.syncRepository(group, name);
|
await this.webSiteClient.webApps.syncRepository(group, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -605,7 +605,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const token = await new StaticAccessToken();
|
const token = new StaticAccessToken();
|
||||||
|
|
||||||
this.cloud = new ResourceManagementClient(token, subscriptionId);
|
this.cloud = new ResourceManagementClient(token, subscriptionId);
|
||||||
this.webSiteClient = new WebSiteManagementClient(token, subscriptionId);
|
this.webSiteClient = new WebSiteManagementClient(token, subscriptionId);
|
||||||
|
@ -614,7 +614,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
this.searchClient = new SearchManagementClient(token, subscriptionId);
|
this.searchClient = new SearchManagementClient(token, subscriptionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createStorageServer (group, name, administratorLogin, administratorPassword, serverName, location) {
|
private async createStorageServer (group: string, name: string, administratorLogin: string, administratorPassword: string, serverName: string, location: string) {
|
||||||
const params = {
|
const params = {
|
||||||
location: location,
|
location: location,
|
||||||
administratorLogin: administratorLogin,
|
administratorLogin: administratorLogin,
|
||||||
|
@ -680,7 +680,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async registerProviders (subscriptionId, baseUrl, accessToken) {
|
private async registerProviders (subscriptionId: string, baseUrl: string, accessToken: string) {
|
||||||
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
|
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
|
||||||
const requestUrl = urlJoin(baseUrl, query);
|
const requestUrl = urlJoin(baseUrl, query);
|
||||||
|
|
||||||
|
@ -793,7 +793,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
return await httpClient.sendRequest(req);
|
return await httpClient.sendRequest(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createSearch (group, name, location) {
|
private async createSearch (group: string, name: string, location: string) {
|
||||||
const params = {
|
const params = {
|
||||||
sku: {
|
sku: {
|
||||||
name: this.freeTier ? 'free' : 'standard'
|
name: this.freeTier ? 'free' : 'standard'
|
||||||
|
@ -804,7 +804,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
return await this.searchClient.services.beginCreateOrUpdateAndWait(group, name, params as any);
|
return await this.searchClient.services.beginCreateOrUpdateAndWait(group, name, params as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createStorage (group, serverName, name, location) {
|
private async createStorage (group: string, serverName: string, name: string, location: string) {
|
||||||
const params = {
|
const params = {
|
||||||
sku: { name: this.freeTier ? 'Free' : 'Basic' },
|
sku: { name: this.freeTier ? 'Free' : 'Basic' },
|
||||||
createMode: 'Default',
|
createMode: 'Default',
|
||||||
|
@ -814,7 +814,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
return await this.storageClient.databases.beginCreateOrUpdateAndWait(group, serverName, name, params);
|
return await this.storageClient.databases.beginCreateOrUpdateAndWait(group, serverName, name, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createCognitiveServices (group, name, location, kind): Promise<Account> {
|
private async createCognitiveServices (group: string, name: string, location: string, kind: string): Promise<Account> {
|
||||||
const params = {
|
const params = {
|
||||||
sku: {
|
sku: {
|
||||||
name: name
|
name: name
|
||||||
|
@ -840,40 +840,40 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
return await this.cognitiveClient.accounts.beginCreateAndWait(group, name, params);
|
return await this.cognitiveClient.accounts.beginCreateAndWait(group, name, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createSpeech (group, name, location): Promise<Account> {
|
private async createSpeech (group: string, name: string, location: string): Promise<Account> {
|
||||||
return await this.createCognitiveServices(group, name, location, 'SpeechServices');
|
return await this.createCognitiveServices(group, name, location, 'SpeechServices');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createNLP (group, name, location): Promise<Account> {
|
private async createNLP (group: string, name: string, location: string): Promise<Account> {
|
||||||
return await this.createCognitiveServices(group, name, location, 'LUIS');
|
return await this.createCognitiveServices(group, name, location, 'LUIS');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createNLPAuthoring (group, name, location): Promise<Account> {
|
private async createNLPAuthoring (group: string, name: string, location: string): Promise<Account> {
|
||||||
return await this.createCognitiveServices(group, name, location, 'LUIS.Authoring');
|
return await this.createCognitiveServices(group, name, location, 'LUIS.Authoring');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createSpellChecker (group, name): Promise<Account> {
|
private async createSpellChecker (group: string, name: string): Promise<Account> {
|
||||||
return await this.createCognitiveServices(group, name, 'westus', 'CognitiveServices');
|
return await this.createCognitiveServices(group, name, 'westus', 'CognitiveServices');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createTextAnalytics (group, name, location): Promise<Account> {
|
private async createTextAnalytics (group: string, name: string, location: string): Promise<Account> {
|
||||||
return await this.createCognitiveServices(group, name, location, 'TextAnalytics');
|
return await this.createCognitiveServices(group, name, location, 'TextAnalytics');
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createDeployGroup (name, location) {
|
private async createDeployGroup (name: string, location: string) {
|
||||||
const params = { location: location };
|
const params = { location: location };
|
||||||
|
|
||||||
return await this.cloud.resourceGroups.createOrUpdate(name, params);
|
return await this.cloud.resourceGroups.createOrUpdate(name, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async enableResourceProviders (name) {
|
private async enableResourceProviders (name: string) {
|
||||||
const ret = await this.cloud.providers.get(name);
|
const ret = await this.cloud.providers.get(name);
|
||||||
if (ret.registrationState === 'NotRegistered') {
|
if (ret.registrationState === 'NotRegistered') {
|
||||||
await this.cloud.providers.register(name);
|
await this.cloud.providers.register(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createHostingPlan (group, name, location): Promise<AppServicePlan> {
|
private async createHostingPlan (group: string, name: string, location: string): Promise<AppServicePlan> {
|
||||||
const params = {
|
const params = {
|
||||||
serverFarmWithRichSkuName: name,
|
serverFarmWithRichSkuName: name,
|
||||||
location: location,
|
location: location,
|
||||||
|
@ -887,7 +887,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
return await this.webSiteClient.appServicePlans.beginCreateOrUpdateAndWait(group, name, params);
|
return await this.webSiteClient.appServicePlans.beginCreateOrUpdateAndWait(group, name, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createServer (farmId, group, name, location) {
|
private async createServer (farmId: string, group: string, name: string, location: string) {
|
||||||
let tryed = false;
|
let tryed = false;
|
||||||
const create = async () => {
|
const create = async () => {
|
||||||
const parameters: Site = {
|
const parameters: Site = {
|
||||||
|
@ -937,7 +937,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async updateWebisteConfig (group, name, serverFarmId, instance: IGBInstance) {
|
private async updateWebisteConfig (group: string, name: string, serverFarmId: string, instance: IGBInstance) {
|
||||||
const parameters: Site = {
|
const parameters: Site = {
|
||||||
location: instance.cloudLocation,
|
location: instance.cloudLocation,
|
||||||
serverFarmId: serverFarmId,
|
serverFarmId: serverFarmId,
|
||||||
|
|
|
@ -56,6 +56,7 @@ import Path from 'path';
|
||||||
import sgMail from '@sendgrid/mail';
|
import sgMail from '@sendgrid/mail';
|
||||||
import mammoth from 'mammoth';
|
import mammoth from 'mammoth';
|
||||||
import qrcode from 'qrcode';
|
import qrcode from 'qrcode';
|
||||||
|
import { json } from 'body-parser';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base services of conversation to be called by BASIC.
|
* Base services of conversation to be called by BASIC.
|
||||||
|
@ -1028,10 +1029,7 @@ export class DialogKeywords {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getSingleton({}) {
|
public async getSingleton({}) {
|
||||||
const executionId = this.sys().getRandomId();
|
|
||||||
GBServer.globals.executions[executionId]={};
|
|
||||||
return {
|
return {
|
||||||
executionId: executionId,
|
|
||||||
id: this.sys().getRandomId(),
|
id: this.sys().getRandomId(),
|
||||||
username: this.userName(),
|
username: this.userName(),
|
||||||
mobile: this.userMobile(),
|
mobile: this.userMobile(),
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
|
|
||||||
import { GBLog, GBMinInstance, GBService, IGBCoreService, GBDialogStep } from 'botlib';
|
import { GBLog, GBMinInstance, GBService, IGBCoreService, GBDialogStep } from 'botlib';
|
||||||
import * as Fs from 'fs';
|
import * as Fs from 'fs';
|
||||||
|
import { GBServer } from '../../../src/app.js';
|
||||||
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
|
import { GBDeployer } from '../../core.gbapp/services/GBDeployer.js';
|
||||||
import { TSCompiler } from './TSCompiler.js';
|
import { TSCompiler } from './TSCompiler.js';
|
||||||
import { CollectionUtil } from 'pragmatismo-io-framework';
|
import { CollectionUtil } from 'pragmatismo-io-framework';
|
||||||
|
@ -48,6 +49,10 @@ import walkPromise from 'walk-promise';
|
||||||
import child_process from 'child_process';
|
import child_process from 'child_process';
|
||||||
import Path from 'path';
|
import Path from 'path';
|
||||||
import indent from 'indent.js';
|
import indent from 'indent.js';
|
||||||
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||||
|
import pkg from 'swagger-client';
|
||||||
|
const {Swagger} = pkg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @fileoverview Decision was to priorize security(isolation) and debugging,
|
* @fileoverview Decision was to priorize security(isolation) and debugging,
|
||||||
* over a beautiful BASIC transpiler (to be done).
|
* over a beautiful BASIC transpiler (to be done).
|
||||||
|
@ -1022,6 +1027,10 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
let code = min.sandBoxMap[text];
|
let code = min.sandBoxMap[text];
|
||||||
|
|
||||||
|
const executionId = GBAdminService.getNumberIdentifier();
|
||||||
|
GBServer.globals.executions[executionId]={
|
||||||
|
executionId: executionId,
|
||||||
|
};
|
||||||
if (GBConfigService.get('VM3') === 'true') {
|
if (GBConfigService.get('VM3') === 'true') {
|
||||||
try {
|
try {
|
||||||
const vm1 = new NodeVM({
|
const vm1 = new NodeVM({
|
||||||
|
|
|
@ -46,7 +46,7 @@ export const createVm2Pool = ({ min, max, ...limits }) => {
|
||||||
|
|
||||||
let stderrCache = '';
|
let stderrCache = '';
|
||||||
|
|
||||||
const run = async (code, scope) => {
|
const run = async (code: any, scope: any) => {
|
||||||
const childProcess = spawn(
|
const childProcess = spawn(
|
||||||
'cpulimit',
|
'cpulimit',
|
||||||
[
|
[
|
||||||
|
|
|
@ -38,8 +38,7 @@
|
||||||
import cliProgress from 'cli-progress';
|
import cliProgress from 'cli-progress';
|
||||||
import { DialogSet, TextPrompt } from 'botbuilder-dialogs';
|
import { DialogSet, TextPrompt } from 'botbuilder-dialogs';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import Swagger from 'swagger-client';
|
import SwaggerClient from 'swagger-client';
|
||||||
|
|
||||||
import removeRoute from 'express-remove-route';
|
import removeRoute from 'express-remove-route';
|
||||||
import AuthenticationContext from 'adal-node';
|
import AuthenticationContext from 'adal-node';
|
||||||
import wash from 'washyourmouthoutwithsoap';
|
import wash from 'washyourmouthoutwithsoap';
|
||||||
|
@ -331,15 +330,14 @@ export class GBMinService {
|
||||||
if (process.env.TEST_MESSAGE) {
|
if (process.env.TEST_MESSAGE) {
|
||||||
GBLog.info(`Starting auto test with '${process.env.TEST_MESSAGE}'.`);
|
GBLog.info(`Starting auto test with '${process.env.TEST_MESSAGE}'.`);
|
||||||
|
|
||||||
const client = await new Swagger({
|
const client = await new SwaggerClient({
|
||||||
spec: JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')),
|
spec:JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')),
|
||||||
usePromise: true
|
requestInterceptor: req => {
|
||||||
});
|
req.headers["Authorization"] = `Bearer ${min.instance.webchatKey}`
|
||||||
client.clientAuthorizations.add(
|
|
||||||
'AuthorizationBotConnector',
|
}});
|
||||||
new Swagger.ApiKeyAfuthorization('Authorization', `Bearer ${min.instance.webchatKey}`, 'header')
|
|
||||||
);
|
const response = await client.apis.Conversations.Conversations_StartConversation();
|
||||||
const response = await client.Conversations.Conversations_StartConversation();
|
|
||||||
const conversationId = response.obj.conversationId;
|
const conversationId = response.obj.conversationId;
|
||||||
GBServer.globals.debugConversationId = conversationId;
|
GBServer.globals.debugConversationId = conversationId;
|
||||||
|
|
||||||
|
@ -351,7 +349,7 @@ export class GBMinService {
|
||||||
};
|
};
|
||||||
|
|
||||||
await CollectionUtil.asyncForEach(steps, async step => {
|
await CollectionUtil.asyncForEach(steps, async step => {
|
||||||
client.Conversations.Conversations_PostActivity({
|
client.apis.Conversations.Conversations_PostActivity({
|
||||||
conversationId: conversationId,
|
conversationId: conversationId,
|
||||||
activity: {
|
activity: {
|
||||||
textFormat: 'plain',
|
textFormat: 'plain',
|
||||||
|
@ -411,7 +409,7 @@ export class GBMinService {
|
||||||
GBDeployer.mountGBKBAssets(`${instance.botId}.gbkb`, instance.botId, `${instance.botId}.gbkb`);
|
GBDeployer.mountGBKBAssets(`${instance.botId}.gbkb`, instance.botId, `${instance.botId}.gbkb`);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static isChatAPI(req, res) {
|
public static isChatAPI(req:any, res: any) {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return 'GeneralBots';
|
return 'GeneralBots';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue