mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 23:25:26 +00:00
190 lines
6.6 KiB
TypeScript
190 lines
6.6 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { useRouter } from "next/router";
|
|
import queryString from "query-string";
|
|
|
|
import {
|
|
useCreateIntegration
|
|
} from "@app/hooks/api";
|
|
|
|
import {
|
|
Button,
|
|
Card,
|
|
CardTitle,
|
|
FormControl,
|
|
Input,
|
|
Select,
|
|
SelectItem
|
|
} from "../../../components/v2";
|
|
import { useGetIntegrationAuthById } from "../../../hooks/api/integrationAuth";
|
|
import { useGetWorkspaceById } from "../../../hooks/api/workspace";
|
|
|
|
const awsRegions = [
|
|
{ name: "US East (Ohio)", slug: "us-east-2" },
|
|
{ name: "US East (N. Virginia)", slug: "us-east-1" },
|
|
{ name: "US West (N. California)", slug: "us-west-1" },
|
|
{ name: "US West (Oregon)", slug: "us-west-2" },
|
|
{ name: "Africa (Cape Town)", slug: "af-south-1" },
|
|
{ name: "Asia Pacific (Hong Kong)", slug: "ap-east-1" },
|
|
{ name: "Asia Pacific (Hyderabad)", slug: "ap-south-2" },
|
|
{ name: "Asia Pacific (Jakarta)", slug: "ap-southeast-3" },
|
|
{ name: "Asia Pacific (Melbourne)", slug: "ap-southeast-4" },
|
|
{ name: "Asia Pacific (Mumbai)", slug: "ap-south-1" },
|
|
{ name: "Asia Pacific (Osaka)", slug: "ap-northeast-3" },
|
|
{ name: "Asia Pacific (Seoul)", slug: "ap-northeast-2" },
|
|
{ name: "Asia Pacific (Singapore)", slug: "ap-southeast-1" },
|
|
{ name: "Asia Pacific (Sydney)", slug: "ap-southeast-2" },
|
|
{ name: "Asia Pacific (Tokyo)", slug: "ap-northeast-1" },
|
|
{ name: "Canada (Central)", slug: "ca-central-1" },
|
|
{ name: "Europe (Frankfurt)", slug: "eu-central-1" },
|
|
{ name: "Europe (Ireland)", slug: "eu-west-1" },
|
|
{ name: "Europe (London)", slug: "eu-west-2" },
|
|
{ name: "Europe (Milan)", slug: "eu-south-1" },
|
|
{ name: "Europe (Paris)", slug: "eu-west-3" },
|
|
{ name: "Europe (Spain)", slug: "eu-south-2" },
|
|
{ name: "Europe (Stockholm)", slug: "eu-north-1" },
|
|
{ name: "Europe (Zurich)", slug: "eu-central-2" },
|
|
{ name: "Middle East (Bahrain)", slug: "me-south-1" },
|
|
{ name: "Middle East (UAE)", slug: "me-central-1" },
|
|
{ name: "South America (Sao Paulo)", slug: "sa-east-1" },
|
|
{ name: "AWS GovCloud (US-East)", slug: "us-gov-east-1" },
|
|
{ name: "AWS GovCloud (US-West)", slug: "us-gov-west-1" }
|
|
];
|
|
|
|
export default function AWSSecretManagerCreateIntegrationPage() {
|
|
const router = useRouter();
|
|
const { mutateAsync } = useCreateIntegration();
|
|
|
|
const { integrationAuthId } = queryString.parse(router.asPath.split("?")[1]);
|
|
|
|
const { data: workspace } = useGetWorkspaceById(localStorage.getItem("projectData.id") ?? "");
|
|
const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? "");
|
|
|
|
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
|
|
const [secretPath, setSecretPath] = useState("/");
|
|
const [selectedAWSRegion, setSelectedAWSRegion] = useState("");
|
|
const [targetSecretName, setTargetSecretName] = useState("");
|
|
const [targetSecretNameErrorText, setTargetSecretNameErrorText] = useState("");
|
|
|
|
// const [path, setPath] = useState('');
|
|
// const [pathErrorText, setPathErrorText] = useState('');
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
useEffect(() => {
|
|
if (workspace) {
|
|
setSelectedSourceEnvironment(workspace.environments[0].slug);
|
|
setSelectedAWSRegion(awsRegions[0].slug);
|
|
}
|
|
}, [workspace]);
|
|
|
|
// const isValidAWSPath = (path: string) => {
|
|
// const pattern = /^\/[\w./]+\/$/;
|
|
// return pattern.test(path) && path.length <= 2048;
|
|
// }
|
|
|
|
const handleButtonClick = async () => {
|
|
try {
|
|
if (targetSecretName.trim() === "") {
|
|
setTargetSecretName("Secret name cannot be blank");
|
|
return;
|
|
}
|
|
|
|
if (!integrationAuth?._id) return;
|
|
|
|
setIsLoading(true);
|
|
|
|
await mutateAsync({
|
|
integrationAuthId: integrationAuth?._id,
|
|
isActive: true,
|
|
app: targetSecretName.trim(),
|
|
appId: null,
|
|
sourceEnvironment: selectedSourceEnvironment,
|
|
targetEnvironment: null,
|
|
targetEnvironmentId: null,
|
|
targetService: null,
|
|
targetServiceId: null,
|
|
owner: null,
|
|
path: null,
|
|
region: selectedAWSRegion,
|
|
secretPath
|
|
});
|
|
|
|
setIsLoading(false);
|
|
setTargetSecretNameErrorText("");
|
|
|
|
router.push(`/integrations/${localStorage.getItem("projectData.id")}`);
|
|
} catch (err) {
|
|
console.error(err);
|
|
}
|
|
};
|
|
|
|
return integrationAuth && workspace && selectedSourceEnvironment ? (
|
|
<div className="flex h-full w-full items-center justify-center">
|
|
<Card className="max-w-md rounded-md p-8">
|
|
<CardTitle className="text-center">AWS Secret Manager Integration</CardTitle>
|
|
<FormControl label="Project Environment" className="mt-4">
|
|
<Select
|
|
value={selectedSourceEnvironment}
|
|
onValueChange={(val) => setSelectedSourceEnvironment(val)}
|
|
className="w-full border border-mineshaft-500"
|
|
>
|
|
{workspace?.environments.map((sourceEnvironment) => (
|
|
<SelectItem
|
|
value={sourceEnvironment.slug}
|
|
key={`flyio-environment-${sourceEnvironment.slug}`}
|
|
>
|
|
{sourceEnvironment.name}
|
|
</SelectItem>
|
|
))}
|
|
</Select>
|
|
</FormControl>
|
|
<FormControl label="Secrets Path">
|
|
<Input
|
|
value={secretPath}
|
|
onChange={(evt) => setSecretPath(evt.target.value)}
|
|
placeholder="Provide a path, default is /"
|
|
/>
|
|
</FormControl>
|
|
<FormControl label="AWS Region">
|
|
<Select
|
|
value={selectedAWSRegion}
|
|
onValueChange={(val) => setSelectedAWSRegion(val)}
|
|
className="w-full border border-mineshaft-500"
|
|
>
|
|
{awsRegions.map((awsRegion) => (
|
|
<SelectItem value={awsRegion.slug} key={`flyio-environment-${awsRegion.slug}`}>
|
|
{awsRegion.name}
|
|
</SelectItem>
|
|
))}
|
|
</Select>
|
|
</FormControl>
|
|
<FormControl
|
|
label="AWS SM Secret Name"
|
|
errorText={targetSecretNameErrorText}
|
|
isError={targetSecretNameErrorText !== "" ?? false}
|
|
>
|
|
<Input
|
|
placeholder={`${workspace.name
|
|
.toLowerCase()
|
|
.replace(/ /g, "-")}/${selectedSourceEnvironment}`}
|
|
value={targetSecretName}
|
|
onChange={(e) => setTargetSecretName(e.target.value)}
|
|
/>
|
|
</FormControl>
|
|
<Button
|
|
onClick={handleButtonClick}
|
|
color="mineshaft"
|
|
className="mt-4"
|
|
isLoading={isLoading}
|
|
>
|
|
Create Integration
|
|
</Button>
|
|
</Card>
|
|
</div>
|
|
) : (
|
|
<div />
|
|
);
|
|
}
|
|
|
|
AWSSecretManagerCreateIntegrationPage.requireAuth = true;
|