Skip to content

Commit

Permalink
fix(core.gbapp): Fixing loading of instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 15, 2019
1 parent 5b320e5 commit bc9c588
Show file tree
Hide file tree
Showing 10 changed files with 7,180 additions and 6,345 deletions.
1 change: 0 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
"arrowParens": "avoid",
"semi": true,
"singleQuote": true

}
4 changes: 1 addition & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ node_js:

notifications:
email: false

before_script:
- npm run build

script:
- npm run coveralls

branches:
only:
Expand Down
13,158 changes: 6,932 additions & 6,226 deletions package-lock.json

Large diffs are not rendered by default.

102 changes: 51 additions & 51 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,103 +47,103 @@
"commit": "git-cz"
},
"dependencies": {
"@microsoft/microsoft-graph-client": "1.5.2",
"@semantic-release/exec": "^3.3.2",
"@microsoft/microsoft-graph-client": "1.6.0",
"@semantic-release/exec": "3.3.2",
"adal-node": "0.1.28",
"async": "2.6.2",
"async-promises": "0.2.1",
"azure-arm-cognitiveservices": "2.4.1",
"async-promises": "0.2.2",
"azure-arm-cognitiveservices": "3.0.0",
"azure-arm-resource": "7.3.0",
"azure-arm-search": "^1.3.0-preview",
"azure-arm-sql": "5.6.0",
"azure-arm-search": "1.3.0-preview",
"azure-arm-sql": "5.7.0",
"azure-arm-website": "5.7.0",
"bluebird": "^3.5.4",
"body-parser": "1.18.3",
"botbuilder": "4.3.4",
"botbuilder-ai": "4.3.4",
"botbuilder-azure": "4.3.4",
"bluebird": "3.5.4",
"body-parser": "1.19.0",
"botbuilder": "4.4.0",
"botbuilder-ai": "4.4.0",
"botbuilder-azure": "4.4.0",
"botbuilder-choices": "4.0.0-preview1.2",
"botbuilder-dialogs": "4.3.4",
"botbuilder-dialogs": "4.4.0",
"botbuilder-prompts": "4.0.0-preview1.2",
"botlib": "0.1.24",
"botlib": "1.2.0",
"chai": "4.2.0",
"child_process": "^1.0.2",
"chokidar": "2.1.5",
"cli-spinner": "^0.2.10",
"csv-parse": "4.3.4",
"child_process": "1.0.2",
"chokidar": "3.0.0",
"cli-spinner": "0.2.10",
"csv-parse": "4.4.1",
"dotenv-extended": "2.4.0",
"express": "4.16.4",
"express-promise-router": "3.0.3",
"fs-extra": "7.0.1",
"ip": "^1.1.5",
"js-beautify": "^1.9.1",
"fs-extra": "8.0.0",
"ip": "1.1.5",
"js-beautify": "1.10.0",
"localize": "0.4.7",
"marked": "0.6.2",
"mocha": "6.0.2",
"mocha": "6.1.4",
"mocha-typescript": "1.1.17",
"ms": "2.1.1",
"ms-rest-azure": "2.6.0",
"ms-rest-js": "^1.0.1",
"ms-rest-js": "1.0.1",
"nexmo": "2.4.1",
"ngrok": "3.1.1",
"nyc": "13.3.0",
"nyc": "14.1.1",
"opn": "6.0.0",
"pragmatismo-io-framework": "1.0.19",
"process-exists": "3.1.0",
"public-ip": "^3.0.0",
"public-ip": "3.1.0",
"reflect-metadata": "0.1.13",
"request-promise": "4.2.4",
"request-promise-native": "1.0.7",
"scanf": "^1.0.2",
"sequelize": "^5.2.12",
"sequelize-typescript": "0.6.9",
"scanf": "1.0.2",
"sequelize": "5.8.6",
"sequelize-typescript": "0.6.10",
"shx": "0.3.2",
"simple-git": "1.110.0",
"sqlite3": "4.0.6",
"strict-password-generator": "^1.1.2",
"simple-git": "1.113.0",
"sqlite3": "4.0.8",
"strict-password-generator": "1.1.2",
"swagger-client": "3.8.25",
"tedious": "6.1.0",
"temperature-js": "^0.1.0",
"ts-node": "8.0.3",
"tedious": "6.1.1",
"temperature-js": "0.1.0",
"ts-node": "8.1.0",
"typedoc": "0.14.2",
"typedoc-plugin-external-module-name": "^2.0.0",
"typedoc-plugin-markdown": "^1.1.27",
"typescript": "3.4.1",
"typedoc-plugin-external-module-name": "2.1.0",
"typedoc-plugin-markdown": "1.2.0",
"typescript": "3.4.5",
"url-join": "4.0.0",
"vbscript-to-typescript": "^1.0.8",
"vbscript-to-typescript": "1.0.8",
"wait-until": "0.0.2",
"walk-promise": "0.2.0",
"winston": "3.2.1"
},
"devDependencies": {
"@semantic-release/changelog": "^3.0.2",
"@semantic-release/commit-analyzer": "^6.1.0",
"@semantic-release/git": "^7.0.8",
"@semantic-release/github": "^5.2.10",
"@semantic-release/npm": "^5.1.4",
"@semantic-release/release-notes-generator": "^7.1.4",
"@semantic-release/changelog": "3.0.2",
"@semantic-release/commit-analyzer": "6.1.0",
"@semantic-release/git": "7.0.8",
"@semantic-release/github": "5.2.10",
"@semantic-release/npm": "5.1.7",
"@semantic-release/release-notes-generator": "7.1.4",
"@types/chai": "4.1.7",
"@types/mocha": "5.2.6",
"@types/sequelize": "4.27.46",
"@types/sequelize": "4.27.49",
"@types/url-join": "4.0.0",
"@types/winston": "2.4.4",
"ban-sensitive-files": "1.9.2",
"commitizen": "^3.0.7",
"coveralls": "^3.0.3",
"cz-conventional-changelog": "^2.1.0",
"commitizen": "3.1.1",
"coveralls": "3.0.3",
"cz-conventional-changelog": "2.1.0",
"dependency-check": "3.3.0",
"deps-ok": "1.4.1",
"git-issues": "1.3.1",
"license-checker": "25.0.1",
"nsp": "3.2.1",
"pre-git": "3.17.1",
"prettier-standard": "9.1.1",
"semantic-release": "^15.13.3",
"semantic-release": "15.13.12",
"standard": "12.0.1",
"travis-deploy-once": "5.0.11",
"ts-loader": "^5.3.3",
"tslint": "^5.15.0",
"tslint-microsoft-contrib": "^6.1.0"
"ts-loader": "6.0.0",
"tslint": "5.16.0",
"tslint-microsoft-contrib": "6.1.1"
},
"eslintConfig": {
"env": {
Expand Down
134 changes: 99 additions & 35 deletions packages/azuredeployer.gbapp/services/AzureDeployerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,37 @@ export class AzureDeployerService implements IGBInstallationDeployer {
};
}

public async botExists(botId, group, endpoint) {
const baseUrl = `https://management.azure.com/`;
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');

const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
const httpClient = new ServiceClient();

const parameters = {
properties: {
endpoint: endpoint
}
};

const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'GET', JSON.stringify(parameters));
const res = await httpClient.sendRequest(req);
// CHECK
if (!JSON.parse(res.bodyAsText).id) {
return false;
}
else {
return true;
}
}


