Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit d4d380f

Browse files
DiegoCardozo94VictorGrycuk
authored andcommitted
[Botskills] Implement support for --gov (#2850)
* Implement Azure Government Support * Implement AZ Government in connectSkill * Implement AZ Government in refreshSkill Co-authored-by: Victor Grycuk <[email protected]>
1 parent 34d195c commit d4d380f

File tree

6 files changed

+38
-3
lines changed

6 files changed

+38
-3
lines changed

tools/botskills/src/functionality/connectSkill.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
ISkillManifest,
1717
IUtteranceSource
1818
} from '../models';
19-
import { AuthenticationUtils, ChildProcessUtils, getDispatchNames, isValidCultures, wrapPathWithQuotes } from '../utils';
19+
import { AuthenticationUtils, ChildProcessUtils, getDispatchNames, isCloudGovernment, isValidCultures, wrapPathWithQuotes } from '../utils';
2020
import { RefreshSkill } from './refreshSkill';
2121

2222
export class ConnectSkill {
@@ -211,12 +211,20 @@ Make sure you have a Dispatch for the cultures you are trying to connect, and th
211211
try {
212212
// tslint:disable-next-line:no-backbone-get-set-outside-model
213213
const luisApp: string = <string> executionModelByCulture.get('luisApp');
214+
214215
// Update Dispatch file
215216
const dispatchAddCommandArguments: string[] = ['--type', '--name', '--filePath', '--intentName', '--dataFolder', '--dispatch'];
217+
216218
dispatchAddCommandArguments.forEach((argument: string): void => {
217219
const argumentValue: string = <string> executionModelByCulture.get(argument);
218220
dispatchAddCommand.push(...[argument, argumentValue]);
219221
});
222+
223+
// Append '--gov true' if it is a government cloud
224+
if (await isCloudGovernment() === true) {
225+
dispatchAddCommand.push('--gov', 'true');
226+
}
227+
220228
await this.runCommand(dispatchAddCommand, `Executing dispatch add for the ${culture} ${luisApp} LU file`);
221229
} catch (err) {
222230
throw new Error(`There was an error in the dispatch add command:\nCommand: ${dispatchAddCommand.join(' ')}\n${err}`);

tools/botskills/src/functionality/refreshSkill.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { existsSync, readFileSync } from 'fs';
66
import { join } from 'path';
77
import { ConsoleLogger, ILogger } from '../logger';
88
import { ICognitiveModel, IRefreshConfiguration } from '../models';
9-
import { ChildProcessUtils, getDispatchNames, wrapPathWithQuotes } from '../utils';
9+
import { ChildProcessUtils, getDispatchNames, isCloudGovernment, wrapPathWithQuotes } from '../utils';
1010

1111
export class RefreshSkill {
1212
public logger: ILogger;
@@ -44,6 +44,10 @@ export class RefreshSkill {
4444
const argumentValue: string = <string> executionModelByCulture.get(argument);
4545
dispatchRefreshCommand.push(...[argument, argumentValue]);
4646
});
47+
// Append '--gov true' if it is a government cloud
48+
if (await isCloudGovernment() === true) {
49+
dispatchRefreshCommand.push('--gov', 'true');
50+
}
4751
await this.runCommand(
4852
dispatchRefreshCommand,
4953
`Executing dispatch refresh for the ${dispatchName} file`);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Copyright(c) Microsoft Corporation.All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
export interface ICloud {
7+
isActive: boolean;
8+
name: string;
9+
}

tools/botskills/src/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ export {
2828
IUtterance,
2929
IUtteranceSource } from './skillManifest';
3030
export { IRefreshConfiguration } from './refreshConfiguration';
31+
export { ICloud } from './cloud';

tools/botskills/src/utils/azUtils.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
import { gte } from 'semver';
7+
import { ICloud } from '../models/Cloud';
78
import { ChildProcessUtils } from './childProcessUtils';
89

910
const azPreviewMessage: string = `Command group 'bot' is in preview. It may be changed/removed in a future release.\r\n`;
@@ -36,3 +37,15 @@ export async function isValidAzVersion(): Promise<boolean> {
3637

3738
return false;
3839
}
40+
41+
/**
42+
* @returns Returns TRUE if the AzureUSGovernment is active
43+
*/
44+
// tslint:disable-next-line:export-name
45+
export async function isCloudGovernment(): Promise<boolean> {
46+
const azCloudListCommand: string[] = ['az', 'cloud', 'list'];
47+
// tslint:disable-next-line: no-unsafe-any
48+
const azCloudList: ICloud[] = JSON.parse(await childProcess.tryExecute(azCloudListCommand));
49+
50+
return azCloudList.some((cloud: ICloud) => cloud.isActive && cloud.name === 'AzureUSGovernment');
51+
}

tools/botskills/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
export { AuthenticationUtils } from './authenticationUtils';
7-
export { isAzPreviewMessage, isValidAzVersion } from './azUtils';
7+
export { isAzPreviewMessage, isCloudGovernment, isValidAzVersion } from './azUtils';
88
export { ChildProcessUtils } from './childProcessUtils';
99
export { getDispatchNames } from './dispatchUtils';
1010
export { sanitizePath, wrapPathWithQuotes } from './sanitizationUtils';

0 commit comments

Comments
 (0)