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 Generate Intermediate CSR #18807

Merged
merged 6 commits into from
Jan 24, 2023
Merged

Conversation

zofskeez
Copy link
Contributor

@zofskeez zofskeez commented Jan 23, 2023

Adds component for generating intermediate CSR in config and issuer views. Tests to come in follow up PR to keep things moving!

Update: tests were ready by the time this was initially reviewed so I added them!

image
image

@@ -23,6 +24,8 @@ const validations = {
export default class PkiActionModel extends Model {
@service secretMountPath;

@tracked actionType; // used to toggle between different form fields when creating configuration
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Needed to move this to the model for conditional validation since issuerName is not a required field when generating a CSR.

Copy link
Collaborator

@hashishaw hashishaw 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 so far!

ui/app/serializers/pki/action.js Show resolved Hide resolved
const { isValid, state, invalidFormMessage } = model.validate();
if (isValid) {
yield model.save({
adapterOptions: { actionType: 'generate-csr', useIssuer: model.canGenerateIssuerIntermediate },
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the model uses lazyCapabilities I found that if we only call it during the save action it doesn't always get the response back in time to be useful to this method. So I recommend calculating it as you pass in useIssuer and then replace this with that arg. That way the parent can easily override it as well.

Suggested change
adapterOptions: { actionType: 'generate-csr', useIssuer: model.canGenerateIssuerIntermediate },
adapterOptions: { actionType: 'generate-csr', useIssuer: this.args.useIssuer },

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm glad you pointed that out! I was working on tests for the component and noticed that it wasn't picking up the capabilities but it was when I went through the same steps in the app.

I thought we wanted to get away from evaluating form validation on change for UX purposes since the errors show up immediately and can be distracting. I can make the change but since generateIssuerCsrPath is a promise proxy, what if I were to await that before calling save?

const issuerCapabilities = yield model.generateIssuerCsrPath;
yield model.save({
  adapterOptions: { actionType: 'generate-csr', useIssuer: issuerCapabilities.get('canCreate') }
});

With the above change the test is now passing!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting. I don't love having to do all the manual jumps to get it to Just Work, but it's good to know that yielding the path manually does work! One other thing to note is that if we go with your proposed code, that does differ from the patterns we have already established in the other PKI forms. If we go with what you propose I would ask that we remove useIssuer from the component args and maybe document this usage in the lazyCapabilities definition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I enabled auto merge since I stepped out to walk the dog. I reverted those changes and my test is failing again. I updated the pki-generate-csr to pass in adapterOptions instead and the capabilities are resolving after the save request. The same is true if I pass just the property as useIssuer as suggested. Even though canGenerateIssuerIntermediate is passed in as an arg the computed is not triggered until the property is accessed. I suspect a similar test would fail in the generate-root component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The useIssuer arg in the interface should have been removed since it was from an early iteration of the component so I will get that updated. I can add a test for saving the config from the generate-root component and see if it fails and then align the capabilities access between the 2 components. I can also add some comments somewhere to note that we should be waiting for the promises if not accessed from a template.

@zofskeez zofskeez enabled auto-merge (squash) January 24, 2023 18:13
Copy link
Collaborator

@hashishaw hashishaw left a comment

Choose a reason for hiding this comment

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

Thanks for writing the tests!

@task
@waitFor
*save(event: Event) {
*save(event: Event): Generator<Promise<boolean | PkiActionModel>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Interesting, is the task "returning" whatever is yielded, that's why you need both the boolean and the PkiActionModel in the promise value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya it's the IterableIterator returned from yield which in this case is 2 different things. I had to look it up 😁.

@zofskeez zofskeez merged commit b57206c into main Jan 24, 2023
jayant07-yb pushed a commit to jayant07-yb/hashicorp-vault-integrations that referenced this pull request Mar 15, 2023
* adds pki generate csr component

* adds keyParamsByType helper to pki-generate-toggle-groups component

* removes unused router service from pki-generate-csr component

* updates common pki generate form fields

* addresses feedback and adds tests
@zofskeez zofskeez deleted the ui/VAULT-6515/pki-generate-intermediate branch May 6, 2024 15:03
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

2 participants