mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-20 14:42:51 +00:00
feat: chef secret-sync
This commit is contained in:
+97
@@ -0,0 +1,97 @@
|
||||
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 {
|
||||
TChefDataBag,
|
||||
useChefConnectionListDataBags,
|
||||
useChefConnectionListDataBagItems,
|
||||
TChefDataBagItem
|
||||
} from "@app/hooks/api/appConnections/chef";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
import { TSecretSyncForm } from "../schemas";
|
||||
|
||||
export const ChefSyncFields = () => {
|
||||
const { control, setValue } = useFormContext<
|
||||
TSecretSyncForm & { destination: SecretSync.Chef }
|
||||
>();
|
||||
|
||||
const connectionId = useWatch({ name: "connection.id", control });
|
||||
const dataBagName = useWatch({ name: "destinationConfig.dataBagName", control });
|
||||
const dataBagItemName = useWatch({ name: "destinationConfig.dataBagItemName", control });
|
||||
|
||||
const { data: dataBags, isLoading: isDataBagsLoading } = useChefConnectionListDataBags(
|
||||
connectionId,
|
||||
{
|
||||
enabled: Boolean(connectionId)
|
||||
}
|
||||
);
|
||||
|
||||
const { data: dataBagItems, isLoading: isDataBagItemsLoading } =
|
||||
useChefConnectionListDataBagItems(connectionId, dataBagName, {
|
||||
enabled: Boolean(connectionId && dataBagName)
|
||||
});
|
||||
|
||||
console.log({ dataBags, dataBagItems });
|
||||
|
||||
const handleChangeConnection = () => {
|
||||
setValue("destinationConfig.dataBagName", "");
|
||||
setValue("destinationConfig.dataBagItemName", "");
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncConnectionField onChange={handleChangeConnection} />
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.dataBagName"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Data Bag">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isDataBagsLoading && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={dataBags?.find((dataBag) => dataBag.name === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const selectedDataBag = option as SingleValue<TChefDataBag>;
|
||||
onChange(selectedDataBag?.name ?? "");
|
||||
setValue("destinationConfig.dataBagItemName", "");
|
||||
}}
|
||||
options={dataBags}
|
||||
placeholder="Select a data bag..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.dataBagItemName"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Data Bag Item">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isDataBagItemsLoading && Boolean(connectionId && dataBagName)}
|
||||
isDisabled={!connectionId || !dataBagName}
|
||||
value={dataBagItems?.find((dataBagItem) => dataBagItem.name === value) ?? null}
|
||||
onChange={(option) => {
|
||||
const selectedDataBagItem = option as SingleValue<TChefDataBagItem>;
|
||||
onChange(selectedDataBagItem?.name ?? "");
|
||||
setValue("destinationConfig.dataBagItemName", selectedDataBagItem?.name ?? "");
|
||||
}}
|
||||
options={dataBagItems}
|
||||
placeholder="Select a data bag item..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.name}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
+3
@@ -34,6 +34,7 @@ import { TerraformCloudSyncFields } from "./TerraformCloudSyncFields";
|
||||
import { VercelSyncFields } from "./VercelSyncFields";
|
||||
import { WindmillSyncFields } from "./WindmillSyncFields";
|
||||
import { ZabbixSyncFields } from "./ZabbixSyncFields";
|
||||
import { ChefSyncFields } from "./ChefSyncFields";
|
||||
|
||||
export const SecretSyncDestinationFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm>();
|
||||
@@ -103,6 +104,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <BitbucketSyncFields />;
|
||||
case SecretSync.LaravelForge:
|
||||
return <LaravelForgeSyncFields />;
|
||||
case SecretSync.Chef:
|
||||
return <ChefSyncFields />;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Config Field: ${destination}`);
|
||||
}
|
||||
|
||||
+1
@@ -70,6 +70,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
|
||||
case SecretSync.Netlify:
|
||||
case SecretSync.Bitbucket:
|
||||
case SecretSync.LaravelForge:
|
||||
case SecretSync.Chef:
|
||||
AdditionalSyncOptionsFieldsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
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 ChefSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.Chef }>();
|
||||
const dataBagName = watch("destinationConfig.dataBagName");
|
||||
const dataBagItemName = watch("destinationConfig.dataBagItemName");
|
||||
|
||||
return (
|
||||
<>
|
||||
<GenericFieldLabel label="Data Bag">{dataBagName}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Data Bag Item">{dataBagItemName}</GenericFieldLabel>
|
||||
</>
|
||||
);
|
||||
};
|
||||
+4
@@ -47,6 +47,7 @@ import { TerraformCloudSyncReviewFields } from "./TerraformCloudSyncReviewFields
|
||||
import { VercelSyncReviewFields } from "./VercelSyncReviewFields";
|
||||
import { WindmillSyncReviewFields } from "./WindmillSyncReviewFields";
|
||||
import { ZabbixSyncReviewFields } from "./ZabbixSyncReviewFields";
|
||||
import { ChefSyncReviewFields } from "./ChefSyncReviewFields";
|
||||
|
||||
export const SecretSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm>();
|
||||
@@ -173,6 +174,9 @@ export const SecretSyncReviewFields = () => {
|
||||
case SecretSync.LaravelForge:
|
||||
DestinationFieldsComponent = <LaravelForgeSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.Chef:
|
||||
DestinationFieldsComponent = <ChefSyncReviewFields />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Review Fields: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
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 ChefSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
destination: z.literal(SecretSync.Chef),
|
||||
destinationConfig: z.object({
|
||||
dataBagName: z.string().trim().min(1, "Data Bag Name required"),
|
||||
dataBagItemName: z.string().trim().min(1, "Data Bag Item Name required")
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -31,6 +31,7 @@ import { TerraformCloudSyncDestinationSchema } from "./terraform-cloud-destinati
|
||||
import { VercelSyncDestinationSchema } from "./vercel-sync-destination-schema";
|
||||
import { WindmillSyncDestinationSchema } from "./windmill-sync-destination-schema";
|
||||
import { ZabbixSyncDestinationSchema } from "./zabbix-sync-destination-schema";
|
||||
import { ChefSyncDestinationSchema } from "./chef-sync-destination-schema";
|
||||
|
||||
const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
AwsParameterStoreSyncDestinationSchema,
|
||||
@@ -63,7 +64,8 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
DigitalOceanAppPlatformSyncDestinationSchema,
|
||||
NetlifySyncDestinationSchema,
|
||||
BitbucketSyncDestinationSchema,
|
||||
LaravelForgeSyncDestinationSchema
|
||||
LaravelForgeSyncDestinationSchema,
|
||||
ChefSyncDestinationSchema
|
||||
]);
|
||||
|
||||
export const SecretSyncFormSchema = SecretSyncUnionSchema;
|
||||
|
||||
Reference in New Issue
Block a user