feat: added render app connection

This commit is contained in:
Sheen Capadngan
2025-06-13 20:14:24 +08:00
parent b26e56c97e
commit f9c012387c
17 changed files with 339 additions and 13 deletions
+5 -1
View File
@@ -37,6 +37,7 @@ import {
WindmillConnectionMethod
} from "@app/hooks/api/appConnections/types";
import { OCIConnectionMethod } from "@app/hooks/api/appConnections/types/oci-connection";
import { RenderConnectionMethod } from "@app/hooks/api/appConnections/types/render-connection";
export const APP_CONNECTION_MAP: Record<
AppConnection,
@@ -78,7 +79,8 @@ export const APP_CONNECTION_MAP: Record<
[AppConnection.LDAP]: { name: "LDAP", image: "LDAP.png", size: 65 },
[AppConnection.TeamCity]: { name: "TeamCity", image: "TeamCity.png" },
[AppConnection.OCI]: { name: "OCI", image: "Oracle.png", enterprise: true },
[AppConnection.OnePass]: { name: "1Password", image: "1Password.png" }
[AppConnection.OnePass]: { name: "1Password", image: "1Password.png" },
[AppConnection.Render]: { name: "Render", image: "Render.png" }
};
export const getAppConnectionMethodDetails = (method: TAppConnection["method"]) => {
@@ -124,6 +126,8 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
return { name: "App Role", icon: faUser };
case LdapConnectionMethod.SimpleBind:
return { name: "Simple Bind", icon: faLink };
case RenderConnectionMethod.ApiKey:
return { name: "API Key", icon: faKey };
default:
throw new Error(`Unhandled App Connection Method: ${method}`);
}
@@ -22,5 +22,6 @@ export enum AppConnection {
LDAP = "ldap",
TeamCity = "teamcity",
OCI = "oci",
OnePass = "1password"
OnePass = "1password",
Render = "render"
}
@@ -20,6 +20,7 @@ import { TMySqlConnection } from "./mysql-connection";
import { TOCIConnection } from "./oci-connection";
import { TOracleDBConnection } from "./oracledb-connection";
import { TPostgresConnection } from "./postgres-connection";
import { TRenderConnection } from "./render-connection";
import { TTeamCityConnection } from "./teamcity-connection";
import { TTerraformCloudConnection } from "./terraform-cloud-connection";
import { TVercelConnection } from "./vercel-connection";
@@ -45,6 +46,7 @@ export * from "./mysql-connection";
export * from "./oci-connection";
export * from "./oracledb-connection";
export * from "./postgres-connection";
export * from "./render-connection";
export * from "./teamcity-connection";
export * from "./terraform-cloud-connection";
export * from "./vercel-connection";
@@ -74,7 +76,8 @@ export type TAppConnection =
| TLdapConnection
| TTeamCityConnection
| TOCIConnection
| TOnePassConnection;
| TOnePassConnection
| TRenderConnection;
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id">;
@@ -126,4 +129,5 @@ export type TAppConnectionMap = {
[AppConnection.TeamCity]: TTeamCityConnection;
[AppConnection.OCI]: TOCIConnection;
[AppConnection.OnePass]: TOnePassConnection;
[AppConnection.Render]: TRenderConnection;
};
@@ -0,0 +1,13 @@
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";
export enum RenderConnectionMethod {
ApiKey = "api-key"
}
export type TRenderConnection = TRootAppConnection & { app: AppConnection.Render } & {
method: RenderConnectionMethod.ApiKey;
credentials: {
apiKey: string;
};
};
@@ -29,6 +29,7 @@ import { MySqlConnectionForm } from "./MySqlConnectionForm";
import { OCIConnectionForm } from "./OCIConnectionForm";
import { OracleDBConnectionForm } from "./OracleDBConnectionForm";
import { PostgresConnectionForm } from "./PostgresConnectionForm";
import { RenderConnectionForm } from "./RenderConnectionForm";
import { TeamCityConnectionForm } from "./TeamCityConnectionForm";
import { TerraformCloudConnectionForm } from "./TerraformCloudConnectionForm";
import { VercelConnectionForm } from "./VercelConnectionForm";
@@ -119,6 +120,8 @@ const CreateForm = ({ app, onComplete }: CreateFormProps) => {
return <OCIConnectionForm onSubmit={onSubmit} />;
case AppConnection.OnePass:
return <OnePassConnectionForm onSubmit={onSubmit} />;
case AppConnection.Render:
return <RenderConnectionForm onSubmit={onSubmit} />;
default:
throw new Error(`Unhandled App ${app}`);
}
@@ -203,6 +206,8 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
return <OCIConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
case AppConnection.OnePass:
return <OnePassConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
case AppConnection.Render:
return <RenderConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
default:
throw new Error(`Unhandled App ${(appConnection as TAppConnection).app}`);
}
@@ -0,0 +1,132 @@
import { Controller, FormProvider, useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { z } from "zod";
import {
Button,
FormControl,
ModalClose,
SecretInput,
Select,
SelectItem
} from "@app/components/v2";
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
import { RenderConnectionMethod, TRenderConnection } from "@app/hooks/api/appConnections";
import { AppConnection } from "@app/hooks/api/appConnections/enums";
import {
genericAppConnectionFieldsSchema,
GenericAppConnectionsFields
} from "./GenericAppConnectionFields";
type Props = {
appConnection?: TRenderConnection;
onSubmit: (formData: FormData) => Promise<void>;
};
const rootSchema = genericAppConnectionFieldsSchema.extend({
app: z.literal(AppConnection.Render)
});
const formSchema = z.discriminatedUnion("method", [
rootSchema.extend({
method: z.literal(RenderConnectionMethod.ApiKey),
credentials: z.object({
apiKey: z.string().trim().min(1, "API Key required")
})
})
]);
type FormData = z.infer<typeof formSchema>;
export const RenderConnectionForm = ({ appConnection, onSubmit }: Props) => {
const isUpdate = Boolean(appConnection);
const form = useForm<FormData>({
resolver: zodResolver(formSchema),
defaultValues: appConnection ?? {
app: AppConnection.Render,
method: RenderConnectionMethod.ApiKey
}
});
const {
handleSubmit,
control,
formState: { isSubmitting, isDirty }
} = form;
return (
<FormProvider {...form}>
<form onSubmit={handleSubmit(onSubmit)}>
{!isUpdate && <GenericAppConnectionsFields />}
<Controller
name="method"
control={control}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl
tooltipText={`The method you would like to use to connect with ${
APP_CONNECTION_MAP[AppConnection.Render].name
}. This field cannot be changed after creation.`}
errorText={error?.message}
isError={Boolean(error?.message)}
label="Method"
>
<Select
isDisabled={isUpdate}
value={value}
onValueChange={(val) => onChange(val)}
className="w-full border border-mineshaft-500"
position="popper"
dropdownContainerClassName="max-w-none"
>
{Object.values(RenderConnectionMethod).map((method) => {
return (
<SelectItem value={method} key={method}>
{getAppConnectionMethodDetails(method).name}{" "}
</SelectItem>
);
})}
</Select>
</FormControl>
)}
/>
<Controller
name="credentials.apiKey"
control={control}
shouldUnregister
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl
errorText={error?.message}
isError={Boolean(error?.message)}
label="API Key"
>
<SecretInput
containerClassName="text-gray-400 group-focus-within:!border-primary-400/50 border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
value={value}
onChange={(e) => onChange(e.target.value)}
/>
</FormControl>
)}
/>
<div className="mt-8 flex items-center">
<Button
className="mr-4"
size="sm"
type="submit"
colorSchema="secondary"
isLoading={isSubmitting}
isDisabled={isSubmitting || !isDirty}
>
{isUpdate ? "Update Credentials" : "Connect to Render"}
</Button>
<ModalClose asChild>
<Button colorSchema="secondary" variant="plain">
Cancel
</Button>
</ModalClose>
</div>
</form>
</FormProvider>
);
};