feat: adds secret sync handlers

This commit is contained in:
Piyush Gupta
2025-10-13 17:16:02 +05:30
parent 5b765841b7
commit 789d64843e
20 changed files with 289 additions and 46 deletions
@@ -50,6 +50,9 @@ export const LaravelForgeSyncFields = () => {
setValue("destinationConfig.orgSlug", "");
setValue("destinationConfig.serverId", "");
setValue("destinationConfig.siteId", "");
setValue("destinationConfig.orgName", "");
setValue("destinationConfig.serverName", "");
setValue("destinationConfig.siteName", "");
};
return (
@@ -69,6 +72,7 @@ export const LaravelForgeSyncFields = () => {
onChange={(option) => {
const selectedOrg = option as SingleValue<TLaravelForgeOrganization>;
onChange(selectedOrg?.slug ?? "");
setValue("destinationConfig.orgName", selectedOrg?.name ?? "");
setValue("destinationConfig.serverId", "");
setValue("destinationConfig.siteId", "");
}}
@@ -94,6 +98,7 @@ export const LaravelForgeSyncFields = () => {
onChange={(option) => {
const selectedServer = option as SingleValue<TLaravelForgeServer>;
onChange(selectedServer?.id ?? "");
setValue("destinationConfig.serverName", selectedServer?.name ?? "");
setValue("destinationConfig.siteId", "");
}}
options={servers}
@@ -118,6 +123,7 @@ export const LaravelForgeSyncFields = () => {
onChange={(option) => {
const selectedSite = option as SingleValue<TLaravelForgeSite>;
onChange(selectedSite?.id ?? "");
setValue("destinationConfig.siteName", selectedSite?.name ?? "");
}}
options={sites}
placeholder="Select a site..."
@@ -69,6 +69,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
case SecretSync.DigitalOceanAppPlatform:
case SecretSync.Netlify:
case SecretSync.Bitbucket:
case SecretSync.LaravelForge:
AdditionalSyncOptionsFieldsComponent = null;
break;
default:
@@ -77,7 +78,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
return (
<>
<p className="mb-4 text-sm text-bunker-300">Configure how secrets should be synced.</p>
<p className="text-bunker-300 mb-4 text-sm">Configure how secrets should be synced.</p>
{!hideInitialSync && (
<>
<Controller
@@ -100,7 +101,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
return (
<li key={name}>
<p className="text-mineshaft-300">
<span className="font-medium text-bunker-200">{name}</span>:{" "}
<span className="text-bunker-200 font-medium">{name}</span>:{" "}
{description}
</p>
</li>
@@ -118,7 +119,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
isDisabled={!syncOption?.canImportSecrets}
value={value}
onValueChange={(val) => onChange(val)}
className="w-full border border-mineshaft-500"
className="border-mineshaft-500 w-full border"
position="popper"
placeholder="Select an option..."
dropdownContainerClassName="max-w-none"
@@ -137,7 +138,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
)}
/>
{!syncOption?.canImportSecrets && (
<p className="-mt-2.5 mb-2.5 text-xs text-yellow">
<p className="text-yellow -mt-2.5 mb-2.5 text-xs">
<FontAwesomeIcon className="mr-1" size="xs" icon={faTriangleExclamation} />
{destinationName} only supports overwriting destination secrets.{" "}
{!currentSyncOption.disableSecretDeletion &&
@@ -218,7 +219,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
return (
<FormControl isError={Boolean(error)} errorText={error?.message}>
<Switch
className="bg-mineshaft-400/80 shadow-inner data-[state=checked]:bg-green/80"
className="bg-mineshaft-400/80 data-[state=checked]:bg-green/80 shadow-inner"
id="auto-sync-enabled"
thumbClassName="bg-mineshaft-800"
onCheckedChange={onChange}
@@ -0,0 +1,23 @@
import { useFormContext } from "react-hook-form";
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
import { GenericFieldLabel } from "@app/components/v2";
import { SecretSync } from "@app/hooks/api/secretSyncs";
export const LaravelForgeSyncReviewFields = () => {
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.LaravelForge }>();
const orgName = watch("destinationConfig.orgName");
const orgSlug = watch("destinationConfig.orgSlug");
const serverName = watch("destinationConfig.serverName");
const serverId = watch("destinationConfig.serverId");
const siteName = watch("destinationConfig.siteName");
const siteId = watch("destinationConfig.siteId");
return (
<>
<GenericFieldLabel label="Account">{orgName || orgSlug}</GenericFieldLabel>
<GenericFieldLabel label="Server">{serverName || serverId || "None"}</GenericFieldLabel>
<GenericFieldLabel label="Site">{siteName || siteId || "None"}</GenericFieldLabel>
</>
);
};
@@ -35,6 +35,7 @@ import { GitLabSyncReviewFields } from "./GitLabSyncReviewFields";
import { HCVaultSyncReviewFields } from "./HCVaultSyncReviewFields";
import { HerokuSyncReviewFields } from "./HerokuSyncReviewFields";
import { HumanitecSyncReviewFields } from "./HumanitecSyncReviewFields";
import { LaravelForgeSyncReviewFields } from "./LaravelForgeSyncReviewFields";
import { NetlifySyncReviewFields } from "./NetlifySyncReviewFields";
import { OCIVaultSyncReviewFields } from "./OCIVaultSyncReviewFields";
import { OnePassSyncReviewFields } from "./OnePassSyncReviewFields";
@@ -168,6 +169,9 @@ export const SecretSyncReviewFields = () => {
case SecretSync.Bitbucket:
DestinationFieldsComponent = <BitbucketSyncReviewFields />;
break;
case SecretSync.LaravelForge:
DestinationFieldsComponent = <LaravelForgeSyncReviewFields />;
break;
default:
throw new Error(`Unhandled Destination Review Fields: ${destination}`);
}
@@ -175,8 +179,8 @@ export const SecretSyncReviewFields = () => {
return (
<div className="mb-4 flex flex-col gap-6">
<div className="flex flex-col gap-3">
<div className="w-full border-b border-mineshaft-600">
<span className="text-sm text-mineshaft-300">Source</span>
<div className="border-mineshaft-600 w-full border-b">
<span className="text-mineshaft-300 text-sm">Source</span>
</div>
<div className="flex flex-wrap gap-x-8 gap-y-2">
<GenericFieldLabel label="Environment">{environment.name}</GenericFieldLabel>
@@ -184,14 +188,14 @@ export const SecretSyncReviewFields = () => {
</div>
</div>
<div className="flex flex-col gap-3">
<div className="flex w-full items-center gap-2 border-b border-mineshaft-600">
<span className="text-sm text-mineshaft-300">Destination</span>
{isChecking && <span className="text-xs text-mineshaft-400">Checking...</span>}
<div className="border-mineshaft-600 flex w-full items-center gap-2 border-b">
<span className="text-mineshaft-300 text-sm">Destination</span>
{isChecking && <span className="text-mineshaft-400 text-xs">Checking...</span>}
</div>
{hasDuplicate && (
<div className="mb-2 flex items-start rounded-md border border-yellow-600 bg-yellow-900/20 px-3 py-2">
<div className="flex text-sm text-yellow-100">
<FontAwesomeIcon icon={faWarning} className="mt-1 mr-2 text-yellow-600" />
<FontAwesomeIcon icon={faWarning} className="mr-2 mt-1 text-yellow-600" />
<div>
<p>
Another secret sync in your organization is already configured with the same
@@ -215,8 +219,8 @@ export const SecretSyncReviewFields = () => {
</div>
</div>
<div className="flex flex-col gap-3">
<div className="w-full border-b border-mineshaft-600">
<span className="text-sm text-mineshaft-300">Sync Options</span>
<div className="border-mineshaft-600 w-full border-b">
<span className="text-mineshaft-300 text-sm">Sync Options</span>
</div>
<div className="flex flex-wrap gap-x-8 gap-y-2">
<GenericFieldLabel label="Auto-Sync">
@@ -237,8 +241,8 @@ export const SecretSyncReviewFields = () => {
</div>
</div>
<div className="flex flex-col gap-3">
<div className="w-full border-b border-mineshaft-600">
<span className="text-sm text-mineshaft-300">Details</span>
<div className="border-mineshaft-600 w-full border-b">
<span className="text-mineshaft-300 text-sm">Details</span>
</div>
<div className="flex flex-wrap gap-x-8 gap-y-2">
<GenericFieldLabel label="Name">{name}</GenericFieldLabel>
@@ -8,8 +8,11 @@ export const LaravelForgeSyncDestinationSchema = BaseSecretSyncSchema().merge(
destination: z.literal(SecretSync.LaravelForge),
destinationConfig: z.object({
orgSlug: z.string().trim().min(1, "Org Slug required"),
orgName: z.string().trim().min(1, "Org Name required"),
serverId: z.string().trim().min(1, "Server ID required"),
siteId: z.string().trim().min(1, "Site ID required")
serverName: z.string().trim().min(1, "Server Name required"),
siteId: z.string().trim().min(1, "Site ID required"),
siteName: z.string().trim().min(1, "Site Name required")
})
})
);