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

PKI role non-default options #17393

Merged
merged 46 commits into from
Oct 12, 2022
Merged

PKI role non-default options #17393

merged 46 commits into from
Oct 12, 2022

Conversation

Monkeychip
Copy link
Contributor

@Monkeychip Monkeychip commented Oct 3, 2022

2 of 3 PRs needed to finish the PKI Roles Create View

This PR handles the three Toggle Options: Domain handling, Key parameters, and Key usage.

Some notes:

  1. Domain handling needed another kind of formField option that only showed a more-info type callout.
    image

  2. Key Parameters two special cases:
    a. it needed a subText formField with no input and no label.
    image
    b. the keyBits param's possibleValues are conditional depending on what keyType the user selected.
    https://user-images.githubusercontent.com/6618863/194140779-529f7d70-08e1-4182-90bf-6090d6189b9d.mov

  3. Key Usage needed to use CSS Grid to match the designs AND all those checkboxes are just list items, not actually API params, so I append them to the ext_key_usage and key_usage parameters in a component.

image

You can see why I stopped at this PR instead of finishing the view. This custom functionality is outside our normal patterns so a lot of custom work and modifications to formFields, etc had to be made, but in the end it makes PKI a LOT easier for users to navigate.

  1. At this point designs and the work do not exactly match. There are a lot of comments on the designs, but even then, if something doesn't exactly match, but makes sense, then it's probably been a confirmed change in a conversation between backend and design.

TODO:

  • in future PR remove the helpText on string-list components. There is some refactoring that should happen in that component, so moving outside the scope of this PR.

