Adding arm token to config file and reading from it if present (#1168)
This commit is contained in:
Родитель
8f22a9d2d9
Коммит
2241623753
|
@ -18,6 +18,7 @@ export default class ConfigSetLuis extends Command {
|
|||
appId: flags.string({description: 'LUIS application Id'}),
|
||||
authoringKey: flags.string({description: 'LUIS cognitive services authoring key (aka Ocp-Apim-Subscription-Key).'}),
|
||||
subscriptionKey: flags.string({description: 'LUIS cognitive services subscription key (aka Ocp-Apim-Subscription-Key)'}),
|
||||
armToken: flags.string({description: 'User`s ARM token used to validate azure accounts information)'}),
|
||||
versionId: flags.string({description: 'LUIS version Id'}),
|
||||
endpoint: flags.string({description: 'LUIS application endpoint hostname, ex: <region>.api.cognitive.microsoft.com'}),
|
||||
}
|
||||
|
|
|
@ -36,5 +36,15 @@ describe('config:set:luis', () => {
|
|||
expect(config.luis__appId).to.contain('9999')
|
||||
expect(ctx.stdout).to.contain('appId set to 9999')
|
||||
})
|
||||
|
||||
test
|
||||
.stdout()
|
||||
.stderr()
|
||||
.command(['config:set:luis', '--armToken', '9999'])
|
||||
.it('displays an message indication arm token saved successfully', async ctx => {
|
||||
let config = await fs.readJSON(getConfigFile())
|
||||
expect(config.luis__armToken).to.contain('9999')
|
||||
expect(ctx.stdout).to.contain('armToken set to 9999')
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -14,13 +14,13 @@ export default class LuisApplicationAssignazureaccount extends Command {
|
|||
|
||||
static flags: flags.Input<any> = {
|
||||
help: flags.help({char: 'h'}),
|
||||
appId: flags.string({description: '(required) LUIS application Id (defaults to config:LUIS:appId)'}),
|
||||
appId: flags.string({description: '(required) LUIS application Id (defaults to config:set:luis --appId {APPLICATION_ID})'}),
|
||||
endpoint: flags.string({description: 'LUIS endpoint hostname'}),
|
||||
subscriptionKey: flags.string({description: '(required) LUIS cognitive services subscription key (default: config:LUIS:subscriptionKey)'}),
|
||||
subscriptionKey: flags.string({description: '(required) LUIS cognitive services subscription key (default: config:set:luis --subscriptionKey {SUBSCRIPTION_KEY})'}),
|
||||
azureSubscriptionId: flags.string({description: 'Azure Subscription Id', required: true}),
|
||||
resourceGroup: flags.string({description: 'Resource Group', required: true}),
|
||||
accountName: flags.string({description: 'Account name', required: true}),
|
||||
armToken: flags.string({description: 'The bearer authorization header to use; containing the user`s ARM token used to validate azure accounts information', required: true}),
|
||||
armToken: flags.string({description: '(required) User`s ARM token used to validate azure accounts information (default: config:set:luis --armToken {ARM_TOKEN})'}),
|
||||
json: flags.boolean({description: 'Display output as JSON'})
|
||||
}
|
||||
|
||||
|
@ -33,15 +33,16 @@ export default class LuisApplicationAssignazureaccount extends Command {
|
|||
appId,
|
||||
endpoint,
|
||||
subscriptionKey,
|
||||
armToken
|
||||
} = await utils.processInputs(flags, flagLabels, configDir)
|
||||
|
||||
const requiredProps = {appId, endpoint, subscriptionKey}
|
||||
const requiredProps = {appId, endpoint, subscriptionKey, armToken}
|
||||
utils.validateRequiredProps(requiredProps)
|
||||
|
||||
try {
|
||||
const messageData = await Application.assignAzureAccount(
|
||||
{appId, endpoint, subscriptionKey},
|
||||
flags.armToken,
|
||||
armToken,
|
||||
flags.azureSubscriptionId,
|
||||
flags.resourceGroup,
|
||||
flags.accountName
|
||||
|
@ -55,7 +56,7 @@ export default class LuisApplicationAssignazureaccount extends Command {
|
|||
this.log(output)
|
||||
|
||||
} catch (err) {
|
||||
throw new CLIError(`Failed to assign accout: ${err}`)
|
||||
throw new CLIError(`Failed to assign account: ${err}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -56,7 +56,14 @@ const isDirectory = (path: string): boolean => {
|
|||
}
|
||||
|
||||
const filterByAllowedConfigValues = (configObj: any, prefix: string) => {
|
||||
const allowedConfigValues = [`${prefix}appId`, `${prefix}endpoint`, `${prefix}region`, `${prefix}subscriptionKey`, `${prefix}versionId`, `${prefix}authoringKey`]
|
||||
const allowedConfigValues = [
|
||||
`${prefix}appId`,
|
||||
`${prefix}endpoint`,
|
||||
`${prefix}region`,
|
||||
`${prefix}subscriptionKey`,
|
||||
`${prefix}versionId`,
|
||||
`${prefix}authoringKey`,
|
||||
`${prefix}armToken`]
|
||||
const filtered = Object.keys(configObj)
|
||||
.filter(key => allowedConfigValues.includes(key))
|
||||
.reduce((filteredConfigObj: any, key) => {
|
||||
|
|
|
@ -13,6 +13,14 @@ describe('luis:application:assignazureaccount', () => {
|
|||
sinon.restore();
|
||||
});
|
||||
|
||||
test
|
||||
.stderr()
|
||||
.command(['luis:application:assignazureaccount', '--endpoint', 'https://westus.api.cognitive.microsoft.com', '--subscriptionKey', uuidv1(), '--azureSubscriptionId', uuidv1(), '--resourceGroup', 'adfhrkg', '--accountName', 'sfgsgdszg', '--appId', uuidv1()])
|
||||
.exit(1)
|
||||
.it('Errors if arm token not passed', ctx => {
|
||||
expect(ctx.stderr).to.contain(`Required input property 'armToken' missing. Please pass it in as a flag or set it in the config file.`)
|
||||
})
|
||||
|
||||
test
|
||||
.nock('https://westus.api.cognitive.microsoft.com', api => api
|
||||
.post(uri => uri.includes('apps'))
|
||||
|
|
Загрузка…
Ссылка в новой задаче