fix(core.gbapp): Admin protected again, additional checks and adjustments.
This commit is contained in:
parent
f5e0835cc3
commit
efea36f1cc
10 changed files with 3544 additions and 786 deletions
4248
package-lock.json
generated
4248
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -86,6 +86,7 @@
|
||||||
"request-promise-native": "1.0.8",
|
"request-promise-native": "1.0.8",
|
||||||
"rimraf": "3.0.0",
|
"rimraf": "3.0.0",
|
||||||
"scanf": "1.1.1",
|
"scanf": "1.1.1",
|
||||||
|
"sequelize": "5.21.5",
|
||||||
"sequelize-typescript": "1.1.0",
|
"sequelize-typescript": "1.1.0",
|
||||||
"shx": "0.3.2",
|
"shx": "0.3.2",
|
||||||
"simple-git": "1.129.0",
|
"simple-git": "1.129.0",
|
||||||
|
|
|
@ -126,20 +126,20 @@ export class AdminDialog extends IGBDialog {
|
||||||
const prompt = Messages[locale].authenticate;
|
const prompt = Messages[locale].authenticate;
|
||||||
|
|
||||||
return await step.prompt('textPrompt', prompt);
|
return await step.prompt('textPrompt', prompt);
|
||||||
// },
|
},
|
||||||
// async step => {
|
async step => {
|
||||||
// const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
// const sensitive = step.result;
|
const sensitive = step.result;
|
||||||
|
|
||||||
// if (sensitive === GBConfigService.get('ADMIN_PASS')) {
|
if (sensitive === GBConfigService.get('ADMIN_PASS')) {
|
||||||
// await step.context.sendActivity(Messages[locale].welcome);
|
await step.context.sendActivity(Messages[locale].welcome);
|
||||||
|
|
||||||
// return await step.prompt('textPrompt', Messages[locale].which_task);
|
return await step.prompt('textPrompt', Messages[locale].which_task);
|
||||||
// } else {
|
} else {
|
||||||
// await step.context.sendActivity(Messages[locale].wrong_password);
|
await step.context.sendActivity(Messages[locale].wrong_password);
|
||||||
|
|
||||||
// return await step.endDialog();
|
return await step.endDialog();
|
||||||
// }
|
}
|
||||||
},
|
},
|
||||||
async step => {
|
async step => {
|
||||||
const locale: string = step.context.activity.locale;
|
const locale: string = step.context.activity.locale;
|
||||||
|
|
|
@ -57,7 +57,7 @@ export class GuaribasAdmin extends Model<GuaribasAdmin> {
|
||||||
@Column
|
@Column
|
||||||
public key: string;
|
public key: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(1024))
|
@Column(DataType.STRING(2048))
|
||||||
public value: string;
|
public value: string;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
|
|
|
@ -176,7 +176,7 @@ export class GBAdminService implements IGBAdminService {
|
||||||
instance.authenticatorClientSecret,
|
instance.authenticatorClientSecret,
|
||||||
resource,
|
resource,
|
||||||
async (err, res) => {
|
async (err, res) => {
|
||||||
if (err !== undefined) {
|
if (err !== null) {
|
||||||
reject(err);
|
reject(err);
|
||||||
} else {
|
} else {
|
||||||
const token = res as TokenResponse;
|
const token = res as TokenResponse;
|
||||||
|
|
|
@ -520,8 +520,8 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
luisKey: nlpKey,
|
luisKey: nlpKey,
|
||||||
msaAppId: appId,
|
msaAppId: appId,
|
||||||
msaAppPassword: appPassword,
|
msaAppPassword: appPassword,
|
||||||
enabledChannels: ['webchat'], // , "skype", "facebook"],
|
enabledChannels: ['webchat', "skype"],//, "facebook"],
|
||||||
configuredChannels: ['webchat'] // , "skype", "facebook"]
|
configuredChannels: ['webchat' , "skype"]//, "facebook"]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -604,6 +604,30 @@ export class AzureDeployerService implements IGBInstallationDeployer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async createApplicationSecret(token: string, appId: string) {
|
||||||
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
let client = MicrosoftGraph.Client.init({
|
||||||
|
authProvider: done => {
|
||||||
|
done(null, token);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const body = {
|
||||||
|
passwordCredential: {
|
||||||
|
displayName: "General Bots Generated"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
client.api(`/applications/${appId}/addPassword`).post(body, (err, res) => {
|
||||||
|
if (err) {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resolve(res.secretText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private async registerProviders(subscriptionId, baseUrl, accessToken) {
|
private async registerProviders(subscriptionId, baseUrl, accessToken) {
|
||||||
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);
|
||||||
|
|
|
@ -62,7 +62,7 @@ export class WelcomeDialog extends IGBDialog {
|
||||||
return step.replaceDialog(GBServer.globals.entryPointDialog);
|
return step.replaceDialog(GBServer.globals.entryPointDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
const user = await min.userProfile.get(context, {});
|
const user = await min.userProfile.get(step.context, {});
|
||||||
const locale = step.context.activity.locale;
|
const locale = step.context.activity.locale;
|
||||||
|
|
||||||
if (!user.once) {
|
if (!user.once) {
|
||||||
|
|
|
@ -311,8 +311,7 @@ STORAGE_SYNC=true
|
||||||
let instance = await GuaribasInstance.findOne(options);
|
let instance = await GuaribasInstance.findOne(options);
|
||||||
// tslint:disable-next-line:prefer-object-spread
|
// tslint:disable-next-line:prefer-object-spread
|
||||||
instance = Object.assign(instance, fullInstance);
|
instance = Object.assign(instance, fullInstance);
|
||||||
let ret = await instance.save();
|
return await instance.save();
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -166,27 +166,29 @@ export class GBDeployer {
|
||||||
public async deployBlankBot(botId: string) {
|
public async deployBlankBot(botId: string) {
|
||||||
let instance = await this.importer.createBotInstance(botId);
|
let instance = await this.importer.createBotInstance(botId);
|
||||||
|
|
||||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
const accessToken = await GBServer.globals.minBoot.adminService
|
||||||
const password = GBConfigService.get('CLOUD_PASSWORD');
|
.acquireElevatedToken(GBServer.globals.bootInstance.instanceId);
|
||||||
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
|
|
||||||
|
|
||||||
const service = new AzureDeployerService(this);
|
const service = new AzureDeployerService(this);
|
||||||
let application = await service.createApplication(accessToken, botId);
|
let application = await service.createApplication(accessToken, botId);
|
||||||
|
|
||||||
instance.marketplaceId = (application as any).appId;
|
instance.marketplaceId = (application as any).appId;
|
||||||
instance.marketplacePassword = (application as any).passwordCredentials[0];
|
instance.marketplacePassword = await service.createApplicationSecret(
|
||||||
|
accessToken, (application as any).id);
|
||||||
instance.adminPass = GBAdminService.getRndPassword();
|
instance.adminPass = GBAdminService.getRndPassword();
|
||||||
|
instance.title = botId;
|
||||||
|
|
||||||
|
|
||||||
await this.core.saveInstance(instance);
|
await this.core.saveInstance(instance);
|
||||||
|
|
||||||
return this.deployBotFull(instance, GBServer.globals.publicAddress);
|
return await this.deployBotFull(instance, GBServer.globals.publicAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deploys a bot to the storage.
|
* Deploys a bot to the storage.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<void> {
|
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<IGBInstance> {
|
||||||
|
|
||||||
const service = new AzureDeployerService(this);
|
const service = new AzureDeployerService(this);
|
||||||
const username = GBConfigService.get('CLOUD_USERNAME');
|
const username = GBConfigService.get('CLOUD_USERNAME');
|
||||||
|
@ -242,7 +244,7 @@ export class GBDeployer {
|
||||||
|
|
||||||
await GBServer.globals.minService.mountBot(instance);
|
await GBServer.globals.minService.mountBot(instance);
|
||||||
}
|
}
|
||||||
await this.core.saveInstance(instance);
|
return await this.core.saveInstance(instance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ export class GBWhatsappPackage implements IGBPackage {
|
||||||
public loadBot(min: GBMinInstance): void {
|
public loadBot(min: GBMinInstance): void {
|
||||||
// Only loads engine if it is defined on services.json.
|
// Only loads engine if it is defined on services.json.
|
||||||
|
|
||||||
if (min.instance.whatsappBotKey !== undefined && min.instance.whatsappBotKey !== null ) {
|
if (min.instance.whatsappServiceKey !== null ) {
|
||||||
min.whatsAppDirectLine = new WhatsappDirectLine(
|
min.whatsAppDirectLine = new WhatsappDirectLine(
|
||||||
min.botId,
|
min.botId,
|
||||||
min.instance.whatsappBotKey,
|
min.instance.whatsappBotKey,
|
||||||
|
|
Loading…
Add table
Reference in a new issue