>
<RadioSelectTtlOrString @model={{@model}} @attr={{attr}} />
</FormFieldGroupsLoop>
{{#each @model.fieldGroups as |fieldGroup|}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ended up not being able to use FormFieldGroupsLoop for two main reasons:

  1. because there is a lot of custom work required to make the CSS grid for Key Usage work, and it didn't make sense to apply that logic to a widely used component where PKI might be a unique situation where CSS grid is needed.
  2. I needed to pass in a conditional attr when dealing with key_bits, this complicated a whole mess of things and again is a one off situation specific to pki.

@Monkeychip Monkeychip marked this pull request as ready for review October 5, 2022 19:04
Copy link
Contributor

@zofskeez zofskeez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow lots of work here good job. I left some comments but mainly want to discuss the serializer work further.

ui/app/adapters/pki/pki-role-engine.js Show resolved Hide resolved
ui/app/models/pki/pki-role-engine.js Outdated Show resolved Hide resolved
ui/app/models/pki/pki-role-engine.js Outdated Show resolved Hide resolved
{{#each fields as |attr|}}
<FormField
data-test-field={{true}}
@attr={{if (eq attr.name "keyBits") @model.keyBitsConditional attr}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it would be tidier to do this in the fieldGroups getter on the model instead? After doing fieldToAttrs you could replace the keyBits attr with the result from the keyBitsConditional getter.

Copy link
Contributor Author

@Monkeychip Monkeychip Oct 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get that to work. And it doesn't feel cleaner in the model because I have to really dig into the _fieldToAttrsGroups.

// inside the model on row 256, just before I return this_fieldToAttrsGroups
    this._fieldToAttrsGroups[2]['Key parameters'][2] = this.keyBitsConditional;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts?

ui/app/models/pki/pki-role-engine.js Outdated Show resolved Hide resolved
ui/app/serializers/pki/pki-role-engine.js Outdated Show resolved Hide resolved
ui/app/styles/core/helpers.scss Outdated Show resolved Hide resolved
Comment on lines +1 to +17
import Component from '@glimmer/component';

/**
* @module FormFieldGroupsLoop
* FormFieldGroupsLoop components loop through the "groups" set on a model and display them either as default or behind toggle components.
*
* @example
* ```js
<FormFieldGroupsLoop @model={{this.model}} @mode={{if @model.isNew "create" "update"}}/>
* ```
* @param {class} model - The routes model class.
* @param {string} mode - "create" or "update" used to hide the name form field. TODO: not ideal, would prefer to disable it to follow new design patterns.
* @param {function} [modelValidations] - Passed through to formField.
* @param {boolean} [showHelpText] - Passed through to formField.
*/
/* eslint ember/no-empty-glimmer-component-classes: 'warn' */
export default class FormFieldGroupsLoop extends Component {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

ui/lib/core/addon/components/form-field.hbs Outdated Show resolved Hide resolved
Copy link
Contributor

@hellobontempo hellobontempo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments! Kind of have wonky end of day brain, but I'll revisit tomorrow!

ui/app/models/pki/pki-role-engine.js Outdated Show resolved Hide resolved
ui/app/models/pki/pki-role-engine.js Outdated Show resolved Hide resolved
ui/lib/core/addon/components/form-field.hbs Outdated Show resolved Hide resolved
ui/lib/core/addon/components/string-list.hbs Outdated Show resolved Hide resolved
ui/lib/pki/addon/components/pki-key-usage.hbs Outdated Show resolved Hide resolved
@Monkeychip Monkeychip enabled auto-merge (squash) October 7, 2022 19:16
Copy link
Contributor

@hellobontempo hellobontempo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this so far! It's so nice seeing the PKI work come together 😄

/>
{{#if (get @model prop)}}
<div class="box is-tall is-marginless">
<FormFieldLabel
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

ui/lib/pki/addon/components/pki-key-usage.hbs Outdated Show resolved Hide resolved
ui/lib/pki/addon/components/pki-key-usage.hbs Outdated Show resolved Hide resolved
* @param {string} group - The name of the group created in the model. In this case, it's the "Key usage" group.
*/

const KEY_USAGE_FIELDS = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I think this is much clearer with the label attr removed 😄

CrlSign: { label: 'CRL Sign' },
KeyAgreement: {
label: 'Key Agreement',
value: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think setting these values here means that they will always be true. So when editing a role, these will always change back to true regardless of what the @model value is..

Starting to think that writing component tests earlier than later for these forms will save a bunch of time/energy speculating the various what ifs for this form 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When they change, the model updates the keyUsage list. But yep, working on the tests in the next PR.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So by default are all the true values checked? And then what happens when editing and the model has false values instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default the true values are checked. On any click for any of the checkboxes it updates the keyUsage list. So if it has a false value it's removed from the list. In the screenshot only Key Encipherment is checked, so it's the only one in the list.

CodeSigning: { label: 'Code Signing' },
};

export default class PkiKeyUsage extends Component {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a test for this component would be 😍

ui/app/models/pki/pki-role-engine.js Show resolved Hide resolved
ui/lib/core/addon/components/form-field.hbs Outdated Show resolved Hide resolved
Copy link
Contributor

@hellobontempo hellobontempo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small cleanup comments. Really great work on this! All of that custom form work is 🤯

ed25519: [0],
any: [0],
};
const attrs = expandAttributeMeta(this, ['keyBits']);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

ui/app/models/pki/pki-role-engine.js Show resolved Hide resolved
ui/app/styles/core/box.scss Outdated Show resolved Hide resolved
@@ -9,15 +9,15 @@
)
)
}}
{{#unless (eq @attr.type "object")}}
{{#if (not (or (eq @attr.type "object") (eq @attr.options.editType "moreInfo")))}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can revert this back and remove moreInfo

@@ -21,7 +21,7 @@ import { dasherize } from 'vault/helpers/dasherize';
* label: "Foo", // custom label to be shown, otherwise attr.name will be displayed
* defaultValue: "", // default value to display if model value is not present
* fieldValue: "bar", // used for value lookup on model over attr.name
* editType: "ttl", type of field to use. List of editTypes:boolean, file, json, kv, optionalText, mountAccessor, password, radio, regex, searchSelect, stringArray,textarea, ttl, yield.
* editType: "ttl", type of field to use. List of editTypes:boolean, file, json, kv, optionalText, mountAccessor, moreInfo, password, radio, regex, searchSelect, stringArray, textarea, ttl, yield.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moreInfo can be removed here, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ug, I know I did a whole search for moreInfo, but I've been working off this branch for testing and I think I messed up a push 🤦🏻‍♀️

CrlSign: { label: 'CRL Sign' },
KeyAgreement: {
label: 'Key Agreement',
value: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So by default are all the true values checked? And then what happens when editing and the model has false values instead?

const value = event.target['checked'];
type === 'keyUsage'
? this.args.model.set('keyUsage', this._amendList(checkboxName, value, type))
: this.args.model.set('extKeyUsage', this._amendList(checkboxName, value, type));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if type is the attr name on the model could the conditional be removed and this change to:

Suggested change
: this.args.model.set('extKeyUsage', this._amendList(checkboxName, value, type));
this.args.model.set(type, this._amendList(checkboxName, value, type));

or, since this component is glimmerized, do we need to use `.set` here?
Suggested change
: this.args.model.set('extKeyUsage', this._amendList(checkboxName, value, type));
this.args.model[type] = this._amendList(checkboxName, value, type)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, yep. This works: this.args.model.set(type, this._amendList(checkboxName, value, type));

/>
{{#if (get @model prop)}}
<div class="box is-marginless">
{{#let (get @model.fieldGroupsInfo group) as |groupInfo|}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@Monkeychip Monkeychip merged commit 8188328 into main Oct 12, 2022
@Monkeychip Monkeychip deleted the ui/VAULT-6521/pki-role-create-2 branch October 12, 2022 18:56
jayant07-yb pushed a commit to jayant07-yb/hashicorp-vault-integrations that referenced this pull request Mar 15, 2023
* dynamically render the secretlistheader in the parent route.

* start getting form setup even without openAPi working

* add in create and cancel

* making openAPI work

* add default openAPI params

* wip for new component with two radio options a ttl and input

* handle createRecord on pki-roles-form

* remove tooltips and cleanup

* move formfieldgroupsloop back to non addon

* cleanup

* move secretListHeader

* broadcast from radioSelectTtlOrString to parent

* cleanup

* hide tooltips

* pass through sub text to stringArray

* Add conditional for keybits and keyType

* set defaults for keyBits ... 🤮

* fix some small issues

* more info form field typ

* show only label and subText

* wip context switch 🤮

* fix dontShowLabel

* getting css grid setup

* more on flex groups

* adding the second chunk to key usage

* serialize the post for key_usage

* finish for ext_key_usage

* clean up

* fix snack_case issue

* commit for working state, next trying to remove form-field-group-loops because it's causing issues.

* remove usage of formfieldgroupsloop because of issues with css grid and conditionals

* clean up

* remove string-list helpText changes for tooltip removal because that should be it's own pr.

* clarification from design and backend.

* small cleanup

* pull key_usage and ext_key_usage out of the model and into a component

* clean up

* clean up

* restructure css grid:

* clean up

* broke some things

* fix error when roles list returned 404

* claires feedback

* cleanup

* clean up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants