Skip to content

Commit

Permalink
ui/config-wizard: AuthenticateScanner component with AWS form
Browse files Browse the repository at this point in the history
  • Loading branch information
ssangervasi committed Jun 27, 2022
1 parent 74ed249 commit 5276f9a
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 0 deletions.
165 changes: 165 additions & 0 deletions clients/admin-ui/src/features/config-wizard/AuthenticateAwsForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
import {
Accordion,
AccordionButton,
AccordionItem,
AccordionPanel,
Button,
Heading,
HStack,
Link,
Stack,
} from "@fidesui/react";
import { Form, Formik } from "formik";
import React from "react";
import * as Yup from "yup";

import { CustomSelect, CustomTextInput } from "../common/form/inputs";
import {
AWS_REGION_OPTIONS,
DOCS_URL_AWS_PERMISSIONS,
DOCS_URL_IAM_POLICY,
} from "./constants";
import { useGenerateMutation } from "./scanner.slice";
import { ScannerGenerateResponse } from "./types";

// TODO: There should just be a theme/variant for blue links.
const DocsLink = (props: React.ComponentProps<typeof Link>) => (
<Link isExternal color="complimentary.500" {...props} />
);

const initialValues = {
aws_access_key_id: "",
aws_secret_access_key: "",
region_name: "",
};

type FormValues = typeof initialValues;

const ValidationSchema = Yup.object().shape({
aws_access_key_id: Yup.string().required().label("Access Key ID"),
aws_secret_access_key: Yup.string().required().label("Secret"),
region_name: Yup.string().required().label("Default Region"),
});

const AuthenticateAwsForm = () => {
// TODO: The organization key needs to come from the shared wizard state.
const organizationKey = "default_organization";
// TODO: These callbacks need to write to some shared wizard state so that that the data passed
// through the wizard (in addition to the step number).
const handleResults: (
results: ScannerGenerateResponse["generate_results"]
) => void = () => {};
const handleError: (error: unknown) => void = () => {};
const handleCancel = () => {};

const [generate, { isLoading }] = useGenerateMutation();

const handleSubmit = async (values: FormValues) => {
const response = await generate({
organization_key: organizationKey,
generate: {
config: values,
target: "aws",
type: "systems",
},
});

if ("error" in response) {
handleError(response.error);
} else {
handleResults(response.data.generate_results);
}
};

return (
<Formik
initialValues={initialValues}
validationSchema={ValidationSchema}
onSubmit={handleSubmit}
>
{({ isValid, dirty }) => (
<Form>
<Stack ml="100px" spacing={10}>
<Heading as="h3" size="lg">
Add a system
</Heading>
<Accordion allowToggle border="transparent">
<AccordionItem>
{({ isExpanded }) => (
<>
<h2>
The scanner can be connected to your cloud infrastructure
provider to automatically scan and create a list of all
systems that may contain personal data.
<AccordionButton
display="inline"
padding="0px"
ml="5px"
width="auto"
color="complimentary.500"
>
{isExpanded ? `(show less)` : `(show more)`}
</AccordionButton>
</h2>
<AccordionPanel padding="0px" mt="20px">
In order to run the scanner, please provide credentials
for authenticating to AWS. Please note, the credentials
must have the{" "}
<DocsLink href={DOCS_URL_AWS_PERMISSIONS}>
minimum permissions listed in the support documentation
here
</DocsLink>
. You can{" "}
<DocsLink href={DOCS_URL_IAM_POLICY}>
copy the sample IAM policy here
</DocsLink>
.
</AccordionPanel>
</>
)}
</AccordionItem>
</Accordion>
<Stack>
<CustomTextInput
name="aws_access_key_id"
label="Access Key ID"
// TODO(#724): These fields should link to the AWS docs, but that requires HTML
// content instead of just a string label. The message would be:
// "You can find more information about creating access keys and secrets on AWS docs here."
tooltip="AWS Access Key ID is the AWS ID associated with the account you want to use for scanning."
/>
<CustomTextInput
name="aws_secret_access_key"
label="Secret"
// "You can find more about creating access keys and secrets on AWS docs here."
tooltip="The secret access key is generated when you create your new access key ID."
/>
<CustomSelect
name="region_name"
label="Default Region"
// "You can learn more about regions in AWS docs here."
tooltip="Specify the default region in which your infrastructure is located. This is necessary for successful scanning."
options={AWS_REGION_OPTIONS}
/>
</Stack>
<HStack>
<Button variant="outline" onClick={handleCancel}>
Cancel
</Button>
<Button
type="submit"
variant="primary"
isDisabled={!dirty || !isValid}
isLoading={isLoading}
>
Save and Continue
</Button>
</HStack>
</Stack>
</Form>
)}
</Formik>
);
};

