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

Add TLS Cert input #1784

Merged
merged 12 commits into from
Oct 13, 2023
Merged

Add TLS Cert input #1784

merged 12 commits into from
Oct 13, 2023

Conversation

benjaminleonard
Copy link
Contributor

@benjaminleonard benjaminleonard commented Oct 10, 2023

Fixes #1736

Uses the mini table and modal create pattern to add TLS certificates. I've omitted service as there's only one option currently external_api.

As specced in the API, key and cert are plain text — added readBlobAsText to read that from the File object.

tls-cert

Running into a couple of nits around the required validation. If you try to click cancel after opening the modal, the first click will be interrupted by the error on the "Name" field. Similarly, when you click on the file upload you immediately get the required error message. Should probably handle in a separate PR.

@vercel
Copy link

vercel bot commented Oct 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
console ✅ Ready (Inspect) Visit Preview Oct 13, 2023 8:20pm

tabIndex={0}
aria-rowindex={index + 1}
aria-label={`Name: ${item.name}, Description: ${item.description}`}
key={item.name}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently we aren't checking for uniqueness around name. Do we want to do so? If not, we should use something like ${item.name}-${index} to ensure the keys do not clash.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, we probably should enforce uniqueness. I guess we’d check that on submit in the modal? Refuse to submit if there’s a duplicate.

@benjaminleonard
Copy link
Contributor Author

Validated working against dogfood earlier today.

@david-crespo david-crespo self-requested a review October 11, 2023 00:25
return (
<TextField
validate={(name) =>
allNames.includes(name) ? 'Certificate with this name already exists' : true
Copy link
Contributor Author

@benjaminleonard benjaminleonard Oct 12, 2023

Choose a reason for hiding this comment

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

I did attempt to get this going in the onSubmit of AddCertModal but for whatever reason nothing I put in there was firing. Guessing react-hook-form is intercepting the default onSubmit.

But the benefit of this approach is we don't need to mess around with setError or anything like that. I did consider memoizing allNames but figured it might be overboard for the number of certs we'll have here.

Also the key is guaranteed to be unique because if a name is not, it will never be added.

Comment on lines 65 to 68
/* Validating this onBlur causes the required
error message to appear on click. Instead we can
validate on form submit by overriding onBlur */
onBlur={() => {}}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any thoughts on this @david-crespo? We might want to validate onChange if we have anything like validating filenames or sizes – but it might give you an error when you clear the file, which we may or may not want. Presently we are only really validating required or not.

This fixes the issue where the error appears as soon as you click on the file input.

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed in chat, I think validate on blur only if dirty (#1289) would be our ideal behavior, though I don't think RHF supports it yet. I will look into patching or PRing it so we can test that out. On the other hand, I don't think that would solve #1786 because you could still trigger by typing something invalid in the name field and then trying to change the radio input.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah – though this specifically is targeting the error appearing when you click on the file input. It seems like the onBlur is triggered whenever the file input opens.

@david-crespo
Copy link
Collaborator

Merging main with #1787 fixed the issues with the file input error on blur, plus the one (same as #1786) where if you scroll down and click the add cert button without typing in the name field, you'd get a validation error on name due to the blur that prevents your click on the button from going through (probably because it gets scrolled out of the way, ugh).

I noticed name was not being validated as a required field, fixing that.

@@ -53,7 +53,6 @@ export interface TextFieldProps<
description?: string
placeholder?: string
units?: string
// TODO: think about this doozy of a type
Copy link
Collaborator

Choose a reason for hiding this comment

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

one year of thinking is enough

} else if (!/^[a-z0-9-]+$/.test(value)) {
return 'Can only contain lower-case letters, numbers, and dashes'
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this wasn't used. apparently a leftover from when we switched from Formik to RHF

Copy link
Collaborator

@david-crespo david-crespo left a comment

Choose a reason for hiding this comment

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

This looks good to me. I want to give the code and the E2Es another once-over later and then merge.

Something we should follow up on: displaying the certs on the silo detail page where we currently list IdPs. I'm a little confused about the API for this, will need to look into it. I don't see a way to list these certs.

@david-crespo david-crespo enabled auto-merge (squash) October 13, 2023 20:21
@david-crespo david-crespo merged commit d07ca14 into main Oct 13, 2023
8 checks passed
@david-crespo david-crespo deleted the add-tls-cert-input branch October 13, 2023 20:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add TLS certs to silo create form
2 participants