mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 16:27:46 +00:00
feat: updated ui for aws sm assume role integration
This commit is contained in:
@@ -802,6 +802,7 @@ export const useSaveIntegrationAccessToken = () => {
|
|||||||
refreshToken,
|
refreshToken,
|
||||||
accessId,
|
accessId,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
awsAssumeIamRoleArn,
|
||||||
url,
|
url,
|
||||||
namespace
|
namespace
|
||||||
}: {
|
}: {
|
||||||
@@ -810,6 +811,7 @@ export const useSaveIntegrationAccessToken = () => {
|
|||||||
refreshToken?: string;
|
refreshToken?: string;
|
||||||
accessId?: string;
|
accessId?: string;
|
||||||
accessToken?: string;
|
accessToken?: string;
|
||||||
|
awsAssumeIamRoleArn?: string;
|
||||||
url?: string;
|
url?: string;
|
||||||
namespace?: string;
|
namespace?: string;
|
||||||
}) => {
|
}) => {
|
||||||
@@ -821,6 +823,7 @@ export const useSaveIntegrationAccessToken = () => {
|
|||||||
refreshToken,
|
refreshToken,
|
||||||
accessId,
|
accessId,
|
||||||
accessToken,
|
accessToken,
|
||||||
|
awsAssumeIamRoleArn,
|
||||||
url,
|
url,
|
||||||
namespace
|
namespace
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,54 +1,70 @@
|
|||||||
import { useState } from "react";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import Head from "next/head";
|
import Head from "next/head";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { useRouter } from "next/router";
|
import { useRouter } from "next/router";
|
||||||
import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons";
|
import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
Card,
|
||||||
|
CardBody,
|
||||||
|
CardTitle,
|
||||||
|
FormControl,
|
||||||
|
Input,
|
||||||
|
Select,
|
||||||
|
SelectItem
|
||||||
|
} from "@app/components/v2";
|
||||||
import { useSaveIntegrationAccessToken } from "@app/hooks/api";
|
import { useSaveIntegrationAccessToken } from "@app/hooks/api";
|
||||||
|
|
||||||
import { Button, Card, CardTitle, FormControl, Input } from "../../../components/v2";
|
enum AwsAuthType {
|
||||||
|
AccessKey = "access-key",
|
||||||
|
AssumeRole = "assume-role"
|
||||||
|
}
|
||||||
|
|
||||||
|
const formSchema = z.discriminatedUnion("type", [
|
||||||
|
z.object({
|
||||||
|
type: z.literal(AwsAuthType.AccessKey),
|
||||||
|
accessKey: z.string().min(1),
|
||||||
|
accessSecretKey: z.string().min(1)
|
||||||
|
}),
|
||||||
|
z.object({
|
||||||
|
type: z.literal(AwsAuthType.AssumeRole),
|
||||||
|
iamRoleArn: z.string().min(1)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
type TForm = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
export default function AWSSecretManagerCreateIntegrationPage() {
|
export default function AWSSecretManagerCreateIntegrationPage() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { mutateAsync } = useSaveIntegrationAccessToken();
|
const { mutateAsync } = useSaveIntegrationAccessToken();
|
||||||
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const { control, handleSubmit, formState, watch } = useForm<TForm>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: {
|
||||||
|
type: AwsAuthType.AccessKey
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const formAwsAuthTypeField = watch("type");
|
||||||
|
|
||||||
const [accessKey, setAccessKey] = useState("");
|
const handleFormSubmit = async (data: TForm) => {
|
||||||
const [accessKeyErrorText, setAccessKeyErrorText] = useState("");
|
|
||||||
const [accessSecretKey, setAccessSecretKey] = useState("");
|
|
||||||
const [accessSecretKeyErrorText, setAccessSecretKeyErrorText] = useState("");
|
|
||||||
|
|
||||||
const handleButtonClick = async () => {
|
|
||||||
try {
|
try {
|
||||||
setAccessKeyErrorText("");
|
|
||||||
setAccessSecretKeyErrorText("");
|
|
||||||
|
|
||||||
if (accessKey.length === 0) {
|
|
||||||
setAccessKeyErrorText("Access key cannot be blank");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (accessSecretKey.length === 0) {
|
|
||||||
setAccessSecretKeyErrorText("Secret access key cannot be blank");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
setIsLoading(true);
|
|
||||||
|
|
||||||
const integrationAuth = await mutateAsync({
|
const integrationAuth = await mutateAsync({
|
||||||
workspaceId: localStorage.getItem("projectData.id"),
|
workspaceId: localStorage.getItem("projectData.id"),
|
||||||
integration: "aws-secret-manager",
|
integration: "aws-secret-manager",
|
||||||
accessId: accessKey,
|
...(data.type === AwsAuthType.AssumeRole
|
||||||
accessToken: accessSecretKey
|
? {
|
||||||
|
awsAssumeIamRoleArn: data.iamRoleArn
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
accessId: data.accessKey,
|
||||||
|
accessToken: data.accessSecretKey
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
setAccessKey("");
|
|
||||||
setAccessSecretKey("");
|
|
||||||
setIsLoading(false);
|
|
||||||
|
|
||||||
router.push(
|
router.push(
|
||||||
`/integrations/aws-secret-manager/create?integrationAuthId=${integrationAuth.id}`
|
`/integrations/aws-secret-manager/create?integrationAuthId=${integrationAuth.id}`
|
||||||
);
|
);
|
||||||
@@ -69,7 +85,7 @@ export default function AWSSecretManagerCreateIntegrationPage() {
|
|||||||
subTitle="After adding the details below, you will be prompted to set up an integration for a particular Infisical project and environment."
|
subTitle="After adding the details below, you will be prompted to set up an integration for a particular Infisical project and environment."
|
||||||
>
|
>
|
||||||
<div className="flex flex-row items-center">
|
<div className="flex flex-row items-center">
|
||||||
<div className="inline flex items-center">
|
<div className="flex items-center">
|
||||||
<Image
|
<Image
|
||||||
src="/images/integrations/Amazon Web Services.png"
|
src="/images/integrations/Amazon Web Services.png"
|
||||||
height={35}
|
height={35}
|
||||||
@@ -92,37 +108,90 @@ export default function AWSSecretManagerCreateIntegrationPage() {
|
|||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
<FormControl
|
<CardBody>
|
||||||
label="Access Key ID"
|
<form onSubmit={handleSubmit(handleFormSubmit)}>
|
||||||
errorText={accessKeyErrorText}
|
<Controller
|
||||||
isError={accessKeyErrorText !== "" ?? false}
|
control={control}
|
||||||
className="px-6"
|
name="type"
|
||||||
>
|
defaultValue={AwsAuthType.AccessKey}
|
||||||
<Input placeholder="" value={accessKey} onChange={(e) => setAccessKey(e.target.value)} />
|
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
||||||
</FormControl>
|
<FormControl
|
||||||
<FormControl
|
label="Authentication Mode"
|
||||||
label="Secret Access Key"
|
errorText={error?.message}
|
||||||
errorText={accessSecretKeyErrorText}
|
isError={Boolean(error)}
|
||||||
isError={accessSecretKeyErrorText !== "" ?? false}
|
>
|
||||||
className="px-6"
|
<Select
|
||||||
>
|
defaultValue={field.value}
|
||||||
<Input
|
{...field}
|
||||||
placeholder=""
|
onValueChange={(e) => onChange(e)}
|
||||||
type="password"
|
className="w-full"
|
||||||
autoComplete="new-password"
|
>
|
||||||
value={accessSecretKey}
|
<SelectItem value={AwsAuthType.AccessKey}>Access Key</SelectItem>
|
||||||
onChange={(e) => setAccessSecretKey(e.target.value)}
|
<SelectItem value={AwsAuthType.AssumeRole}>AWS Assume Role</SelectItem>
|
||||||
/>
|
</Select>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<Button
|
)}
|
||||||
onClick={handleButtonClick}
|
/>
|
||||||
colorSchema="primary"
|
{formAwsAuthTypeField === AwsAuthType.AccessKey ? (
|
||||||
variant="outline_bg"
|
<>
|
||||||
className="mb-6 mt-2 ml-auto mr-6 w-min"
|
<Controller
|
||||||
isLoading={isLoading}
|
control={control}
|
||||||
>
|
name="accessKey"
|
||||||
Connect to AWS Secrets Manager
|
render={({ field, fieldState: { error } }) => (
|
||||||
</Button>
|
<FormControl
|
||||||
|
label="Access Key ID"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<Input placeholder="" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="accessSecretKey"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="Secret Access Key"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<Input
|
||||||
|
type="password"
|
||||||
|
autoComplete="new-password"
|
||||||
|
placeholder=""
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<Controller
|
||||||
|
control={control}
|
||||||
|
name="iamRoleArn"
|
||||||
|
render={({ field, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
label="IAM Role ARN For Role Assumption"
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error)}
|
||||||
|
>
|
||||||
|
<Input placeholder="" {...field} />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
<Button
|
||||||
|
type="submit"
|
||||||
|
colorSchema="primary"
|
||||||
|
variant="outline_bg"
|
||||||
|
className="mb-6 mt-2 ml-auto mr-6 w-min"
|
||||||
|
isLoading={formState.isSubmitting}
|
||||||
|
>
|
||||||
|
Connect to AWS Secrets Manager
|
||||||
|
</Button>
|
||||||
|
</form>
|
||||||
|
</CardBody>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user