-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New routes and full form, successful creation of ACLs Cleanup, and testing acl verification method Simplify some functions, fix form
- Loading branch information
Showing
8 changed files
with
501 additions
and
1 deletion.
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
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,134 @@ | ||
/*! | ||
* Copyright © 2023 United States Government as represented by the | ||
* Administrator of the National Aeronautics and Space Administration. | ||
* All Rights Reserved. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
import type { LoaderFunctionArgs } from '@remix-run/node' | ||
import { useFetcher, useLoaderData } from '@remix-run/react' | ||
import type { ModalRef } from '@trussworks/react-uswds' | ||
import { | ||
Button, | ||
Grid, | ||
Icon, | ||
Modal, | ||
ModalFooter, | ||
ModalHeading, | ||
ModalToggleButton, | ||
} from '@trussworks/react-uswds' | ||
import { useRef } from 'react' | ||
|
||
import { getUser } from './_auth/user.server' | ||
import HeadingWithAddButton from '~/components/HeadingWithAddButton' | ||
import SegmentedCards from '~/components/SegmentedCards' | ||
import { getGroups } from '~/lib/cognito.server' | ||
import type { KafkaACL } from '~/lib/kafka.server' | ||
import { getKafkaACLs } from '~/lib/kafka.server' | ||
|
||
export async function loader({ request }: LoaderFunctionArgs) { | ||
const user = await getUser(request) | ||
if (!user) throw new Response(null, { status: 403 }) | ||
const aclData = await getKafkaACLs(user) | ||
const userGroups = (await getGroups()) | ||
.filter((group) => group.GroupName?.startsWith('gcn.nasa.gov/')) | ||
.map((group) => group.GroupName) | ||
|
||
return { aclData, userGroups } | ||
} | ||
|
||
export default function Index() { | ||
const { aclData } = useLoaderData<typeof loader>() | ||
|
||
return ( | ||
<> | ||
<HeadingWithAddButton headingLevel={1}>Kafka Admin</HeadingWithAddButton> | ||
<h2>Kafka ACLs</h2> | ||
<SegmentedCards> | ||
{aclData.map((x, index) => ( | ||
<KafkaAclCard key={index} acl={x} /> | ||
))} | ||
</SegmentedCards> | ||
</> | ||
) | ||
} | ||
|
||
function KafkaAclCard({ acl }: { acl: KafkaACL }) { | ||
const ref = useRef<ModalRef>(null) | ||
const fetcher = useFetcher() | ||
const disabled = fetcher.state !== 'idle' | ||
|
||
return ( | ||
<> | ||
<Grid row style={disabled ? { opacity: '50%' } : undefined}> | ||
<div className="tablet:grid-col flex-fill"> | ||
<div> | ||
<small> | ||
<strong>Topic:</strong> {acl.topicName} | ||
</small> | ||
</div> | ||
<div> | ||
<small> | ||
<strong>Permission Type:</strong> {acl.permissionType} | ||
</small> | ||
</div> | ||
<div> | ||
<small> | ||
<strong>Group:</strong> {acl.group} | ||
</small> | ||
</div> | ||
</div> | ||
<div className="tablet:grid-col flex-auto margin-y-auto"> | ||
<ModalToggleButton | ||
opener | ||
disabled={disabled} | ||
modalRef={ref} | ||
type="button" | ||
className="usa-button--secondary" | ||
> | ||
<Icon.Delete | ||
role="presentation" | ||
className="bottom-aligned margin-right-05" | ||
/> | ||
Delete | ||
</ModalToggleButton> | ||
</div> | ||
</Grid> | ||
<Modal | ||
id="modal-delete" | ||
ref={ref} | ||
aria-labelledby="modal-delete-heading" | ||
aria-describedby="modal-delete-description" | ||
renderToPortal={false} | ||
> | ||
<fetcher.Form method="POST" action="/admin/kafka"> | ||
<input type="hidden" name="topicName" value={acl.topicName} /> | ||
<input type="hidden" name="group" value={acl.group} /> | ||
<input | ||
type="hidden" | ||
name="permissionType" | ||
value={acl.permissionType} | ||
/> | ||
<ModalHeading id="modal-delete-heading"> | ||
Delete Kafka ACL | ||
</ModalHeading> | ||
<p id="modal-delete-description"> | ||
This will delete the DynamoDB entry and{' '} | ||
{acl.permissionType == 'consumer' | ||
? '"read" and "describe"' | ||
: '"create", "write", and "describe"'}{' '} | ||
Kafka ACLs. Do you wish to continue? | ||
</p> | ||
<ModalFooter> | ||
<ModalToggleButton modalRef={ref} closer outline> | ||
Cancel | ||
</ModalToggleButton> | ||
<Button data-close-modal type="submit" name="intent" value="delete"> | ||
Delete | ||
</Button> | ||
</ModalFooter> | ||
</fetcher.Form> | ||
</Modal> | ||
</> | ||
) | ||
} |
Oops, something went wrong.