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/create edit transformation fixes #9668

Merged
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
9 changes: 5 additions & 4 deletions ui/app/adapters/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default ApplicationAdapter.extend({

deleteRecord(store, type, snapshot) {
const { id } = snapshot;
return this.ajax(this.urlForRole(snapshot.record.get('backend'), id), 'DELETE');
return this.ajax(this.urlForTransformations(snapshot.record.get('backend'), id), 'DELETE');
},

pathForType() {
Expand Down Expand Up @@ -63,9 +63,10 @@ export default ApplicationAdapter.extend({
const { id, backend } = query;
let zeroAddressAjax = resolve();
const queryAjax = this.ajax(this.urlForTransformations(backend, id), 'GET', this.optionsForQuery(id));
if (!id) {
zeroAddressAjax = this.findAllZeroAddress(store, query);
}
// TODO: come back to why you need this, carry over.
// if (!id) {
// zeroAddressAjax = this.findAllZeroAddress(store, query);
// }

return allSettled([queryAjax, zeroAddressAjax]).then(results => {
// query result 404d, so throw the adapterError
Expand Down
2 changes: 1 addition & 1 deletion ui/app/components/role-edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default Component.extend(FocusOnInsertMixin, {
createOrUpdate(type, event) {
event.preventDefault();

const modelId = this.get('model.id') || this.get('model.name'); //ARG TODO this is not okay
const modelId = this.get('model.id') || this.get('model.name'); // ARG TODO this is not okay
// prevent from submitting if there's no key
// maybe do something fancier later
if (type === 'create' && isBlank(modelId)) {
Expand Down
8 changes: 8 additions & 0 deletions ui/app/components/transform-show-transformation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import RoleEdit from './role-edit';

export default RoleEdit.extend({
init() {
this._super(...arguments);
this.set('backendType', 'transform');
},
});
2 changes: 1 addition & 1 deletion ui/app/helpers/options-for-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const SECRET_BACKENDS = {
transform: {
displayName: 'Transformation',
navigateTree: false,
listItemPartial: 'partials/secret-list/item',
listItemPartial: 'partials/secret-list/transform-transformation-item',
tabs: [
{
name: 'transformations',
Expand Down
53 changes: 25 additions & 28 deletions ui/app/models/transform.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { alias } from '@ember/object/computed';
import { computed } from '@ember/object';
import DS from 'ember-data';
import lazyCapabilities, { apiPath } from 'vault/macros/lazy-capabilities';
import { apiPath } from 'vault/macros/lazy-capabilities';
import { expandAttributeMeta } from 'vault/utils/field-to-attrs';
import attachCapabilities from 'vault/lib/attach-capabilities';

const { attr } = DS;

Expand Down Expand Up @@ -35,11 +35,10 @@ const TWEAK_SOURCE = [
},
];

export default DS.Model.extend({
const Model = DS.Model.extend({
// TODO: for now, commenting out openApi info, but keeping here just in case we end up using it.
// useOpenAPI: true,
// getHelpUrl: function(backend) {
// console.log(backend, 'Backend');
// return `/v1/${backend}?help=1`;
// },
name: attr('string', {
Expand All @@ -55,51 +54,49 @@ export default DS.Model.extend({
subText:
'Vault provides two types of transformations: Format Preserving Encryption (FPE) is reversible, while Masking is not.',
}),
template: attr('stringArray', {
label: 'Template', // TODO: make this required for making a transformation
subLabel: 'Template Name',
subText:
'Templates allow Vault to determine what and how to capture the value to be transformed. Type to use an existing template or create a new one.',
editType: 'searchSelect',
fallbackComponent: 'string-list',
models: ['transform/template'],
}),
tweak_source: attr('string', {
defaultValue: 'supplied',
label: 'Tweak source',
possibleValues: TWEAK_SOURCE,
subText: `A tweak value is used when performing FPE transformations. This can be supplied, generated, or internal.`, // TODO: I do not include the link here. Need to figure out the best way to approach this.
}),
masking_character: attr('string', {
defaultValue: '*',
label: 'Masking character',
subText: 'Specify which character you’d like to mask your data.',
}),
allowed_roles: attr('stringArray', {
template: attr('string', {
editType: 'searchSelect',
fallbackComponent: 'string-list',
label: 'Template', // TODO: make this required for making a transformation
models: ['transform/template'],
subLabel: 'Template Name',
subText:
'Templates allow Vault to determine what and how to capture the value to be transformed. Type to use an existing template or create a new one.',
}),
templates: attr('array'), // TODO: remove once BE changes the returned property to a singular template on the GET request.
allowed_roles: attr('string', {
label: 'Allowed roles',
editType: 'searchSelect',
fallbackComponent: 'string-list',
models: ['transform/role'],
subText: 'Search for an existing role, type a new role to create it, or use a wildcard (*).',
}),
transformAttrs: computed(function() {
transformAttrs: computed('type', function() {
// TODO: group them into sections/groups. Right now, we don't different between required and not required as we do by hiding options.
// will default to design mocks on how to handle as it will likely be a different pattern using client-side validation, which we have not done before
return ['name', 'type', 'template', 'tweak_source', 'masking_characters', 'allowed_roles'];
if (this.type === 'masking') {
return ['name', 'type', 'masking_character', 'template', 'templates', 'allowed_roles'];
}
return ['name', 'type', 'tweak_source', 'template', 'templates', 'allowed_roles'];
}),
transformFieldAttrs: computed('transformAttrs', function() {
return expandAttributeMeta(this, this.get('transformAttrs'));
}),
updatePath: lazyCapabilities(apiPath`${'backend'}/transforms/${'id'}`, 'backend', 'id'),
canDelete: alias('updatePath.canDelete'),
canEdit: alias('updatePath.canUpdate'),
canRead: alias('updatePath.canRead'),

generatePath: lazyCapabilities(apiPath`${'backend'}/creds/${'id'}`, 'backend', 'id'),
canGenerate: alias('generatePath.canUpdate'),

signPath: lazyCapabilities(apiPath`${'backend'}/sign/${'id'}`, 'backend', 'id'),
canSign: alias('signPath.canUpdate'),
// zeroAddressPath: lazyCapabilities(apiPath`${'backend'}/config/zeroaddress`, 'backend'),
// canEditZeroAddress: alias('zeroAddressPath.canUpdate'),
});

zeroAddressPath: lazyCapabilities(apiPath`${'backend'}/config/zeroaddress`, 'backend'),
canEditZeroAddress: alias('zeroAddressPath.canUpdate'),
export default attachCapabilities(Model, {
updatePath: apiPath`transform/transformation/${'id'}`,
});
11 changes: 11 additions & 0 deletions ui/app/serializers/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ApplicationSerializer from './application';

export default ApplicationSerializer.extend({
normalizeResponse(store, primaryModelClass, payload, id, requestType) {
if (payload.data.masking_character) {
payload.data.masking_character = String.fromCharCode(payload.data.masking_character);
}
// TODO: the BE is working on a ticket to amend these response, so revisit.
return this._super(store, primaryModelClass, payload, id, requestType);
},
});
8 changes: 8 additions & 0 deletions ui/app/styles/components/transform-edit.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.copy-text {
background: $ui-gray-010;

& > code {
color: $ui-gray-800;
padding: 14px;
}
}
1 change: 1 addition & 0 deletions ui/app/styles/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
@import './components/token-expire-warning';
@import './components/toolbar';
@import './components/tool-tip';
@import './components/transform-edit.scss';
@import './components/transit-card';
@import './components/ttl-picker2';
@import './components/unseal-warning';
Expand Down
3 changes: 2 additions & 1 deletion ui/app/styles/core/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ label {
.b-checkbox .is-label {
color: $grey-darker;
display: inline-block;
font-size: $size-small;
font-size: $body-size;
font-weight: $font-weight-bold;

&:not(:last-child) {
Expand Down Expand Up @@ -73,6 +73,7 @@ label {
.sub-text {
color: $grey;
margin-bottom: 0.25rem;
font-size: $size-8;
}
.input,
.textarea,
Expand Down
4 changes: 4 additions & 0 deletions ui/app/styles/core/helpers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,10 @@
.has-top-margin-xl {
margin-top: $spacing-xl;
}
.has-border-bottom-light {
border-radius: 0;
border-bottom: 1px solid $grey-light;
}
.has-border-danger {
border: 1px solid $danger;
}
Expand Down
3 changes: 1 addition & 2 deletions ui/app/templates/components/transform-edit-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
@model={{model}}
/>
{{/each}}
<FormFieldGroups @model={{model}} @mode="create" />
</div>
<div class="field is-grouped-split box is-fullwidth is-bottomless">
<div class="control">
Expand All @@ -21,7 +20,7 @@
data-test-role-ssh-create=true
>
{{#if (eq mode 'create')}}
Create role
Create transformation
{{else if (eq mode 'edit')}}
Save
{{/if}}
Expand Down
48 changes: 48 additions & 0 deletions ui/app/templates/components/transform-show-transformation.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="box is-fullwidth is-sideless is-paddingless is-marginless">
{{#each model.transformFieldAttrs as |attr|}}
{{#if (eq attr.type "object")}}
{{info-table-row label=(capitalize (or attr.options.label (humanize (dasherize attr.name)))) value=(stringify (get model attr.name))}}
{{else}}
{{info-table-row label=(capitalize (or attr.options.label (humanize (dasherize attr.name)))) value=(get model attr.name)}}
{{/if}}
{{/each}}
</div>

<div class="has-top-margin-xl has-bottom-margin-s">
<label class="title has-border-bottom-light page-header">CLI Commands</label>
{{!-- ARG TODO make these components? --}}
<div class="has-bottom-margin-s">
<h2 class="title is-6">Encode</h2>
<div class="has-bottom-margin-s">
<span class="helper-text has-text-grey">
To test the encoding capability of your transformation, use the following command. It will output an encoded_value.
</span>
</div>
<div class="copy-text level">
{{#let "vault write transform/encode/payments value=<enter your value here>" as |copyEncodeCommand|}}
<code>vault write transform/encode/payments value=&lt;enter your value here&gt;</code>
<CopyButton class="button is-transparent level-right" @clipboardText={{copyEncodeCommand}}
@buttonType="button" @success={{action (set-flash-message 'Command copied!')}}>
<Icon @size='l' @glyph="copy-action" aria-label="Copy" />
</CopyButton>
{{/let}}
</div>
</div>
<div>
<h2 class="title is-6">Decode</h2>
<div class="has-bottom-margin-s">
<span class="helper-text has-text-grey">
To test decoding capability of your transformation, use the encoded_value in the following command. It should return your original input.
</span>
</div>
<div class="copy-text level">
{{#let "vault write transform/decode/payments value=<enter your value here>" as |copyDecodeCommand|}}
<code>vault write transform/decode/payments value=&lt;enter your value here&gt;</code>
<CopyButton class="button is-transparent level-right" @clipboardText={{copyDecodeCommand}}
@buttonType="button" @success={{action (set-flash-message 'Command copied!')}}>
<Icon @size='l' @glyph="copy-action" aria-label="Copy" />
</CopyButton>
{{/let}}
</div>
</div>
</div>
44 changes: 14 additions & 30 deletions ui/app/templates/components/transformation-edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
{{else if (eq mode 'edit')}}
Edit Transformation
{{else}}
SSH role <code>{{model.id}}</code>
Transformation <code>{{model.id}}</code>
{{/if}}
</h1>
</p.levelLeft>
Expand All @@ -24,55 +24,39 @@
{{#if (eq mode "show")}}
<Toolbar>
<ToolbarActions>
{{#if (eq model.keyType "otp")}}
<ToolbarSecretLink
@secret={{model.id}}
@mode="credentials"
@data-test-backend-credentials=true
@replace=true
>
Generate Credential
</ToolbarSecretLink>
{{else}}
<ToolbarSecretLink
@secret={{model.id}}
@mode="sign"
@data-test-backend-credentials=true
@replace=true
>
Sign Keys
</ToolbarSecretLink>
{{/if}}
{{!-- TODO: update these actions, show delete grey out if not allowed --}}
{{#if (or model.canUpdate model.canDelete)}}
<div class="toolbar-separator" />
{{/if}}
{{#if model.canDelete}}
{{!-- TODO only allow deletion when not in use by a role --}}
<ConfirmAction
@buttonClasses="toolbar-link"
@onConfirmAction={{action "delete"}}
@confirmTitle="Are you sure?"
@confirmMessage="This transformation is not in use by a role and can be deleted."
>
Delete role
Delete transformation
</ConfirmAction>
{{/if}}
{{#if (or model.canUpdate model.canDelete)}}
{{#if model.canUpdate }}
<ToolbarSecretLink
@secret={{model.id}}
@mode="edit"
@data-test-edit-link=true
@replace=true
>
Edit role
Edit transformation
</ToolbarSecretLink>
{{/if}}
</ToolbarActions>
</Toolbar>
{{/if}}

<TransformEditForm @mode={{mode}} @model={{model}} />
{{!-- TODO: keeping here for now to remind us what other component we need to add --}}
{{!-- TODO: not following partial pattern in Transform, this comes from SSH --}}
{{!-- {{#if (or (eq mode 'edit') (eq mode 'create'))}}
{{partial 'partials/role-ssh/form'}}
{{#if (or (eq mode 'edit') (eq mode 'create'))}}
<TransformEditForm @mode={{mode}} @model={{model}} />
{{else}}
{{partial 'partials/role-ssh/show'}}
{{/if}} --}}
<TransformShowTransformation
@model={{model}}
/>
{{/if}}
Loading