fix: allow empty secret names

This commit is contained in:
Daniel Hougaard
2025-09-23 02:59:12 +04:00
parent a722ac3522
commit 294f33bc1e
5 changed files with 46 additions and 5 deletions

View File

@@ -43,8 +43,6 @@ export const GenericResourceNameSchema = z
export const BaseSecretNameSchema = z.string().trim().min(1); export const BaseSecretNameSchema = z.string().trim().min(1);
export const SecretNameSchema = BaseSecretNameSchema.refine( export const SecretNameSchema = BaseSecretNameSchema.refine(
(el) => !el.includes(" "), (el) => !el.includes(":"),
"Secret name cannot contain spaces." "Secret name cannot contain colon."
) ).refine((el) => !el.includes("/"), "Secret name cannot contain forward slash.");
.refine((el) => !el.includes(":"), "Secret name cannot contain colon.")
.refine((el) => !el.includes("/"), "Secret name cannot contain forward slash.");

View File

@@ -1,6 +1,9 @@
import { ChangeEvent, forwardRef, InputHTMLAttributes, ReactNode } from "react"; import { ChangeEvent, forwardRef, InputHTMLAttributes, ReactNode } from "react";
import { cva, VariantProps } from "cva"; import { cva, VariantProps } from "cva";
import { twMerge } from "tailwind-merge"; import { twMerge } from "tailwind-merge";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faWarning } from "@fortawesome/free-solid-svg-icons";
import { Tooltip } from "../Tooltip";
type Props = { type Props = {
placeholder?: string; placeholder?: string;
@@ -12,6 +15,7 @@ type Props = {
isReadOnly?: boolean; isReadOnly?: boolean;
autoCapitalization?: boolean; autoCapitalization?: boolean;
containerClassName?: string; containerClassName?: string;
warningMessage?: string | ReactNode;
}; };
const inputVariants = cva( const inputVariants = cva(
@@ -84,6 +88,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
size = "md", size = "md",
isReadOnly, isReadOnly,
autoCapitalization, autoCapitalization,
warningMessage,
...props ...props
}, },
ref ref
@@ -120,6 +125,11 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(
inputVariants({ className, isError, size, isRounded, variant }) inputVariants({ className, isError, size, isRounded, variant })
)} )}
/> />
{warningMessage && !rightIcon && (
<Tooltip className="w-full max-w-64" content={warningMessage}>
<FontAwesomeIcon icon={faWarning} className="absolute right-0 mr-3 text-yellow-500" />
</Tooltip>
)}
{rightIcon && <span className="absolute right-0 mr-3">{rightIcon}</span>} {rightIcon && <span className="absolute right-0 mr-3">{rightIcon}</span>}
</div> </div>
); );

View File

@@ -217,6 +217,17 @@ export const CreateSecretForm = ({ secretPath = "/", onClose }: Props) => {
// @ts-expect-error this is for multiple ref single component // @ts-expect-error this is for multiple ref single component
secretKeyInputRef.current = e; secretKeyInputRef.current = e;
}} }}
warningMessage={
secretKey?.includes(" ") ? (
<div>
Secret key contains whitespaces.
<br />
<br /> If this is the desired format, you need to encode it with{" "}
<code className="rounded-md bg-mineshaft-500 px-1 py-0.5">%20</code> when making API
requests.
</div>
) : undefined
}
placeholder="Type your secret name" placeholder="Type your secret name"
onPaste={handlePaste} onPaste={handlePaste}
autoCapitalization={currentProject?.autoCapitalization} autoCapitalization={currentProject?.autoCapitalization}

View File

@@ -178,6 +178,17 @@ export const CreateSecretForm = ({
// @ts-expect-error this is for multiple ref single component // @ts-expect-error this is for multiple ref single component
secretKeyInputRef.current = e; secretKeyInputRef.current = e;
}} }}
warningMessage={
secretKey?.includes(" ") ? (
<div>
Secret key contains whitespaces.
<br />
<br /> If this is the desired format, you need to encode it with{" "}
<code className="rounded-md bg-mineshaft-500 px-1 py-0.5">%20</code> when making API
requests.
</div>
) : undefined
}
placeholder="Type your secret name" placeholder="Type your secret name"
onPaste={handlePaste} onPaste={handlePaste}
autoCapitalization={autoCapitalize} autoCapitalization={autoCapitalize}

View File

@@ -487,6 +487,17 @@ export const SecretItem = memo(
placeholder={error?.message} placeholder={error?.message}
isError={Boolean(error)} isError={Boolean(error)}
onKeyUp={() => trigger("key")} onKeyUp={() => trigger("key")}
warningMessage={
field.value.includes(" ") ? (
<div>
Secret key contains whitespaces.
<br />
<br /> If this is the desired format, you need to encode it with{" "}
<code className="rounded-md bg-mineshaft-500 px-1 py-0.5">%20</code> when
making API requests.
</div>
) : undefined
}
{...field} {...field}
className="w-full px-0 placeholder:text-red-500 focus:text-bunker-100 focus:ring-transparent" className="w-full px-0 placeholder:text-red-500 focus:text-bunker-100 focus:ring-transparent"
/> />