Requested changes

This commit is contained in:
Daniel Hougaard
2024-09-04 13:47:35 +04:00
parent 18951b99de
commit b7c79fa45b
7 changed files with 201 additions and 196 deletions
@@ -122,9 +122,8 @@ export type TDynamicSecretProvider =
inputs: {
host: string;
port: number;
creationStatement: string;
revocationStatement: string;
ca?: string | undefined;
roles: string[];
auth:
| {
@@ -1,4 +1,7 @@
import { Controller, useForm } from "react-hook-form";
import Link from "next/link";
import { faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod";
import ms from "ms";
import { z } from "zod";
@@ -6,17 +9,14 @@ import { z } from "zod";
import { TtlFormLabel } from "@app/components/features";
import { createNotification } from "@app/components/notifications";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
Button,
FormControl,
FormLabel,
IconButton,
Input,
SecretInput,
Select,
SelectItem,
TextArea
SelectItem
} from "@app/components/v2";
import { useCreateDynamicSecret } from "@app/hooks/api";
import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";
@@ -51,8 +51,7 @@ const formSchema = z.object({
})
]),
creationStatement: z.string().trim(),
revocationStatement: z.string().trim(),
roles: z.array(z.string().trim().min(1)).min(1, "At least one role is required"),
ca: z.string().optional()
}),
defaultTTL: z.string().superRefine((val, ctx) => {
@@ -107,17 +106,8 @@ export const ElasticSearchInputForm = ({
auth: {
type: "user"
},
port: 443,
creationStatement: `{
"username": "{{username}}",
"password": "{{password}}",
"roles": ["superuser"],
"metadata": {}
}`,
revocationStatement: `{
"username": "{{username}}"
}`
roles: ["superuser"],
port: 443
}
}
});
@@ -147,6 +137,7 @@ export const ElasticSearchInputForm = ({
};
const selectedAuthType = watch("provider.auth.type");
const selectedRoles = watch("provider.roles");
return (
<div>
@@ -219,7 +210,10 @@ export const ElasticSearchInputForm = ({
isError={Boolean(error?.message)}
errorText={error?.message}
>
<Input {...field} />
<Input
placeholder="https://fgy543ws2w35dfh7jdaafa12ha.aws-us-east-1.io"
{...field}
/>
</FormControl>
)}
/>
@@ -314,6 +308,87 @@ export const ElasticSearchInputForm = ({
)}
/>
</div>
<div className="mb-3 flex flex-col">
<FormLabel
className="mb-2"
label="Roles"
tooltipText={
<div className="space-y-4">
<p>Select which role(s) to assign the users provisioned by Infisical.</p>
<p>
There is a wide range of in-built roles in Elastic Search. Some include,
superuser, apm_user, kibana_admin, monitoring_user, and many more. You can{" "}
<Link
passHref
href="https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-roles.html"
>
<a target="_blank" rel="noopener noreferrer">
<span className="cursor-pointer text-primary-400">
read more about roles here
</span>
</a>
</Link>
.
</p>
<p>
You can also assign custom roles by providing the name of the custom role in
the input field.
</p>
</div>
}
/>
<div className="flex flex-col -space-y-2">
{selectedRoles.map((_, i) => (
<Controller
control={control}
name={`provider.roles.${i}`}
// eslint-disable-next-line react/no-array-index-key
key={`role-${i}`}
render={({ field, fieldState: { error } }) => (
<FormControl isError={Boolean(error?.message)} errorText={error?.message}>
<div className="flex h-9 items-center gap-2">
<Input
placeholder="Insert role name, (superuser, kibana_admin, custom_role)"
className="mb-0 flex-grow"
{...field}
/>
<IconButton
isDisabled={selectedRoles.length === 1}
ariaLabel="delete key"
className="h-9"
variant="outline_bg"
onClick={() => {
if (selectedRoles && selectedRoles?.length > 1) {
setValue(
"provider.roles",
selectedRoles.filter((__, idx) => idx !== i)
);
}
}}
>
<FontAwesomeIcon icon={faTrash} />
</IconButton>
</div>
</FormControl>
)}
/>
))}
</div>
</div>
<div>
<Button
leftIcon={<FontAwesomeIcon icon={faPlus} />}
size="xs"
className="mb-3"
variant="outline_bg"
onClick={() => {
setValue("provider.roles", [...selectedRoles, ""]);
}}
>
Add Role
</Button>
</div>
<div>
<Controller
control={control}
@@ -332,51 +407,6 @@ export const ElasticSearchInputForm = ({
</FormControl>
)}
/>
<Accordion type="single" collapsible className="mb-2 w-full bg-mineshaft-700">
<AccordionItem value="advance-statements">
<AccordionTrigger>Modify ElasticSearch Statements</AccordionTrigger>
<AccordionContent>
<Controller
control={control}
name="provider.creationStatement"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Creation Statement"
isError={Boolean(error?.message)}
errorText={error?.message}
helperText="username, password and expiration are dynamically provisioned"
>
<TextArea
{...field}
reSize="none"
rows={3}
className="border-mineshaft-600 bg-mineshaft-900 text-sm"
/>
</FormControl>
)}
/>
<Controller
control={control}
name="provider.revocationStatement"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Revocation Statement"
isError={Boolean(error?.message)}
errorText={error?.message}
helperText="username is dynamically provisioned"
>
<TextArea
{...field}
reSize="none"
rows={3}
className="border-mineshaft-600 bg-mineshaft-900 text-sm"
/>
</FormControl>
)}
/>
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
</div>
</div>
@@ -1,4 +1,7 @@
import { Controller, useForm } from "react-hook-form";
import Link from "next/link";
import { faPlus, faTrash } from "@fortawesome/free-solid-svg-icons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { zodResolver } from "@hookform/resolvers/zod";
import ms from "ms";
import { z } from "zod";
@@ -6,17 +9,14 @@ import { z } from "zod";
import { TtlFormLabel } from "@app/components/features";
import { createNotification } from "@app/components/notifications";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
Button,
FormControl,
FormLabel,
IconButton,
Input,
SecretInput,
Select,
SelectItem,
TextArea
SelectItem
} from "@app/components/v2";
import { useUpdateDynamicSecret } from "@app/hooks/api";
import { TDynamicSecret } from "@app/hooks/api/dynamicSecret/types";
@@ -51,8 +51,7 @@ const formSchema = z.object({
})
]),
creationStatement: z.string().trim(),
revocationStatement: z.string().trim(),
roles: z.array(z.string().trim().min(1)).min(1, "At least one role is required"),
ca: z.string().optional()
}),
defaultTTL: z.string().superRefine((val, ctx) => {
@@ -147,6 +146,7 @@ export const EditDynamicSecretElasticSearchForm = ({
};
const selectedAuthType = watch("inputs.auth.type");
const selectedRoles = watch("inputs.roles");
return (
<div>
@@ -310,6 +310,89 @@ export const EditDynamicSecretElasticSearchForm = ({
)}
/>
</div>
<div className="relative mb-3 flex flex-col">
<FormLabel
label="Roles"
tooltipText={
<div className="space-y-4">
<p>Select which role(s) to assign the users provisioned by Infisical.</p>
<p>
There is a wide range of in-built roles in Elastic Search. Some include,
superuser, apm_user, kibana_admin, monitoring_user, and many more. You can{" "}
<Link
passHref
href="https://www.elastic.co/guide/en/elasticsearch/reference/current/built-in-roles.html"
>
<a target="_blank" rel="noopener noreferrer">
<span className="cursor-pointer text-primary-400">
read more about roles here
</span>
</a>
</Link>
.
</p>
<p>
You can also assign custom roles by providing the name of the custom role in
the input field.
</p>
</div>
}
/>
{selectedRoles.map((_, i) => (
<Controller
control={control}
name={`inputs.roles.${i}`}
// eslint-disable-next-line react/no-array-index-key
key={`role-${i}`}
render={({ field, fieldState: { error } }) => (
<div className="flex items-center gap-2">
<div className="flex-grow">
<FormControl isError={Boolean(error?.message)} errorText={error?.message}>
<Input
placeholder="Insert role name, (superuser, kibana_admin, custom_role)"
className="mb-0 flex-grow"
{...field}
/>
</FormControl>
</div>
<IconButton
isDisabled={selectedRoles.length === 1}
ariaLabel="delete key"
className="bottom-2 h-9"
variant="outline_bg"
onClick={() => {
if (selectedRoles && selectedRoles?.length > 1) {
setValue(
"inputs.roles",
selectedRoles.filter((__, idx) => idx !== i)
);
}
}}
>
<FontAwesomeIcon icon={faTrash} />
</IconButton>
</div>
)}
/>
))}
<div>
<Button
leftIcon={<FontAwesomeIcon icon={faPlus} />}
size="xs"
className="bottom-2"
variant="outline_bg"
onClick={() => {
setValue("inputs.roles", [...selectedRoles, ""]);
}}
>
Add Role
</Button>
</div>
</div>
<div>
<Controller
control={control}
@@ -328,51 +411,6 @@ export const EditDynamicSecretElasticSearchForm = ({
</FormControl>
)}
/>
<Accordion type="single" collapsible className="mb-2 w-full bg-mineshaft-700">
<AccordionItem value="advance-statements">
<AccordionTrigger>Modify ElasticSearch Statements</AccordionTrigger>
<AccordionContent>
<Controller
control={control}
name="inputs.creationStatement"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Creation Statement"
isError={Boolean(error?.message)}
errorText={error?.message}
helperText="username, password and expiration are dynamically provisioned"
>
<TextArea
{...field}
reSize="none"
rows={3}
className="border-mineshaft-600 bg-mineshaft-900 text-sm"
/>
</FormControl>
)}
/>
<Controller
control={control}
name="inputs.revocationStatement"
render={({ field, fieldState: { error } }) => (
<FormControl
label="Revocation Statement"
isError={Boolean(error?.message)}
errorText={error?.message}
helperText="username is dynamically provisioned"
>
<TextArea
{...field}
reSize="none"
rows={3}
className="border-mineshaft-600 bg-mineshaft-900 text-sm"
/>
</FormControl>
)}
/>
</AccordionContent>
</AccordionItem>
</Accordion>
</div>
</div>
</div>