Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(ui): added mysql dynamic secret

Akhil Mohan40a0691ccb07
diff --git a/frontend/src/hooks/api/dynamicSecret/types.ts b/frontend/src/hooks/api/dynamicSecret/types.ts
index b68ad33a10..cab17bda19 100644
--- a/frontend/src/hooks/api/dynamicSecret/types.ts
+++ b/frontend/src/hooks/api/dynamicSecret/types.ts
@@ -20,7 +20,8 @@ export enum DynamicSecretProviders {
}
export enum SqlProviders {
- Postgres = "postgres"
+ Postgres = "postgres",
+ MySql = "mysql2"
}
export type TDynamicSecretProvider = {
@@ -34,7 +35,7 @@ export type TDynamicSecretProvider = {
password: string;
creationStatement: string;
revocationStatement: string;
- renewStatement: string;
+ renewStatement?: string;
ca?: string | undefined;
};
};
diff --git a/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx b/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx
index 674b25dd03..1893276b03 100644
--- a/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx
+++ b/frontend/src/views/SecretMainPage/components/ActionBar/CreateDynamicSecretForm/SqlDatabaseInputForm.tsx
@@ -31,7 +31,7 @@ const formSchema = z.object({
password: z.string().min(1),
creationStatement: z.string().min(1),
revocationStatement: z.string().min(1),
- renewStatement: z.string().min(1),
+ renewStatement: z.string().optional(),
ca: z.string().optional()
}),
defaultTTL: z.string().superRefine((val, ctx) => {
@@ -66,6 +66,26 @@ type Props = {
environment: string;
};
+const getSqlStatements = (provider: SqlProviders) => {
+ if (provider === SqlProviders.MySql) {
+ return {
+ creationStatement:
+ "CREATE USER \"{{username}}\"@'%' IDENTIFIED BY '{{password}}' PASSWORD EXPIRE;\nGRANT ALL ON \"{{database}}\".* TO \"{{username}}\"@'%';",
+ renewStatement: "",
+ revocationStatement:
+ 'REVOKE ALL PRIVILEGES ON "{{database}}".* FROM "{{username}}"@\'%\';\nDROP USER "{{username}}"@\'%\';'
+ };
+ }
+
+ return {
+ creationStatement:
+ "CREATE USER \"{{username}}\" WITH ENCRYPTED PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';\nGRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO \"{{username}}\";",
+ renewStatement: "ALTER ROLE \"{{username}}\" VALID UNTIL '{{expiration}}';",
+ revocationStatement:
+ 'REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM "{{username}}";\nDROP ROLE "{{username}}";'
+ };
+};
+
export const SqlDatabaseInputForm = ({
onCompleted,
onCancel,
@@ -75,18 +95,13 @@ export const SqlDatabaseInputForm = ({
}: Props) => {
const {
control,
+ setValue,
formState: { isSubmitting },
handleSubmit
} = useForm<TForm>({
resolver: zodResolver(formSchema),
defaultValues: {
- provider: {
- creationStatement:
- "CREATE USER \"{{username}}\" WITH ENCRYPTED PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';\nGRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA public TO \"{{username}}\";",
- renewStatement: "ALTER ROLE \"{{username}}\" VALID UNTIL '{{expiration}}';",
- revocationStatement:
- 'REVOKE ALL PRIVILEGES ON ALL TABLES IN SCHEMA public FROM "{{username}}";\nDROP ROLE "{{username}}";'
- }
+ provider: getSqlStatements(SqlProviders.Postgres)
}
});
@@ -182,10 +197,17 @@ export const SqlDatabaseInputForm = ({
<FormControl isError={Boolean(error?.message)} errorText={error?.message}>
<Select
value={value}
- onValueChange={(val) => onChange(val)}
+ onValueChange={(val) => {
+ onChange(val);
+ const sqlStatment = getSqlStatements(val as SqlProviders);
+ setValue("provider.creationStatement", sqlStatment.creationStatement);
+ setValue("provider.renewStatement", sqlStatment.renewStatement);
+ setValue("provider.revocationStatement", sqlStatment.revocationStatement);
+ }}
className="w-full border border-mineshaft-500"
>
<SelectItem value={SqlProviders.Postgres}>PostgreSQL</SelectItem>
+ <SelectItem value={SqlProviders.MySql}>MySQL</SelectItem>
</Select>
</FormControl>
)}
diff --git a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSqlProviderForm.tsx b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSqlProviderForm.tsx
index 691d73779f..4b4a2088f3 100644
--- a/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSqlProviderForm.tsx
+++ b/frontend/src/views/SecretMainPage/components/DynamicSecretListView/EditDynamicSecretForm/EditDynamicSecretSqlProviderForm.tsx
@@ -32,7 +32,7 @@ const formSchema = z.object({
password: z.string().min(1),
creationStatement: z.string().min(1),
revocationStatement: z.string().min(1),
- renewStatement: z.string().min(1),
+ renewStatement: z.string().optional(),
ca: z.string().optional()
})
.partial(),
@@ -94,7 +94,7 @@ export const EditDynamicSecretSqlProviderForm = ({
}
}
});
-
+
const updateDynamicSecret = useUpdateDynamicSecret();
const handleUpdateDynamicSecret = async ({ inputs, maxTTL, defaultTTL, newName }: TForm) => {
@@ -186,11 +186,13 @@ export const EditDynamicSecretSqlProviderForm = ({
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl isError={Boolean(error?.message)} errorText={error?.message}>
<Select
+ isDisabled
value={value}
onValueChange={(val) => onChange(val)}
className="w-full border border-mineshaft-500"
>
<SelectItem value={SqlProviders.Postgres}>PostgreSQL</SelectItem>
+ <SelectItem value={SqlProviders.MySql}>MySQL</SelectItem>
</Select>
</FormControl>
)}
@@ -221,7 +223,11 @@ export const EditDynamicSecretSqlProviderForm = ({
isError={Boolean(error?.message)}
errorText={error?.message}
>
- <Input {...field} type="number" onChange={(el) => field.onChange(parseInt(el.target.value, 10))} />
+ <Input
+ {...field}
+ type="number"
+ onChange={(el) => field.onChange(parseInt(el.target.value, 10))}
+ />
</FormControl>
)}
/>