Skip to content

Commit

Permalink
fix(core.gbapp): Admin protected again, additional checks and adjustm…
Browse files Browse the repository at this point in the history
…ents.
  • Loading branch information
rodrigorodriguez committed Mar 8, 2020
1 parent f5e0835 commit efea36f
Show file tree
Hide file tree
Showing 10 changed files with 3,590 additions and 832 deletions.
4,340 changes: 3,536 additions & 804 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"request-promise-native": "1.0.8",
"rimraf": "3.0.0",
"scanf": "1.1.1",
"sequelize": "5.21.5",
"sequelize-typescript": "1.1.0",
"shx": "0.3.2",
"simple-git": "1.129.0",
Expand Down
24 changes: 12 additions & 12 deletions packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,20 @@ export class AdminDialog extends IGBDialog {
const prompt = Messages[locale].authenticate;

return await step.prompt('textPrompt', prompt);
// },
// async step => {
// const locale = step.context.activity.locale;
// const sensitive = step.result;
},
async step => {
const locale = step.context.activity.locale;
const sensitive = step.result;

// if (sensitive === GBConfigService.get('ADMIN_PASS')) {
// await step.context.sendActivity(Messages[locale].welcome);
if (sensitive === GBConfigService.get('ADMIN_PASS')) {
await step.context.sendActivity(Messages[locale].welcome);

// return await step.prompt('textPrompt', Messages[locale].which_task);
// } else {
// await step.context.sendActivity(Messages[locale].wrong_password);
return await step.prompt('textPrompt', Messages[locale].which_task);
} else {
await step.context.sendActivity(Messages[locale].wrong_password);

// return await step.endDialog();
// }
return await step.endDialog();
}
},
async step => {
const locale: string = step.context.activity.locale;
Expand Down Expand Up @@ -198,7 +198,7 @@ export class AdminDialog extends IGBDialog {
} else {
await step.context.sendActivity(Messages[locale].finished_working);
}

} catch (error) {
await step.context.sendActivity(error.message);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/admin.gbapp/models/AdminModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class GuaribasAdmin extends Model<GuaribasAdmin> {
@Column
public key: string;

@Column(DataType.STRING(1024))
@Column(DataType.STRING(2048))
public value: string;

@Column
Expand Down
2 changes: 1 addition & 1 deletion packages/admin.gbapp/services/GBAdminService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class GBAdminService implements IGBAdminService {
instance.authenticatorClientSecret,
resource,
async (err, res) => {
if (err !== undefined) {
if (err !== null) {
reject(err);
} else {
const token = res as TokenResponse;
Expand Down
28 changes: 26 additions & 2 deletions packages/azuredeployer.gbapp/services/AzureDeployerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ export class AzureDeployerService implements IGBInstallationDeployer {
luisKey: nlpKey,
msaAppId: appId,
msaAppPassword: appPassword,
enabledChannels: ['webchat'], // , "skype", "facebook"],
configuredChannels: ['webchat'] // , "skype", "facebook"]
enabledChannels: ['webchat', "skype"],//, "facebook"],
configuredChannels: ['webchat' , "skype"]//, "facebook"]
}
};

Expand Down Expand Up @@ -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) {
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
const requestUrl = urlJoin(baseUrl, query);
Expand Down
2 changes: 1 addition & 1 deletion packages/core.gbapp/dialogs/WelcomeDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class WelcomeDialog extends IGBDialog {
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;

if (!user.once) {
Expand Down
3 changes: 1 addition & 2 deletions packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,7 @@ STORAGE_SYNC=true
let instance = await GuaribasInstance.findOne(options);
// tslint:disable-next-line:prefer-object-spread
instance = Object.assign(instance, fullInstance);
let ret = await instance.save();
return ret;
return await instance.save();
}

/**
Expand Down
18 changes: 10 additions & 8 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,29 @@ export class GBDeployer {
public async deployBlankBot(botId: string) {
let instance = await this.importer.createBotInstance(botId);

const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
const accessToken = await GBServer.globals.minBoot.adminService
.acquireElevatedToken(GBServer.globals.bootInstance.instanceId);

const service = new AzureDeployerService(this);
let application = await service.createApplication(accessToken, botId);

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.title = botId;


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.
*/

public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<void> {
public async deployBotFull(instance: IGBInstance, publicAddress: string): Promise<IGBInstance> {

const service = new AzureDeployerService(this);
const username = GBConfigService.get('CLOUD_USERNAME');
Expand Down Expand Up @@ -242,7 +244,7 @@ export class GBDeployer {

await GBServer.globals.minService.mountBot(instance);
}
await this.core.saveInstance(instance);
return await this.core.saveInstance(instance);

}

Expand Down Expand Up @@ -514,7 +516,7 @@ export class GBDeployer {
}

folder = Path.join(e, 'dist');
if (!Fs.existsSync()) {
if (!Fs.existsSync()) {
GBLog.info(`Compiling ${e}...`);

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/whatsapp.gblib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class GBWhatsappPackage implements IGBPackage {
public loadBot(min: GBMinInstance): void {
// 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.botId,
min.instance.whatsappBotKey,
Expand Down

0 comments on commit efea36f

Please sign in to comment.