Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI/Serialize DB Connection Attributes #12770

Merged
merged 20 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions changelog/12770.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Filter DB connection attributes so only relevant attrs POST to backend
```
2 changes: 1 addition & 1 deletion ui/app/components/database-role-setting-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import Component from '@glimmer/component';
import { getStatementFields, getRoleFields } from '../utils/database-role-fields';
import { getStatementFields, getRoleFields } from '../utils/database-helpers';

export default class DatabaseRoleSettingForm extends Component {
get settingFields() {
Expand Down
160 changes: 2 additions & 158 deletions ui/app/models/database/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,163 +3,7 @@ import { computed } from '@ember/object';
import { alias, or } from '@ember/object/computed';
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
import fieldToAttrs, { expandAttributeMeta } from 'vault/utils/field-to-attrs';

const AVAILABLE_PLUGIN_TYPES = [
{
value: 'mongodb-database-plugin',
displayName: 'MongoDB',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'connection_url' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'write_concern', group: 'pluginConfig' },
{ attr: 'username_template', group: 'pluginConfig' },
{ attr: 'tls', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'tls_ca', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'root_rotation_statements', group: 'statements' },
],
},
{
value: 'mssql-database-plugin',
displayName: 'MSSQL',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'connection_url' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'username_template', group: 'pluginConfig' },
{ attr: 'max_open_connections', group: 'pluginConfig' },
{ attr: 'max_idle_connections', group: 'pluginConfig' },
{ attr: 'max_connection_lifetime', group: 'pluginConfig' },
{ attr: 'root_rotation_statements', group: 'statements' },
],
},
{
value: 'mysql-database-plugin',
displayName: 'MySQL/MariaDB',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'connection_url', group: 'pluginConfig' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'max_open_connections', group: 'pluginConfig' },
{ attr: 'max_idle_connections', group: 'pluginConfig' },
{ attr: 'max_connection_lifetime', group: 'pluginConfig' },
{ attr: 'username_template', group: 'pluginConfig' },
{ attr: 'tls', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'tls_ca', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'root_rotation_statements', group: 'statements' },
],
},
{
value: 'mysql-aurora-database-plugin',
displayName: 'MySQL (Aurora)',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'connection_url', group: 'pluginConfig' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'max_open_connections', group: 'pluginConfig' },
{ attr: 'max_idle_connections', group: 'pluginConfig' },
{ attr: 'max_connection_lifetime', group: 'pluginConfig' },
{ attr: 'username_template', group: 'pluginConfig' },
{ attr: 'tls', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'tls_ca', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'root_rotation_statements', group: 'statements' },
],
},
{
value: 'mysql-rds-database-plugin',
displayName: 'MySQL (RDS)',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'connection_url', group: 'pluginConfig' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'max_open_connections', group: 'pluginConfig' },
{ attr: 'max_idle_connections', group: 'pluginConfig' },
{ attr: 'max_connection_lifetime', group: 'pluginConfig' },
{ attr: 'username_template', group: 'pluginConfig' },
{ attr: 'tls', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'tls_ca', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'root_rotation_statements', group: 'statements' },
],
},
{
value: 'mysql-legacy-database-plugin',
displayName: 'MySQL (Legacy)',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'connection_url', group: 'pluginConfig' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'max_open_connections', group: 'pluginConfig' },
{ attr: 'max_idle_connections', group: 'pluginConfig' },
{ attr: 'max_connection_lifetime', group: 'pluginConfig' },
{ attr: 'username_template', group: 'pluginConfig' },
{ attr: 'tls', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'tls_ca', group: 'pluginConfig', subgroup: 'TLS options' },
{ attr: 'root_rotation_statements', group: 'statements' },
],
},
{
value: 'elasticsearch-database-plugin',
displayName: 'Elasticsearch',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'url', group: 'pluginConfig' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'ca_cert', group: 'pluginConfig' },
{ attr: 'ca_path', group: 'pluginConfig' },
{ attr: 'client_cert', group: 'pluginConfig' },
{ attr: 'client_key', group: 'pluginConfig' },
{ attr: 'tls_server_name', group: 'pluginConfig' },
{ attr: 'insecure', group: 'pluginConfig' },
{ attr: 'username_template', group: 'pluginConfig' },
],
},
{
value: 'oracle-database-plugin',
displayName: 'Oracle',
fields: [
{ attr: 'plugin_name' },
{ attr: 'name' },
{ attr: 'verify_connection' },
{ attr: 'password_policy' },
{ attr: 'connection_url', group: 'pluginConfig' },
{ attr: 'username', group: 'pluginConfig', show: false },
{ attr: 'password', group: 'pluginConfig', show: false },
{ attr: 'max_open_connections', group: 'pluginConfig' },
{ attr: 'max_idle_connections', group: 'pluginConfig' },
{ attr: 'max_connection_lifetime', group: 'pluginConfig' },
{ attr: 'username_template', group: 'pluginConfig' },
{ attr: 'root_rotation_statements', group: 'statements' },
],
}
];
import { AVAILABLE_PLUGIN_TYPES } from '../../utils/database-helpers';

/**
* fieldsToGroups helper fn
Expand Down Expand Up @@ -275,8 +119,8 @@ export default Model.extend({
defaultValue: '0s',
}),
insecure: attr('boolean', {
defaultValue: false,
label: 'Disable SSL verification',
defaultValue: false,
}),
tls: attr('string', {
label: 'TLS Certificate Key',
Expand Down
2 changes: 1 addition & 1 deletion ui/app/models/database/role.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { computed } from '@ember/object';
import { alias } from '@ember/object/computed';
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
import { getRoleFields } from '../../utils/database-role-fields';
import { getRoleFields } from '../../utils/database-helpers';

export default Model.extend({
idPrefix: 'role/',
Expand Down
22 changes: 22 additions & 0 deletions ui/app/serializers/database/connection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import RESTSerializer from '@ember-data/serializer/rest';
import { AVAILABLE_PLUGIN_TYPES } from '../../utils/database-helpers';

export default RESTSerializer.extend({
primaryKey: 'name',
Expand Down Expand Up @@ -45,4 +46,25 @@ export default RESTSerializer.extend({
}
return this._super(store, primaryModelClass, transformedPayload, id, requestType);
},

serialize(snapshot, requestType) {
let data = this._super(snapshot, requestType);
if (!data.plugin_name) {
return data;
}
let pluginType = AVAILABLE_PLUGIN_TYPES.find(plugin => plugin.value === data.plugin_name);
if (!pluginType) {
return data;
}
let pluginAttributes = pluginType.fields.map(fields => fields.attr).concat('backend');

// filter data to only allow plugin specific attrs
let allowedAttributes = Object.keys(data).filter(dataAttrs => pluginAttributes.includes(dataAttrs));
for (const key in data) {
if (!allowedAttributes.includes(key)) {
delete data[key];
}
}
return data;
},
});
12 changes: 6 additions & 6 deletions ui/app/templates/components/database-connection.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -307,30 +307,30 @@
</EmptyState>
{{else}}
{{#each @model.showAttrs as |attr|}}
{{#let attr.options.defaultDisplay as |defaultDisplay|}}
hellobontempo marked this conversation as resolved.
Show resolved Hide resolved
{{#let attr.options.defaultShown as |defaultDisplay|}}
{{#if (eq attr.type "object")}}
<InfoTableRow
@alwaysRender={{true}}
@defaultShown={{attr.options.defaultShown}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{stringify (get @model attr.name)}}
/>
{{else if (eq attr.type "array")}}
<InfoTableRow
@alwaysRender={{true}}
@defaultShown={{attr.options.defaultShown}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{or (get @model attr.name) defaultDisplay}}
@value={{get @model attr.name}}
@isLink={{true}}
@queryParam="role"
@type={{attr.type}}
/>
{{else}}
<InfoTableRow
@alwaysRender={{true}}
@defaultShown={{attr.options.defaultShown}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{or (get @model attr.name) defaultDisplay}}
hellobontempo marked this conversation as resolved.
Show resolved Hide resolved
@value={{get @model attr.name}}
/>
{{/if}}
{{/let}}
Expand Down
8 changes: 4 additions & 4 deletions ui/app/templates/components/database-role-edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@
</ToolbarActions>
</Toolbar>
{{#each @model.showFields as |attr|}}
{{#let attr.options.defaultDisplay as |defaultDisplay|}}
{{#let attr.options.defaultShown as |defaultDisplay|}}
{{#if (eq attr.type "object")}}
<InfoTableRow
@alwaysRender={{true}}
@defaultShown={{attr.options.defaultShown}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{stringify (get @model attr.name)}}
/>
{{else}}
<InfoTableRow
@alwaysRender={{true}}
@defaultShown={{attr.options.defaultShown}}
@defaultShown={{defaultDisplay}}
@label={{capitalize (or attr.options.label (humanize (dasherize attr.name)))}}
@value={{or (get @model attr.name) defaultDisplay}}
@value={{get @model attr.name}}
@isLink={{eq attr.name 'database'}}
/>
{{/if}}
Expand Down
Loading