fix merge conflicts

This commit is contained in:
Vladyslav Matsiiako
2023-09-15 13:28:11 -07:00
parent bde788c4f6
commit db5883ae56
@@ -1,10 +1,10 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import Head from "next/head"; import { Controller, useForm } from "react-hook-form";
import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { faArrowUpRightFromSquare, faBookOpen, faBugs } from "@fortawesome/free-solid-svg-icons"; import { yupResolver } from "@hookform/resolvers/yup";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { motion } from "framer-motion";
import queryString from "query-string"; import queryString from "query-string";
import * as yup from "yup";
import { import {
useCreateIntegration useCreateIntegration
@@ -17,7 +17,12 @@ import {
FormControl, FormControl,
Input, Input,
Select, Select,
SelectItem SelectItem,
Switch,
Tab,
TabList,
TabPanel,
Tabs
} from "../../../components/v2"; } from "../../../components/v2";
import { import {
useGetIntegrationAuthApps, useGetIntegrationAuthApps,
@@ -25,41 +30,93 @@ import {
} from "../../../hooks/api/integrationAuth"; } from "../../../hooks/api/integrationAuth";
import { useGetWorkspaceById } from "../../../hooks/api/workspace"; import { useGetWorkspaceById } from "../../../hooks/api/workspace";
enum TabSections {
Connection = "connection",
Options = "options"
}
const schema = yup.object({
selectedSourceEnvironment: yup.string().required("Source environment is required"),
secretPath: yup.string().required("Secret path is required"),
targetAppId: yup.string().required("GCP project is required"),
secretPrefix: yup.string(),
secretSuffix: yup.string(),
shouldLabel: yup.boolean(),
labelName: yup.string(),
labelValue: yup.string()
});
type FormData = yup.InferType<typeof schema>;
export default function GCPSecretManagerCreateIntegrationPage() { export default function GCPSecretManagerCreateIntegrationPage() {
const router = useRouter(); const router = useRouter();
const {
control,
handleSubmit,
setValue,
watch
} = useForm<FormData>({
resolver: yupResolver(schema),
defaultValues: {
secretPath: "/",
shouldLabel: false,
labelName: "managed-by",
labelValue: "infisical"
}
});
const shouldLabel = watch("shouldLabel");
const selectedSourceEnvironment = watch("selectedSourceEnvironment");
const { mutateAsync } = useCreateIntegration(); const { mutateAsync } = useCreateIntegration();
const { integrationAuthId } = queryString.parse(router.asPath.split("?")[1]); const { integrationAuthId } = queryString.parse(router.asPath.split("?")[1]);
const { data: workspace } = useGetWorkspaceById(localStorage.getItem("projectData.id") ?? ""); const { data: workspace } = useGetWorkspaceById(localStorage.getItem("projectData.id") ?? "");
const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? ""); const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? "");
const { data: integrationAuthApps, isLoading: isintegrationAuthAppsLoading } = useGetIntegrationAuthApps({ const { data: integrationAuthApps } = useGetIntegrationAuthApps({
integrationAuthId: (integrationAuthId as string) ?? "" integrationAuthId: (integrationAuthId as string) ?? ""
}); });
const [selectedSourceEnvironment, setSelectedSourceEnvironment] = useState("");
const [targetAppId, setTargetAppId] = useState("");
const [secretPath, setSecretPath] = useState("/");
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
if (shouldLabel) {
setValue("labelName", "managed-by");
setValue("labelValue", "infisical");
return;
}
setValue("labelName", undefined);
setValue("labelValue", undefined);
}, [shouldLabel]);
useEffect(() => { useEffect(() => {
if (workspace) { if (workspace) {
setSelectedSourceEnvironment(workspace.environments[0].slug); setValue("selectedSourceEnvironment", workspace.environments[0].slug);
} }
}, [workspace]); }, [workspace]);
useEffect(() => { useEffect(() => {
if (integrationAuthApps) { if (integrationAuthApps) {
if (integrationAuthApps.length > 0) { if (integrationAuthApps.length > 0) {
setTargetAppId(integrationAuthApps[0].appId as string); setValue("targetAppId", integrationAuthApps[0].appId as string);
} else { } else {
setTargetAppId("none"); setValue("targetAppId", "none");
} }
} }
}, [integrationAuthApps]); }, [integrationAuthApps]);
const handleButtonClick = async () => { const onFormSubmit = async ({
selectedSourceEnvironment: sce,
secretPath,
targetAppId,
secretPrefix,
secretSuffix,
shouldLabel: sl,
labelName,
labelValue
}: FormData) => {
try { try {
setIsLoading(true); setIsLoading(true);
@@ -70,118 +127,235 @@ export default function GCPSecretManagerCreateIntegrationPage() {
isActive: true, isActive: true,
app: integrationAuthApps?.find((integrationAuthApp) => integrationAuthApp.appId === targetAppId)?.name, app: integrationAuthApps?.find((integrationAuthApp) => integrationAuthApp.appId === targetAppId)?.name,
appId: targetAppId, appId: targetAppId,
sourceEnvironment: selectedSourceEnvironment, sourceEnvironment: sce,
secretPath secretPath,
metadata: {
secretPrefix,
secretSuffix,
...(sl ? {
secretGCPLabel: {
labelName,
labelValue
}
} : {})
}
}); });
setIsLoading(false); setIsLoading(false);
router.push(`/integrations/${localStorage.getItem("projectData.id")}`); router.push(`/integrations/${localStorage.getItem("projectData.id")}`);
} catch (err) { } catch (err) {
console.error(err); console.error(err);
setIsLoading(false);
} }
}; }
return integrationAuth && return integrationAuth &&
workspace && workspace &&
selectedSourceEnvironment && selectedSourceEnvironment &&
integrationAuthApps && integrationAuthApps ? (
targetAppId ? ( <form
<div className="flex h-full w-full items-center justify-center"> onSubmit={handleSubmit(onFormSubmit)}
<Card className="max-w-lg rounded-md border border-mineshaft-600 mb-12"> className="flex h-full w-full items-center justify-center"
<Head> >
<title>Set Up GCP Secret Manager Integration</title> <Card className="max-w-md rounded-md p-8">
<link rel='icon' href='/infisical.ico' /> <CardTitle className="text-center">GCP Secret Manager Integration</CardTitle>
</Head> <Tabs defaultValue={TabSections.Connection}>
<CardTitle <TabList>
className="text-left px-6 text-xl" <Tab value={TabSections.Connection}>Connection</Tab>
subTitle="After creating an integration, your secrets will automatically start syncing from Infisical to GCP Secret Manager." <Tab value={TabSections.Options}>Options</Tab>
> </TabList>
GCP Secret Manager Integration <TabPanel value={TabSections.Connection}>
<Link href="https://infisical.com/docs/integrations/cloud/gcp-secret-manager" passHref> <motion.div
<a target="_blank" rel="noopener noreferrer"> key="panel-1"
<div className="ml-2 mb-1 rounded-md text-yellow text-sm inline-block bg-yellow/20 px-1.5 pb-[0.03rem] pt-[0.04rem] opacity-80 hover:opacity-100 cursor-default"> transition={{ duration: 0.15 }}
<FontAwesomeIcon icon={faBookOpen} className="mr-1.5"/> initial={{ opacity: 0, translateX: 30 }}
Docs animate={{ opacity: 1, translateX: 0 }}
<FontAwesomeIcon icon={faArrowUpRightFromSquare} className="ml-1.5 text-xxs mb-[0.07rem]"/> exit={{ opacity: 0, translateX: 30 }}
</div> >
</a> <div>
</Link> <Controller
</CardTitle> control={control}
<FormControl label="Project Environment" className="px-6"> name="selectedSourceEnvironment"
<Select render={({ field: { onChange, ...field }, fieldState: { error } }) => (
value={selectedSourceEnvironment} <FormControl
onValueChange={(val) => setSelectedSourceEnvironment(val)} label="Project Environment"
className="w-full border border-mineshaft-500" errorText={error?.message}
> isError={Boolean(error)}
{workspace?.environments.map((sourceEnvironment) => ( >
<SelectItem <Select
value={sourceEnvironment.slug} defaultValue={field.value}
key={`source-environment-${sourceEnvironment.slug}`} {...field}
> onValueChange={(e) => onChange(e)}
{sourceEnvironment.name} className="w-full"
</SelectItem> >
))} {workspace?.environments.map((sourceEnvironment) => (
</Select> <SelectItem
</FormControl> value={sourceEnvironment.slug}
<FormControl label="Secrets Path" className="px-6"> key={`source-environment-${sourceEnvironment.slug}`}
<Input >
value={secretPath} {sourceEnvironment.name}
onChange={(evt) => setSecretPath(evt.target.value)} </SelectItem>
placeholder="Provide a path, default is /" ))}
/> </Select>
</FormControl> </FormControl>
<FormControl label="GCP Project" className="px-6"> )}
<Select />
value={targetAppId} <Controller
onValueChange={(val) => setTargetAppId(val)} control={control}
className="w-full border border-mineshaft-500" defaultValue=""
isDisabled={integrationAuthApps.length === 0} name="secretPath"
> render={({ field, fieldState: { error } }) => (
{integrationAuthApps.length > 0 ? ( <FormControl
integrationAuthApps.map((integrationAuthApp) => ( label="Secrets Path"
<SelectItem isError={Boolean(error)}
value={integrationAuthApp.appId as string} errorText={error?.message}
key={`target-app-${integrationAuthApp.appId}`} >
<Input
{...field}
placeholder="/"
/>
</FormControl>
)}
/>
<Controller
control={control}
name="targetAppId"
render={({ field: { onChange, ...field }, fieldState: { error } }) => {
return (
<FormControl
label="GCP Project"
errorText={error?.message}
isError={Boolean(error)}
>
<Select
{...field}
onValueChange={(e) => {
if (e === "") return;
onChange(e)
}}
className="w-full"
>
{integrationAuthApps.length > 0 ? (
integrationAuthApps.map((integrationAuthApp) => (
<SelectItem
value={String(integrationAuthApp.appId as string)}
key={`target-app-${String(integrationAuthApp.appId)}`}
>
{integrationAuthApp.name}
</SelectItem>
))
) : (
<SelectItem value="none" key="target-app-none">
No projects found
</SelectItem>
)}
</Select>
</FormControl>
)
}}
/>
<Button
className="mt-4"
size="sm"
type="submit"
isLoading={isLoading}
> >
{integrationAuthApp.name} Create Integration
</SelectItem> </Button>
)) </div>
) : ( </motion.div>
<SelectItem value="none" key="target-app-none"> </TabPanel>
No projects found <TabPanel value={TabSections.Options}>
</SelectItem> <Controller
control={control}
name="secretPrefix"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Secret Prefix"
isError={Boolean(error)}
errorText={error?.message}
>
<Input
{...field}
placeholder="INFISICAL_"
/>
</FormControl>
)}
/>
<Controller
control={control}
name="secretSuffix"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Secret Suffix"
isError={Boolean(error)}
errorText={error?.message}
>
<Input
{...field}
placeholder="_INFISICAL"
/>
</FormControl>
)}
/>
<div className="mt-8">
<Controller
control={control}
name="shouldLabel"
render={({ field: { onChange, value } }) => (
<Switch
id="label-gcp"
onCheckedChange={(isChecked) => onChange(isChecked)}
isChecked={value}
>
Label in GCP Secret Manager
</Switch>
)}
/>
</div>
{shouldLabel && (
<div className="mt-8">
<Controller
control={control}
name="labelName"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Label Name"
isError={Boolean(error)}
errorText={error?.message}
>
<Input
{...field}
placeholder="managed-by"
/>
</FormControl>
)}
/>
<Controller
control={control}
name="labelValue"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Label Name"
isError={Boolean(error)}
errorText={error?.message}
>
<Input
{...field}
placeholder="infisical"
/>
</FormControl>
)}
/>
</div>
)} )}
</Select> </TabPanel>
</FormControl> </Tabs>
<Button
onClick={handleButtonClick}
colorSchema="primary"
variant="outline_bg"
className="mb-8 mt-2 ml-auto mr-6 w-min"
isLoading={isLoading}
isDisabled={integrationAuthApps.length === 0}
>
Create Integration
</Button>
</Card> </Card>
</div> </form>
) : ( ) : (
<div className="flex justify-center items-center w-full h-full"> <div />
{isintegrationAuthAppsLoading ? <img src="/images/loading/loading.gif" height={70} width={120} alt="infisical loading indicator" /> : <div className="max-w-md h-max p-6 border border-mineshaft-600 rounded-md bg-mineshaft-800 text-mineshaft-200 flex flex-col text-center">
<FontAwesomeIcon icon={faBugs} className="text-6xl my-2 inlineli"/>
<p>
Something went wrong. Please contact <a
className="inline underline underline-offset-4 decoration-primary-500 opacity-80 hover:opacity-100 text-mineshaft-100 duration-200 cursor-pointer"
target="_blank"
rel="noopener noreferrer"
href="mailto:[email protected]"
>
support@infisical.com
</a> if the issue persists.
</p>
</div>}
</div>
); );
} }
GCPSecretManagerCreateIntegrationPage.requireAuth = true; GCPSecretManagerCreateIntegrationPage.requireAuth = true;