UI - add description as helpText, and add sensitive from x-vault-displaySensitive (#6411)

* add description from openAPI as helpText in the models, and add sensitive from x-vault-displaySensitive

* use TypeDurationSecond for TTLs on the GitHub auth method config

* remove empty vals in a loop and add tests

* hold off on changing GH config

* remove isEmpty import

* fix defaultValue
This commit is contained in:
Matthew Irish 2019-03-14 16:12:13 -05:00 committed by GitHub
parent f5dbe1933a
commit 96f7ccd71e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 13 deletions

View File

@ -2,6 +2,7 @@ import DS from 'ember-data';
const { attr } = DS;
import { assign } from '@ember/polyfills';
import { isEmpty } from '@ember/utils';
import { camelize, capitalize } from '@ember/string';
export const expandOpenApiProps = function(props) {
let attrs = {};
@ -18,25 +19,25 @@ export const expandOpenApiProps = function(props) {
if (details.format === 'seconds') {
editType = 'ttl';
} else if (details.items) {
editType = details.items.type + details.type.capitalize();
editType = details.items.type + capitalize(details.type);
}
attrs[prop.camelize()] = {
let attrDefn = {
editType: editType,
type: details.type,
helpText: details.description,
sensitive: details['x-vault-displaySensitive'],
label: details['x-vault-displayName'],
possibleValues: details['enum'],
defaultValue:
details['x-vault-displayValue'] || (!isEmpty(details['default']) ? details['default'] : null),
};
if (details['x-vault-displayName']) {
attrs[prop.camelize()].label = details['x-vault-displayName'];
}
if (details['enum']) {
attrs[prop.camelize()].possibleValues = details['enum'];
}
if (details['x-vault-displayValue']) {
attrs[prop.camelize()].defaultValue = details['x-vault-displayValue'];
} else {
if (!isEmpty(details['default'])) {
attrs[prop.camelize()].defaultValue = details['default'];
// loop to remove empty vals
for (let attrProp in attrDefn) {
if (attrDefn[attrProp] == null) {
delete attrDefn[attrProp];
}
}
attrs[camelize(prop)] = attrDefn;
}
return attrs;
};

View File

@ -8,6 +8,7 @@ module('Unit | Util | OpenAPI Data Utilities', function() {
ttl: {
type: 'string',
format: 'seconds',
description: 'this is a TTL!',
'x-vault-displayName': 'TTL',
},
'awesome-people': {
@ -30,9 +31,15 @@ module('Unit | Util | OpenAPI Data Utilities', function() {
default: 30,
type: 'integer',
},
'super-secret': {
type: 'string',
'x-vault-displaySensitive': true,
description: 'A really secret thing',
},
};
const EXPANDED_PROPS = {
ttl: {
helpText: 'this is a TTL!',
editType: 'ttl',
type: 'string',
label: 'TTL',
@ -57,6 +64,13 @@ module('Unit | Util | OpenAPI Data Utilities', function() {
type: 'number',
defaultValue: 30,
},
superSecret: {
type: 'string',
editType: 'string',
sensitive: true,
helpText: 'A really secret thing',
},
};
const EXISTING_MODEL_ATTRS = [
@ -93,6 +107,7 @@ module('Unit | Util | OpenAPI Data Utilities', function() {
editType: 'ttl',
type: 'string',
label: 'TTL',
helpText: 'this is a TTL!',
}),
awesomePeople: attr({
label: 'People Who Are Awesome',
@ -105,6 +120,12 @@ module('Unit | Util | OpenAPI Data Utilities', function() {
editType: 'string',
possibleValues: ['vanilla', 'chocolate', 'strawberry'],
}),
superSecret: attr('string', {
type: 'string',
editType: 'string',
sensitive: true,
description: 'A really secret thing',
}),
};
const NEW_FIELDS = ['one', 'two', 'three'];