mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-20 12:38:19 +00:00
feat: secret sync foundation
This commit is contained in:
+132
@@ -0,0 +1,132 @@
|
||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||
import { SingleValue } from "react-select";
|
||||
|
||||
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
|
||||
import { FilterableSelect, FormControl } from "@app/components/v2";
|
||||
import {
|
||||
TLaravelForgeOrganization,
|
||||
TLaravelForgeServer,
|
||||
TLaravelForgeSite,
|
||||
useLaravelForgeConnectionListOrganizations,
|
||||
useLaravelForgeConnectionListServers,
|
||||
useLaravelForgeConnectionListSites
|
||||
} from "@app/hooks/api/appConnections/laravel-forge";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
import { TSecretSyncForm } from "../schemas";
|
||||
|
||||
export const LaravelForgeSyncFields = () => {
|
||||
const { control, setValue } = useFormContext<
|
||||
TSecretSyncForm & { destination: SecretSync.LaravelForge }
|
||||
>();
|
||||
|
||||
const connectionId = useWatch({ name: "connection.id", control });
|
||||
const orgSlug = useWatch({ name: "destinationConfig.orgSlug", control });
|
||||
const serverId = useWatch({ name: "destinationConfig.serverId", control });
|
||||
|
||||
const { data: organizations, isLoading: isOrganizationsLoading } =
|
||||
useLaravelForgeConnectionListOrganizations(connectionId, {
|
||||
enabled: Boolean(connectionId)
|
||||
});
|
||||
|
||||
const { data: servers, isLoading: isServersLoading } = useLaravelForgeConnectionListServers(
|
||||
connectionId,
|
||||
orgSlug,
|
||||
{
|
||||
enabled: Boolean(connectionId && orgSlug)
|
||||
}
|
||||
);
|
||||
|
||||
const { data: sites, isLoading: isSitesLoading } = useLaravelForgeConnectionListSites(
|
||||
connectionId,
|
||||
orgSlug,
|
||||
serverId,
|
||||
{
|
||||
enabled: Boolean(connectionId && orgSlug && serverId)
|
||||
}
|
||||
);
|
||||
|
||||
const handleChangeConnection = () => {
|
||||
setValue("destinationConfig.orgSlug", "");
|
||||
setValue("destinationConfig.serverId", "");
|
||||
setValue("destinationConfig.siteId", "");
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncConnectionField onChange={handleChangeConnection} />
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.orgSlug"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Organization">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isOrganizationsLoading && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={organizations?.find((org) => org.slug === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const selectedOrg = option as SingleValue<TLaravelForgeOrganization>;
|
||||
onChange(selectedOrg?.slug ?? "");
|
||||
setValue("destinationConfig.serverId", "");
|
||||
setValue("destinationConfig.siteId", "");
|
||||
}}
|
||||
options={organizations}
|
||||
placeholder="Select an organization..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.serverId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Server">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isServersLoading && Boolean(connectionId && orgSlug)}
|
||||
isDisabled={!connectionId || !orgSlug}
|
||||
value={servers?.find((server) => server.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const selectedServer = option as SingleValue<TLaravelForgeServer>;
|
||||
onChange(selectedServer?.id ?? "");
|
||||
setValue("destinationConfig.siteId", "");
|
||||
}}
|
||||
options={servers}
|
||||
placeholder="Select a server..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.siteId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Site">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isSitesLoading && Boolean(connectionId && orgSlug && serverId)}
|
||||
isDisabled={!connectionId || !orgSlug || !serverId}
|
||||
value={sites?.find((site) => site.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const selectedSite = option as SingleValue<TLaravelForgeSite>;
|
||||
onChange(selectedSite?.id ?? "");
|
||||
}}
|
||||
options={sites}
|
||||
placeholder="Select a site..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
+3
@@ -23,6 +23,7 @@ import { GitLabSyncFields } from "./GitLabSyncFields";
|
||||
import { HCVaultSyncFields } from "./HCVaultSyncFields";
|
||||
import { HerokuSyncFields } from "./HerokuSyncFields";
|
||||
import { HumanitecSyncFields } from "./HumanitecSyncFields";
|
||||
import { LaravelForgeSyncFields } from "./LaravelForgeSyncFields";
|
||||
import { NetlifySyncFields } from "./NetlifySyncFields";
|
||||
import { OCIVaultSyncFields } from "./OCIVaultSyncFields";
|
||||
import { RailwaySyncFields } from "./RailwaySyncFields";
|
||||
@@ -100,6 +101,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <NetlifySyncFields />;
|
||||
case SecretSync.Bitbucket:
|
||||
return <BitbucketSyncFields />;
|
||||
case SecretSync.LaravelForge:
|
||||
return <LaravelForgeSyncFields />;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Config Field: ${destination}`);
|
||||
}
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
export const LaravelForgeSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
destination: z.literal(SecretSync.LaravelForge),
|
||||
destinationConfig: z.object({
|
||||
orgSlug: z.string().trim().min(1, "Org Slug required"),
|
||||
serverId: z.string().trim().min(1, "Server ID required"),
|
||||
siteId: z.string().trim().min(1, "Site ID required")
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -20,6 +20,7 @@ import { GitlabSyncDestinationSchema } from "./gitlab-sync-destination-schema";
|
||||
import { HCVaultSyncDestinationSchema } from "./hc-vault-sync-destination-schema";
|
||||
import { HerokuSyncDestinationSchema } from "./heroku-sync-destination-schema";
|
||||
import { HumanitecSyncDestinationSchema } from "./humanitec-sync-destination-schema";
|
||||
import { LaravelForgeSyncDestinationSchema } from "./laravel-forge-sync-destination-schema";
|
||||
import { NetlifySyncDestinationSchema } from "./netlify-sync-destination-schema";
|
||||
import { OCIVaultSyncDestinationSchema } from "./oci-vault-sync-destination-schema";
|
||||
import { RailwaySyncDestinationSchema } from "./railway-sync-destination-schema";
|
||||
@@ -61,7 +62,8 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
ChecklySyncDestinationSchema,
|
||||
DigitalOceanAppPlatformSyncDestinationSchema,
|
||||
NetlifySyncDestinationSchema,
|
||||
BitbucketSyncDestinationSchema
|
||||
BitbucketSyncDestinationSchema,
|
||||
LaravelForgeSyncDestinationSchema
|
||||
]);
|
||||
|
||||
export const SecretSyncFormSchema = SecretSyncUnionSchema;
|
||||
|
||||
Reference in New Issue
Block a user