public async updateBotProxy(botId, group, endpoint) {
const baseUrl = `https://management.azure.com/`;
const username = GBConfigService.get('CLOUD_USERNAME');
Expand Down Expand Up @@ -229,6 +260,39 @@ export class AzureDeployerService implements IGBInstallationDeployer {
GBLog.info(`Bot proxy updated at: ${endpoint}.`);
}

public async updateBot(botId: string, group: string, name: string,
description: string, endpoint: string, iconUrl: string) {
const baseUrl = `https://management.azure.com/`;
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
const subscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');

const accessToken = await GBAdminService.getADALTokenFromUsername(username, password);
const httpClient = new ServiceClient();

const parameters = {
properties: {
description: description,
displayName: name,
endpoint: endpoint,
iconUrl: iconUrl
}
};

const query = `subscriptions/${subscriptionId}/resourceGroups/${group}/providers/${
this.provider
}/botServices/${botId}?api-version=${this.apiVersion}`;
const url = urlJoin(baseUrl, query);
const req = AzureDeployerService.createRequestObject(url, accessToken, 'PATCH', JSON.stringify(parameters));
const res = await httpClient.sendRequest(req);
// CHECK
if (!JSON.parse(res.bodyAsText).id) {
throw res.bodyAsText;
}
GBLog.info(`Bot proxy updated at: ${endpoint}.`);
}


public async openStorageFirewall(groupName, serverName) {
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
Expand Down Expand Up @@ -296,7 +360,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
instance.searchIndex = 'azuresql-index';
instance.searchIndexer = 'azuresql-indexer';
instance.searchKey = searchKeys.primaryKey;
this.deployer.rebuildIndex(instance, this.deployer);
this.deployer.rebuildIndex(instance, this.getKBSearchSchema(instance.searchIndex));

GBLog.info(`Deploying Speech...`);
const speech = await this.createSpeech(name, `${name}-speech`, instance.cloudLocation);
Expand Down Expand Up @@ -378,43 +442,10 @@ export class AzureDeployerService implements IGBInstallationDeployer {
this.deployFarm(url, instance, credentials, subscriptionId);
}

private initServices(credentials: any, subscriptionId: string) {
this.resourceClient = new ResourceManagementClient.default(credentials, subscriptionId);
this.webSiteClient = new WebSiteManagementClient(credentials, subscriptionId);
this.storageClient = new SqlManagementClient(credentials, subscriptionId);
this.cognitiveClient = new CognitiveServicesManagementClient(credentials, subscriptionId);
this.searchClient = new SearchManagementClient(credentials, subscriptionId);
this.accessToken = credentials.tokenCache._entries[0].accessToken;
}

private async createStorageServer(group, name, administratorLogin, administratorPassword, serverName, location) {
const params = {
location: location,
administratorLogin: administratorLogin,
administratorLoginPassword: administratorPassword,
fullyQualifiedDomainName: `${serverName}.database.windows.net`
};

return this.storageClient.servers.createOrUpdate(group, name, params);
}

private async registerProviders(subscriptionId, baseUrl, accessToken) {
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
const requestUrl = urlJoin(baseUrl, query);

const req = new WebResource();
req.method = 'POST';
req.url = requestUrl;
req.headers = <any>{};
req.headers['Content-Type'] = 'application/json; charset=utf-8';
req.headers['accept-language'] = '*';
(req.headers as any).Authorization = `Bearer ${accessToken}`;
}

/**
* @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(
public async internalDeployBot(
instance,
accessToken,
botId,
Expand Down Expand Up @@ -490,6 +521,39 @@ export class AzureDeployerService implements IGBInstallationDeployer {
});
}

private initServices(credentials: any, subscriptionId: string) {
this.resourceClient = new ResourceManagementClient.default(credentials, subscriptionId);
this.webSiteClient = new WebSiteManagementClient(credentials, subscriptionId);
this.storageClient = new SqlManagementClient(credentials, subscriptionId);
this.cognitiveClient = new CognitiveServicesManagementClient(credentials, subscriptionId);
this.searchClient = new SearchManagementClient(credentials, subscriptionId);
this.accessToken = credentials.tokenCache._entries[0].accessToken;
}

private async createStorageServer(group, name, administratorLogin, administratorPassword, serverName, location) {
const params = {
location: location,
administratorLogin: administratorLogin,
administratorLoginPassword: administratorPassword,
fullyQualifiedDomainName: `${serverName}.database.windows.net`
};

return this.storageClient.servers.createOrUpdate(group, name, params);
}

private async registerProviders(subscriptionId, baseUrl, accessToken) {
const query = `subscriptions/${subscriptionId}/providers/${this.provider}/register?api-version=2018-02-01`;
const requestUrl = urlJoin(baseUrl, query);

const req = new WebResource();
req.method = 'POST';
req.url = requestUrl;
req.headers = <any>{};
req.headers['Content-Type'] = 'application/json; charset=utf-8';
req.headers['accept-language'] = '*';
(req.headers as any).Authorization = `Bearer ${accessToken}`;
}

private async createNLPService(
name: string,
description: string,
Expand Down
3 changes: 3 additions & 0 deletions packages/core.gbapp/services/GBConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ export class GBConfigService {
case 'STORAGE_STORAGE':
value = './guaribas.sqlite';
break;
case 'GBKB_AUTO_DEPLOY':
value = false;
break;
case 'ADDITIONAL_DEPLOY_PATH':
value = undefined;
break;
Expand Down
Loading

0 comments on commit bc9c588

Please sign in to comment.