export default AuthenticateAwsForm;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from "react";

import AuthenticateAwsForm from "./AuthenticateAwsForm";
import { DOCS_URL_AWS_PERMISSIONS, DOCS_URL_IAM_POLICY } from "./constants";
import { Infrastructure } from "./types";

// TODO(#577)
const AuthenticateOktaForm = () => null;

interface Props {
infrastructure?: Infrastructure;
}

const AuthenticateScanner = ({ infrastructure = "aws" }: Props) => (
<>
{infrastructure === "aws" ? <AuthenticateAwsForm /> : null}
{infrastructure === "okta" ? <AuthenticateOktaForm /> : null}
</>
);

export default AuthenticateScanner;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { CloseSolidIcon } from "~/features/common/Icon";
import HorizontalStepper from "../common/HorizontalStepper";
import Stepper from "../common/Stepper";
import AddSystemForm from "./AddSystemForm";
import AuthenticateScanner from "./AuthenticateScanner";
import { HORIZONTAL_STEPS, STEPS } from "./constants";
import DescribeSystemsForm from "./DescribeSystemsForm";
import OrganizationInfoForm from "./OrganizationInfoForm";
Expand Down Expand Up @@ -77,6 +78,9 @@ const ConfigWizardWalkthrough = () => {
{step === 2 ? (
<AddSystemForm handleChangeStep={handleChangeStep} />
) : null}
{step === 3 ? (
<AuthenticateScanner handleChangeStep={handleChangeStep} />
) : null}
{step === 5 ? (
<Stack direction="column">
{reviewStep <= 3 ? (
Expand Down
34 changes: 34 additions & 0 deletions clients/admin-ui/src/features/config-wizard/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,37 @@ export const HORIZONTAL_STEPS = [
];

export const iconButtonSize = 107;

// When more links like these are introduced we should move them to a single file.
export const DOCS_URL_AWS_PERMISSIONS =
"https://ethyca.github.io/fides/guides/generate_resources/#required-permissions";
export const DOCS_URL_IAM_POLICY =
"https://ethyca.github.io/fides/guides/generate_resources/#sample-iam-policy";

// Source: https://docs.aws.amazon.com/general/latest/gr/rande.html
export const AWS_REGION_OPTIONS = [
{ label: "US East (Ohio)", value: "us-east-2" },
{ label: "US East (N. Virginia)", value: "us-east-1" },
{ label: "US West (N. California)", value: "us-west-1" },
{ label: "US West (Oregon)", value: "us-west-2" },
{ label: "Africa (Cape Town)", value: "af-south-1" },
{ label: "Asia Pacific (Hong Kong)", value: "ap-east-1" },
{ label: "Asia Pacific (Jakarta)", value: "ap-southeast-3" },
{ label: "Asia Pacific (Mumbai)", value: "ap-south-1" },
{ label: "Asia Pacific (Osaka)", value: "ap-northeast-3" },
{ label: "Asia Pacific (Seoul)", value: "ap-northeast-2" },
{ label: "Asia Pacific (Singapore)", value: "ap-southeast-1" },
{ label: "Asia Pacific (Sydney)", value: "ap-southeast-2" },
{ label: "Asia Pacific (Tokyo)", value: "ap-northeast-1" },
{ label: "Canada (Central)", value: "ca-central-1" },
{ label: "China (Beijing)", value: "cn-north-1" },
{ label: "China (Ningxia)", value: "cn-northwest-1" },
{ label: "Europe (Frankfurt)", value: "eu-central-1" },
{ label: "Europe (Ireland)", value: "eu-west-1" },
{ label: "Europe (London)", value: "eu-west-2" },
{ label: "Europe (Milan)", value: "eu-south-1" },
{ label: "Europe (Paris)", value: "eu-west-3" },
{ label: "Europe (Stockholm)", value: "eu-north-1" },
{ label: "Middle East (Bahrain)", value: "me-south-1" },
{ label: "South America (São Paulo)", value: "sa-east-1" },
];

0 comments on commit 5276f9a

Please sign in to comment.