misc: addressed comments

This commit is contained in:
Sheen Capadngan
2025-05-29 21:15:53 +08:00
parent 8cfaefcec5
commit 40711ac707
3 changed files with 18 additions and 10 deletions

View File

@@ -1,11 +1,12 @@
import axios from "axios";
import https from "https";
import { InternalServerError } from "@app/lib/errors";
import { withGatewayProxy } from "@app/lib/gateway";
import { blockLocalAndPrivateIpAddresses } from "@app/lib/validator";
import { TKubernetesTokenRequest } from "@app/services/identity-kubernetes-auth/identity-kubernetes-auth-types";
import { TGatewayServiceFactory } from "../../gateway/gateway-service";
import { verifyHostInputValidity } from "../dynamic-secret-fns";
import { DynamicSecretKubernetesSchema, TDynamicProviderFns } from "./models";
const EXTERNAL_REQUEST_TIMEOUT = 10 * 1000;
@@ -17,8 +18,11 @@ type TKubernetesProviderDTO = {
export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO): TDynamicProviderFns => {
const validateProviderInputs = async (inputs: unknown) => {
const providerInputs = await DynamicSecretKubernetesSchema.parseAsync(inputs);
const [hostIp] = await verifyHostInputValidity(providerInputs.url, Boolean(providerInputs.gatewayId));
return { ...providerInputs, hostIp };
if (!providerInputs.gatewayId) {
await blockLocalAndPrivateIpAddresses(providerInputs.url);
}
return providerInputs;
};
const $gatewayProxyWrapper = async <T>(
@@ -106,7 +110,9 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
errorMessage = (error.response?.data as { message: string }).message;
}
throw new Error(`Failed to validate connection: ${errorMessage}`);
throw new InternalServerError({
message: `Failed to validate connection: ${errorMessage}`
});
}
};
@@ -168,7 +174,9 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
errorMessage = (error.response?.data as { message: string }).message;
}
throw new Error(`Failed to validate connection: ${errorMessage}`);
throw new InternalServerError({
message: `Failed to create dynamic secret: ${errorMessage}`
});
}
};

View File

@@ -49,7 +49,7 @@ const formSchema = z.object({
url: z.string().url().trim().min(1),
clusterToken: z.string().trim().min(1),
ca: z.string().optional(),
sslEnabled: z.boolean().default(true),
sslEnabled: z.boolean().default(false),
credentialType: z.literal(CredentialType.Static),
serviceAccountName: z.string().trim().min(1),
namespace: z.string().trim().min(1),
@@ -109,7 +109,7 @@ export const KubernetesInputForm = ({
url: "",
clusterToken: "",
ca: "",
sslEnabled: true,
sslEnabled: false,
serviceAccountName: "",
namespace: "",
credentialType: CredentialType.Static,
@@ -284,7 +284,7 @@ export const KubernetesInputForm = ({
name="provider.url"
render={({ field, fieldState: { error } }) => (
<FormControl
label="URL"
label="Cluster URL"
isError={Boolean(error?.message)}
errorText={error?.message}
>

View File

@@ -47,7 +47,7 @@ const formSchema = z.object({
url: z.string().url().trim().min(1),
clusterToken: z.string().trim().min(1),
ca: z.string().optional(),
sslEnabled: z.boolean().default(true),
sslEnabled: z.boolean().default(false),
credentialType: z.literal(CredentialType.Static),
serviceAccountName: z.string().trim().min(1),
namespace: z.string().trim().min(1),
@@ -277,7 +277,7 @@ export const EditDynamicSecretKubernetesForm = ({
name="inputs.url"
render={({ field, fieldState: { error } }) => (
<FormControl
label="URL"
label="Cluster URL"
isError={Boolean(error?.message)}
errorText={error?.message}
>