More testing and adjustments on automation.

This commit is contained in:
Rodrigo Rodriguez (pragmatismo.io) 2018-10-25 21:57:28 -03:00
parent b7f256b01f
commit d3e82b5806
4 changed files with 74 additions and 74 deletions

View file

@ -249,7 +249,7 @@ export class AzureDeployerService extends GBService {
// No .env so asks for cloud credentials to start a new farm.
if (!username || !password || !subscriptionId || !location || !botId) {
process.stdout.write(
"A empty enviroment is detected. Please, enter details:"
"A empty enviroment is detected. To start automatic deploy, please enter some information:\n"
);
}
let retriveUsername = () => {
@ -366,22 +366,19 @@ export class AzureDeployerService extends GBService {
public async deployBootBot(
instance,
name,
botId,
endpoint,
nlpAppId,
nlpKey,
subscriptionId,
appId
) {
let botId = name + AzureDeployerService.getRndBotId();
[
instance.marketplacePassword,
instance.webchatKey
] = await this.internalDeployBot(
await this.internalDeployBot(
instance,
this.accessToken,
botId,
name,
name,
botId,
botId,
"General BootBot",
endpoint,
"global",
@ -396,10 +393,6 @@ export class AzureDeployerService extends GBService {
return instance;
}
private async dangerouslyDeleteDeploy(name) {
return await this.resourceClient.resourceGroups.deleteMethod(name);
}
private async createStorageServer(
group,
name,
@ -440,7 +433,7 @@ export class AzureDeployerService extends GBService {
/**
* @see https://github.com/Azure/azure-rest-api-specs/blob/master/specification/botservice/resource-manager/Microsoft.BotService/preview/2017-12-01/botservice.json
*/
private async internalDeployBot(
private async internalDeployBot(instance,
accessToken,
botId,
name,
@ -453,56 +446,67 @@ export class AzureDeployerService extends GBService {
subscriptionId,
appId
) {
let baseUrl = `https://management.azure.com/`;
await this.registerProviders(subscriptionId, baseUrl, accessToken);
return new Promise(async (resolve, reject) => {
let baseUrl = `https://management.azure.com/`;
await this.registerProviders(subscriptionId, baseUrl, accessToken);
let appPassword = AzureDeployerService.getRndPassword();
let appPassword = AzureDeployerService.getRndPassword();
let parameters = {
location: location,
sku: {
name: "F0"
},
name: botId,
kind: "sdk",
properties: {
description: description,
displayName: name,
endpoint: endpoint,
iconUrl: iconUrl,
luisAppIds: [nlpAppId],
luisKey: nlpKey,
msaAppId: appId,
msaAppPassword: appPassword
}
};
let parameters = {
location: location,
sku: {
name: "F0"
},
name: botId,
kind: "sdk",
properties: {
description: description,
displayName: name,
endpoint: endpoint,
iconUrl: iconUrl,
luisAppIds: [nlpAppId],
luisKey: nlpKey,
msaAppId: appId,
msaAppPassword: appPassword
}
};
let httpClient = new ServiceClient();
let httpClient = new ServiceClient();
let query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
}/botServices/${botId}?api-version=${AzureDeployerService.apiVersion}`;
let url = UrlJoin(baseUrl, query);
let req = this.createRequestObject(
url,
accessToken,
JSON.stringify(parameters)
);
let res = await httpClient.sendRequest(req);
let query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
}/botServices/${botId}?api-version=${AzureDeployerService.apiVersion}`;
let url = UrlJoin(baseUrl, query);
let req = this.createRequestObject(
url,
accessToken,
JSON.stringify(parameters)
);
let res = await httpClient.sendRequest(req);
query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${
AzureDeployerService.apiVersion
}`;
url = UrlJoin(baseUrl, query);
req = this.createRequestObject(
url,
accessToken,
JSON.stringify(parameters)
);
let resChannel = await httpClient.sendRequest(req);
setTimeout(async () => {
query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/Microsoft.BotService/botServices/${botId}/channels/WebChatChannel/listChannelWithKeys?api-version=${
AzureDeployerService.apiVersion
}`;
url = UrlJoin(baseUrl, query);
req = this.createRequestObject(
url,
accessToken,
JSON.stringify(parameters)
);
let resChannel = await httpClient.sendRequest(req);
let key = (resChannel.bodyAsJson as any).properties.properties.sites[0].key;
return [appPassword, key];
console.log(resChannel.bodyAsText);
let key = (resChannel.bodyAsJson as any).properties.properties.sites[0]
.key;
instance.marketplacePassword = appPassword
instance.webchatKey = key
resolve(instance)
}, 10000);
});
}
private createRequestObject(url: string, accessToken: string, body) {
@ -735,20 +739,6 @@ export class AzureDeployerService extends GBService {
return `sa${generated}`;
}
private static getRndBotId() {
const passwordGenerator = new PasswordGenerator();
const options = {
upperCaseAlpha: false,
lowerCaseAlpha: true,
number: true,
specialCharacter: false,
minimumLength: 8,
maximumLength: 8
};
let generated = passwordGenerator.generatePassword(options);
return `${generated}`;
}
private static getRndPassword() {
const passwordGenerator = new PasswordGenerator();
const options = {
@ -760,6 +750,7 @@ export class AzureDeployerService extends GBService {
maximumLength: 14
};
let password = passwordGenerator.generatePassword(options);
password = password.replace("=", "");
return password;
}

View file

@ -58,6 +58,9 @@ export class GBConfigService {
case "CLOUD_USERNAME":
value = undefined;
break;
case "BOT_ID":
value = undefined;
break;
case "CLOUD_PASSWORD":
value = undefined;
break;

View file

@ -307,6 +307,7 @@ export class GBCoreService implements IGBCoreService {
`STORAGE_NAME=${instance.storageName}\n` +
`STORAGE_USERNAME=${instance.storageUsername}\n` +
`STORAGE_PASSWORD=${instance.storagePassword}\n`+
`STORAGE_SYNC=true\n`+
`CLOUD_USERNAME=${instance.cloudUsername}\n` +
`CLOUD_PASSWORD=${instance.cloudPassword}\n` +
`CLOUD_SUBSCRIPTIONID=${instance.cloudSubscriptionId}\n` +

View file

@ -102,8 +102,13 @@ export class GBServer {
await core.initDatabase();
} catch (error) {
logger.info(`Deploying cognitive infrastructure...`);
let azureDeployer = new AzureDeployerService();
bootInstance = await azureDeployer.deployFarm(proxyAddress);
try {
let azureDeployer = new AzureDeployerService();
bootInstance = await azureDeployer.deployFarm(proxyAddress);
} catch (error) {
logger.warn("Error while deploying to the cloud, please, cleanup any objects created before running again.")
throw error;
}
core.writeEnv(bootInstance);
logger.info(`File .env written, starting...`);
GBConfigService.init();