new(all): TRUE multicloud.

This commit is contained in:
Rodrigo Rodriguez 2024-08-20 15:13:43 -03:00
parent b004f8b4b5
commit 016abf7aac
9 changed files with 18 additions and 25 deletions

View file

@ -8,7 +8,7 @@ import pjson from './package.json' assert { type: 'json' };
// Displays version of Node JS being used at runtime and others attributes.
process.stdout.write(`General Bots. BotServer@${pjson.version}, botlib@${pjson.dependencies.botlib}, botbuilder@${pjson.dependencies.botbuilder}, node@${process.version.replace('v', '')}, ${process.platform} ${process.arch} `);
process.stdout.write(`General Bots. BotServer@${pjson.version}, botlib@${pjson.dependencies.botlib}, node@${process.version.replace('v', '')}, ${process.platform} ${process.arch} `);
console.log(`\nLoading virtual machine source code files...`);
var __dirname = process.env.PWD || process.cwd();

View file

@ -187,7 +187,7 @@ export class GBAdminService implements IGBAdminService {
await deployer['cleanupPackage'](min.instance, packageName);
}
if (GBConfigService.get('STORAGE_FILE')) {
if (!GBConfigService.get('STORAGE_NAME')) {
const path = Path.join(GBConfigService.get('STORAGE_LIBRARY'), gbaiPath);
Fs.cpSync(path, localFolder, { errorOnExist: false, force: true, recursive: true});
} else {

View file

@ -426,8 +426,8 @@ ENDPOINT_UPDATE=true
let instances: IGBInstance[];
try {
instances = await core.loadInstances();
const group = GBConfigService.get('CLOUD_GROUP') ?? GBConfigService.get('BOT_ID');
if (process.env.ENDPOINT_UPDATE === 'true') {
const group = GBConfigService.get('CLOUD_GROUP') ?? GBConfigService.get('BOT_ID');
await CollectionUtil.asyncForEach(instances, async instance => {
GBLogEx.info(instance.instanceId, `Updating bot endpoint for ${instance.botId}...`);
try {
@ -514,12 +514,6 @@ ENDPOINT_UPDATE=true
* before starting the server.
*/
public ensureAdminIsSecured() {
const password = GBConfigService.get('ADMIN_PASS');
if (!GBAdminService.StrongRegex.test(password)) {
throw new Error(
'Please, define a really strong password in ADMIN_PASS environment variable before running the server.'
);
}
}
public async createBootInstance(

View file

@ -222,7 +222,7 @@ export class GBDeployer implements IGBDeployer {
const instance = await this.importer.createBotInstance(botId);
const bootInstance = GBServer.globals.bootInstance;
if (!GBConfigService.get('STORAGE_FILE')) {
if (GBConfigService.get('STORAGE_NAME')) {
// Gets the access token to perform service operations.
const accessToken = await (GBServer.globals.minBoot.adminService as any)['acquireElevatedToken'](
@ -251,7 +251,7 @@ export class GBDeployer implements IGBDeployer {
// Saves bot information to the store.
await this.core.saveInstance(instance);
if (!GBConfigService.get('STORAGE_FILE')) {
if (GBConfigService.get('STORAGE_NAME')) {
await this.deployBotOnAzure(instance, GBServer.globals.publicAddress);
}
// Creates remaining objects on the cloud and updates instance information.

View file

@ -321,7 +321,7 @@ export class GBMinService {
mkdirp.sync(dir);
}
if (GBConfigService.get('STORAGE_FILE')) {
if (!GBConfigService.get('STORAGE_NAME')) {
dir = Path.join(GBConfigService.get('STORAGE_LIBRARY'), 'work', gbai);
const server = GBServer.globals.webDavServer;
@ -695,7 +695,7 @@ export class GBMinService {
color2: this.core.getParam(instance, 'Color2', null)
};
if (GBConfigService.get('STORAGE_FILE')) {
if (!GBConfigService.get('STORAGE_NAME')) {
config['domain'] = `http://localhost:${process.env.PORT}/directline/${botId}`;
} else {
const webchatTokenContainer = await this.getWebchatToken(instance);
@ -767,7 +767,7 @@ export class GBMinService {
? instance.marketplacePassword
: GBConfigService.get('MARKETPLACE_SECRET')
};
if (GBConfigService.get('STORAGE_FILE')) {
if (!GBConfigService.get('STORAGE_NAME')) {
config['clientOptions'] = { baseUri: `http://localhost:${process.env.PORT}` };
}
@ -1198,7 +1198,7 @@ export class GBMinService {
};
try {
if (GBConfigService.get('STORAGE_FILE')) {
if (!GBConfigService.get('STORAGE_NAME')) {
const context = adapter['createContext'](req);
context['_activity'] = context.activity.body;
await handler(context);

View file

@ -5,6 +5,7 @@ import moment from 'moment';
import * as uuidv4 from 'uuid';
import { IActivity, IBotData, IConversation, IConversationUpdateActivity, IMessageActivity } from './types';
import { GBConfigService } from '../GBConfigService.js';
const expiresIn = 1800;
const conversationsCleanupInterval = 10000;
@ -274,8 +275,8 @@ const setPrivateConversationData = (req: express.Request, res: express.Response)
};
export const start = (server, botId)=>{
initializeRoutes(server, Number(process.env.PORT), `http://127.0.0.1:${process.env.PORT}/api/messages/${botId}`, null, botId);
const port = GBConfigService.getServerPort();
initializeRoutes(server, Number(port), `http://127.0.0.1:${port}/api/messages/${botId}`, null, botId);
}
const deleteStateForUser = (req: express.Request, res: express.Response) => {

View file

@ -1370,7 +1370,7 @@ export class KBService implements IGBKBService {
await this.importKbPackage(min, localPath, p, instance);
GBDeployer.mountGBKBAssets(packageName, min.botId, localPath);
if (!GBConfigService.get('STORAGE_FILE')) {
if (GBConfigService.get('STORAGE_NAME')) {
const service = await AzureDeployerService.createInstance(deployer);
const searchIndex = instance.searchIndex ? instance.searchIndex : GBServer.globals.minBoot.instance.searchIndex;
await deployer.rebuildIndex(instance, service.getKBSearchSchema(searchIndex));

View file

@ -190,7 +190,7 @@ export class GBServer {
if (GBConfigService.get('STORAGE_SERVER')) {
azureDeployer = await AzureDeployerService.createInstance(deployer);
await core.initStorage();
} else if (GBConfigService.get('STORAGE_FILE')) {
} else if (!GBConfigService.get('STORAGE_NAME')) {
await core.initStorage();
} else {
[GBServer.globals.bootInstance, azureDeployer] = await core['createBootInstanceEx'](
@ -203,8 +203,6 @@ export class GBServer {
await core.saveInstance(GBServer.globals.bootInstance);
}
core.ensureAdminIsSecured();
// Deploys system and user packages.
GBLogEx.info(0, `Deploying System packages...`);
@ -228,7 +226,7 @@ export class GBServer {
);
if (instances. length === 0) {
if (!GBConfigService.get('STORAGE_FILE')) {
if (GBConfigService.get('STORAGE_NAME')) {
const instance = await importer.importIfNotExistsBotPackage(
GBConfigService.get('BOT_ID'),
'boot.gbot',

View file

@ -70,14 +70,14 @@ export class GBUtil {
public static async getDirectLineClient(min) {
let config = {
url: `http://127.0.0.1:${GBConfigService.get('PORT')}/api/messages`,
url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages`,
spec: JSON.parse(Fs.readFileSync('directline-3.0.json', 'utf8')),
requestInterceptor: req => {
req.headers['Authorization'] = `Bearer ${min.instance.webchatKey}`;
}
};
if (GBConfigService.get('STORAGE_FILE')) {
config['spec'].servers = [{ url: `http://127.0.0.1:${GBConfigService.get('PORT')}/api/messages` }];
if (!GBConfigService.get('STORAGE_NAME')) {
config['spec'].servers = [{ url: `http://127.0.0.1:${GBConfigService.getServerPort()}/api/messages` }];
config['openapi'] = '3.0.0';
}
return await new SwaggerClient(config);