-
Notifications
You must be signed in to change notification settings - Fork 365
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
feat: [M3-7029] - Add AGLB Certificate Create Drawer #9616
Merged
bnussman-akamai
merged 9 commits into
linode:develop
from
bnussman-akamai:M3-7029-add-aglb-cert-create-drawer
Sep 8, 2023
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c4308f8
add component and test
bnussman f786306
do goofy radio styling
bnussman 9a49213
improve validation
bnussman 6c0fa5c
Added changeset: Add AGLB Certificate Create Drawer
bnussman 0380e5c
fix test
bnussman 1fe0ad7
Merge branch 'develop' into M3-7029-add-aglb-cert-create-drawer
bnussman 72a06a2
add `trimmed` prop to SSH Key TextFields
bnussman a32abd0
Merge branch 'develop' into M3-7029-add-aglb-cert-create-drawer
bnussman 1c7764f
Add AGLB cert upload integration tests and related utils
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-9616-upcoming-features-1693507025003.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Upcoming Features | ||
--- | ||
|
||
Add AGLB Certificate Create Drawer ([#9616](https://github.com/linode/manager/pull/9616)) |
31 changes: 31 additions & 0 deletions
31
...c/features/LoadBalancers/LoadBalancerDetail/Certificates/CreateCertificateDrawer.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { act, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { CreateCertificateDrawer } from './CreateCertificateDrawer'; | ||
|
||
describe('CreateCertificateDrawer', () => { | ||
it('should be submittable when form is filled out correctly', async () => { | ||
const onClose = jest.fn(); | ||
|
||
const { getByLabelText, getByTestId } = renderWithTheme( | ||
<CreateCertificateDrawer loadbalancerId={0} onClose={onClose} open /> | ||
); | ||
|
||
const labelInput = getByLabelText('Label'); | ||
const certInput = getByLabelText('TLS Certificate'); | ||
const keyInput = getByLabelText('Private Key'); | ||
|
||
act(() => { | ||
userEvent.type(labelInput, 'my-cert-0'); | ||
userEvent.type(certInput, 'massive cert'); | ||
userEvent.type(keyInput, 'massive key'); | ||
|
||
userEvent.click(getByTestId('submit')); | ||
}); | ||
|
||
await waitFor(() => expect(onClose).toBeCalled()); | ||
}); | ||
}); |
134 changes: 134 additions & 0 deletions
134
...er/src/features/LoadBalancers/LoadBalancerDetail/Certificates/CreateCertificateDrawer.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import { CreateCertificatePayload } from '@linode/api-v4'; | ||
import { Stack } from '@mui/material'; | ||
import { useFormik } from 'formik'; | ||
import React from 'react'; | ||
|
||
import { ActionsPanel } from 'src/components/ActionsPanel/ActionsPanel'; | ||
import { Drawer } from 'src/components/Drawer'; | ||
import { FormControlLabel } from 'src/components/FormControlLabel'; | ||
import { Notice } from 'src/components/Notice/Notice'; | ||
import { Radio } from 'src/components/Radio/Radio'; | ||
import { RadioGroup } from 'src/components/RadioGroup'; | ||
import { TextField } from 'src/components/TextField'; | ||
import { Typography } from 'src/components/Typography'; | ||
import { useLoadBalancerCertificateCreateMutation } from 'src/queries/aglb/certificates'; | ||
import { getErrorMap } from 'src/utilities/errorUtils'; | ||
|
||
interface Props { | ||
loadbalancerId: number; | ||
onClose: () => void; | ||
open: boolean; | ||
} | ||
|
||
export const CreateCertificateDrawer = (props: Props) => { | ||
const { loadbalancerId, onClose: _onClose, open } = props; | ||
|
||
const onClose = () => { | ||
formik.resetForm(); | ||
_onClose(); | ||
reset(); | ||
}; | ||
|
||
const { | ||
error, | ||
mutateAsync: createCertificate, | ||
reset, | ||
} = useLoadBalancerCertificateCreateMutation(loadbalancerId); | ||
|
||
const formik = useFormik<CreateCertificatePayload>({ | ||
initialValues: { | ||
certificate: '', | ||
key: '', | ||
label: '', | ||
type: 'downstream', | ||
}, | ||
async onSubmit(values) { | ||
await createCertificate(values); | ||
onClose(); | ||
}, | ||
}); | ||
|
||
const errorMap = getErrorMap(['label', 'key', 'certificate'], error); | ||
|
||
return ( | ||
<Drawer onClose={onClose} open={open} title="Upload Certificate"> | ||
<form onSubmit={formik.handleSubmit}> | ||
{errorMap.none && <Notice text={errorMap.none} variant="error" />} | ||
<Typography mb={2}> | ||
Upload the certificates for Load Balancer authentication. | ||
</Typography> | ||
<RadioGroup | ||
name="type" | ||
onChange={formik.handleChange} | ||
value={formik.values.type} | ||
> | ||
<FormControlLabel | ||
label={ | ||
<Stack mt={1.5} spacing={1}> | ||
<Typography>TLS Certificate</Typography> | ||
<Typography> | ||
Used by your load balancer to terminate the connection and | ||
decrypt request from client prior to sending the request to | ||
the endpoints in your Service Targets. You can specify a Host | ||
Header. Also referred to as SSL Certificate. | ||
</Typography> | ||
</Stack> | ||
} | ||
control={<Radio />} | ||
sx={{ alignItems: 'flex-start' }} | ||
value="downstream" | ||
/> | ||
<FormControlLabel | ||
label={ | ||
<Stack mt={1.5} spacing={1}> | ||
<Typography>Service Target Certificate</Typography> | ||
<Typography> | ||
Used by the load balancer to accept responses from your | ||
endpoints in your Service Target. This is the certificate | ||
installed on your Endpoints. | ||
</Typography> | ||
</Stack> | ||
} | ||
control={<Radio />} | ||
sx={{ alignItems: 'flex-start', mt: 2 }} | ||
value="ca" | ||
/> | ||
</RadioGroup> | ||
<TextField | ||
errorText={errorMap.label} | ||
label="Label" | ||
name="label" | ||
onChange={formik.handleChange} | ||
value={formik.values.label} | ||
/> | ||
<TextField | ||
errorText={errorMap.certificate} | ||
label="TLS Certificate" | ||
labelTooltipText="TODO" | ||
multiline | ||
name="certificate" | ||
onChange={formik.handleChange} | ||
trimmed | ||
value={formik.values.certificate} | ||
/> | ||
<TextField | ||
errorText={errorMap.key} | ||
label="Private Key" | ||
labelTooltipText="TODO" | ||
multiline | ||
name="key" | ||
onChange={formik.handleChange} | ||
trimmed | ||
value={formik.values.key} | ||
bnussman-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
<ActionsPanel | ||
primaryButtonProps={{ | ||
'data-testid': 'submit', | ||
label: 'Upload Certificate', | ||
type: 'submit', | ||
}} | ||
/> | ||
</form> | ||
</Drawer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { object, string } from 'yup'; | ||
|
||
export const CreateCertificateSchema = object({ | ||
certificate: string().required('Certificate is required.'), | ||
key: string().when('type', { | ||
is: 'downstream', | ||
then: string().required('Private Key is required.'), | ||
}), | ||
label: string().required('Label is required.'), | ||
type: string().oneOf(['downstream', 'ca']).required('Type is required.'), | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just making sure we have this tracked to complete in the future?