diff --git a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretRedisProviderForm.tsx b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretRedisProviderForm.tsx index e483f6280..9f0f75a44 100644 --- a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretRedisProviderForm.tsx +++ b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretRedisProviderForm.tsx @@ -14,24 +14,55 @@ import { FormControl, Input, SecretInput, + Select, + SelectItem, TextArea } from "@app/components/v2"; import { useUpdateDynamicSecret } from "@app/hooks/api"; -import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types"; +import { RedisProviders, TDynamicSecret } from "@app/hooks/api/dynamicSecret/types"; const formSchema = z.object({ inputs: z .object({ + client: z.nativeEnum(RedisProviders), host: z.string().toLowerCase().min(1), port: z.coerce.number(), - username: z.string().min(1), - password: z.string().min(1).optional(), + username: z.string().min(1), // In case of Elasticache, this is accessKeyId + password: z.string().min(1).optional(), // In case of Elasticache, this is secretAccessKey + + elastiCacheIamUsername: z.string().trim().optional(), + elastiCacheRegion: z.string().trim().optional(), + creationStatement: z.string().min(1), renewStatement: z.string().optional(), revocationStatement: z.string().min(1), ca: z.string().optional() }) - .partial(), + .partial() + .refine( + (data) => { + if (data.client === RedisProviders.Elasticache) { + return !!data.elastiCacheIamUsername; + } + return true; + }, + { + message: "elastiCacheIamUsername is required when client is ElastiCache", + path: ["elastiCacheIamUsername"] + } + ) + .refine( + (data) => { + if (data.client === RedisProviders.Elasticache) { + return !!data.elastiCacheRegion; + } + return true; + }, + { + message: "AWS region is required when using ElastiCache", + path: ["elastiCacheRegion"] + } + ), defaultTTL: z.string().superRefine((val, ctx) => { const valMs = ms(val); if (valMs < 60 * 1000) @@ -78,7 +109,8 @@ export const EditDynamicSecretRedisProviderForm = ({ const { control, formState: { isSubmitting }, - handleSubmit + handleSubmit, + watch } = useForm({ resolver: zodResolver(formSchema), values: { @@ -122,6 +154,8 @@ export const EditDynamicSecretRedisProviderForm = ({ } }; + const selectedProvider = watch("inputs.client"); + return (
@@ -173,52 +207,90 @@ export const EditDynamicSecretRedisProviderForm = ({
-
Configuration
+
+ Configuration +
-
+
( - - - - )} - /> - ( - - field.onChange(parseInt(el.target.value, 10))} - /> - - )} - /> -
-
- ( + name="inputs.client" + defaultValue={RedisProviders.Redis} + render={({ field: { value, onChange }, fieldState: { error } }) => ( + + + )} + /> + {selectedProvider === RedisProviders.Elasticache && ( + ( + + + + )} + /> + )} +
+ ( + + + + )} + /> + ( + + + + )} + /> +
+ {selectedProvider === RedisProviders.Elasticache && ( +
+ ( + @@ -226,107 +298,132 @@ export const EditDynamicSecretRedisProviderForm = ({ )} /> - ( - - - - )} - /> -
-
- ( - - - - )} - /> - - - Modify Redis Statements - - ( - -