Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 8a32dba

Browse files
author
JSpru
authored
Add luis:application:publish cmd (#376)
1 parent 3d47faa commit 8a32dba

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
import {CLIError, Command, flags} from '@microsoft/bf-cli-command'
7+
8+
const utils = require('../../../utils/index')
9+
10+
export default class LuisApplicationPublish extends Command {
11+
static description = 'Publishes a specific version of the application'
12+
13+
static examples = [`
14+
$ bf luis:application:publish --endpoint {ENDPOINT} --subscriptionKey {SUBSCRIPTION_KEY} --versionId {INITIAL_VERSION_ID} --appId {APP_ID} --staging {BOOLEAN}
15+
`]
16+
17+
static flags = {
18+
help: flags.help({char: 'h'}),
19+
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
20+
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}),
21+
appId: flags.string({description: 'LUIS applicaton id'}),
22+
versionId: flags.string({description: 'LUIS application initial version Id'}),
23+
staging: flags.string({description: 'Publishes application version to Staging slot, otherwise publish to production (default: false)'}),
24+
direct: flags.string({description: 'Available only in direct version query. Do not publish to staging or production (default: false)'})
25+
}
26+
27+
async run() {
28+
const {flags} = this.parse(LuisApplicationPublish)
29+
const flagLabels = Object.keys(LuisApplicationPublish.flags)
30+
const configDir = this.config.configDir
31+
32+
const {
33+
endpoint,
34+
subscriptionKey,
35+
appId,
36+
versionId,
37+
staging,
38+
direct
39+
} = await utils.processInputs(flags, flagLabels, configDir)
40+
41+
const requiredProps = {endpoint, subscriptionKey, appId, versionId}
42+
utils.validateRequiredProps(requiredProps)
43+
44+
const client = utils.getLUISClient(subscriptionKey, endpoint)
45+
46+
const applicationCreateObject = {
47+
versionId,
48+
isStaging: (staging === 'true'),
49+
directVersionPublish: (direct === 'true')
50+
}
51+
52+
try {
53+
const publishedAppData = await client.apps.publish(appId, applicationCreateObject)
54+
this.log(`App successfully published.\n${JSON.stringify(publishedAppData)}`)
55+
} catch (err) {
56+
throw new CLIError(`Failed to publish app: ${err}`)
57+
}
58+
}
59+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {expect, test} from '@oclif/test'
2+
const sinon = require('sinon')
3+
const uuidv1 = require('uuid/v1')
4+
const utils = require('../../../../src/utils/index')
5+
6+
describe('luis:application:publish', () => {
7+
8+
before(() => {
9+
const newAppId = uuidv1()
10+
})
11+
12+
beforeEach(() => {
13+
sinon.stub(utils, 'processInputs').returnsArg(0)
14+
})
15+
16+
afterEach(() => {
17+
sinon.restore();
18+
});
19+
20+
test
21+
.stdout()
22+
.command(['luis:application:publish', '--help'])
23+
.it('should print the help contents when --help is passed as an argument', ctx => {
24+
expect(ctx.stdout).to.contain('Publishes a specific version of the application')
25+
})
26+
27+
test
28+
.stdout()
29+
.stderr()
30+
.command(['luis:application:publish', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--appId', uuidv1()])
31+
.it('displays an error if any required input parameters are missing', ctx => {
32+
expect(ctx.stderr).to.contain(`Required input property 'versionId' missing.`)
33+
})
34+
35+
test
36+
.stdout()
37+
.stderr()
38+
.command(['luis:application:publish', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--versionId', '0.01'])
39+
.it('displays an error if any required input parameters are missing', ctx => {
40+
expect(ctx.stderr).to.contain(`Required input property 'subscriptionKey' missing.`)
41+
})
42+
43+
test
44+
.nock('https://westus.api.cognitive.microsoft.com', api => api
45+
.post(uri => uri.includes('publish'))
46+
.reply(201, {"versionId":"0.1","isStaging":true,"endpointUrl":"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/4e3d6aec-f79e-4688-b686-feaf6dc2feee","region":"westus","endpointRegion":"westus","failedRegions":"","publishedDateTime":"2019-11-21T21:54:30Z"})
47+
)
48+
.stdout()
49+
.command(['luis:application:publish', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--versionId', '0.01'])
50+
.it('publishes a luis app and displays the published app data', ctx => {
51+
expect(ctx.stdout).to.contain('versionId')
52+
expect(ctx.stdout).to.contain('isStaging')
53+
expect(ctx.stdout).to.contain('endpointUrl')
54+
expect(ctx.stdout).to.contain('publishedDateTime')
55+
})
56+
57+
test
58+
.nock('https://westus.api.cognitive.microsoft.com', api => api
59+
.post(uri => uri.includes('publish'))
60+
.reply(201, {"versionId":"0.1","isStaging":true,"endpointUrl":"https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/4e3d6aec-f79e-4688-b686-feaf6dc2feee","region":"westus","endpointRegion":"westus","failedRegions":"","publishedDateTime":"2019-11-21T21:54:30Z"})
61+
)
62+
.stdout()
63+
.command(['luis:application:publish', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--appId', uuidv1(), '--subscriptionKey', uuidv1(), '--versionId', '0.01', '--staging', 'true', '--direct', 'false' ])
64+
.it('publishes a luis app with optional flags and displays the published app data', ctx => {
65+
expect(ctx.stdout).to.contain('versionId')
66+
expect(ctx.stdout).to.contain('isStaging')
67+
expect(ctx.stdout).to.contain('endpointUrl')
68+
expect(ctx.stdout).to.contain('publishedDateTime')
69+
})
70+
71+
})

0 commit comments

Comments
 (0)