misc: finalized httpsAgent usage

This commit is contained in:
Sheen Capadngan
2025-06-06 23:51:39 +08:00
parent 545df3bf28
commit 80fada6b55
3 changed files with 23 additions and 65 deletions
@@ -94,7 +94,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
const validateConnection = async (inputs: unknown) => { const validateConnection = async (inputs: unknown) => {
const providerInputs = await validateProviderInputs(inputs); const providerInputs = await validateProviderInputs(inputs);
const serviceAccountDynamicCallback = async (host: string, port: number) => { const serviceAccountDynamicCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) { if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) {
throw new Error("invalid callback"); throw new Error("invalid callback");
} }
@@ -121,10 +121,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
@@ -165,10 +162,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
@@ -190,10 +184,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
@@ -210,10 +201,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
} else { } else {
@@ -226,10 +214,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
}); });
} }
@@ -244,15 +229,12 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
}; };
const serviceAccountStaticCallback = async (host: string, port: number) => { const serviceAccountStaticCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Static) { if (providerInputs.credentialType !== KubernetesCredentialType.Static) {
throw new Error("invalid callback"); throw new Error("invalid callback");
} }
@@ -270,10 +252,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
}; };
@@ -344,7 +323,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}) => { }) => {
const providerInputs = await validateProviderInputs(inputs); const providerInputs = await validateProviderInputs(inputs);
const serviceAccountDynamicCallback = async (host: string, port: number) => { const serviceAccountDynamicCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) { if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) {
throw new Error("invalid callback"); throw new Error("invalid callback");
} }
@@ -371,10 +350,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
@@ -415,10 +391,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
@@ -440,17 +413,14 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
return { ...res.data, serviceAccountName }; return { ...res.data, serviceAccountName };
}; };
const tokenRequestStaticCallback = async (host: string, port: number) => { const tokenRequestStaticCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Static) { if (providerInputs.credentialType !== KubernetesCredentialType.Static) {
throw new Error("invalid callback"); throw new Error("invalid callback");
} }
@@ -474,10 +444,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
@@ -547,7 +514,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
const revoke = async (inputs: unknown, entityId: string) => { const revoke = async (inputs: unknown, entityId: string) => {
const providerInputs = await validateProviderInputs(inputs); const providerInputs = await validateProviderInputs(inputs);
const serviceAccountDynamicCallback = async (host: string, port: number) => { const serviceAccountDynamicCallback = async (host: string, port: number, httpsAgent?: https.Agent) => {
if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) { if (providerInputs.credentialType !== KubernetesCredentialType.Dynamic) {
throw new Error("invalid callback"); throw new Error("invalid callback");
} }
@@ -567,10 +534,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
} }
); );
} else { } else {
@@ -583,10 +547,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
}); });
} }
@@ -600,10 +561,7 @@ export const KubernetesProvider = ({ gatewayService }: TKubernetesProviderDTO):
}, },
signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT), signal: AbortSignal.timeout(EXTERNAL_REQUEST_TIMEOUT),
timeout: EXTERNAL_REQUEST_TIMEOUT, timeout: EXTERNAL_REQUEST_TIMEOUT,
httpsAgent: new https.Agent({ httpsAgent
ca: providerInputs.ca,
rejectUnauthorized: providerInputs.sslEnabled
})
}); });
}; };
@@ -122,7 +122,7 @@ const formSchema = z
ctx.addIssue({ ctx.addIssue({
path: ["provider.clusterToken"], path: ["provider.clusterToken"],
code: z.ZodIssueCode.custom, code: z.ZodIssueCode.custom,
message: "When auth method is set to Manual Token, a cluster token must be provided" message: "When auth method is set to Token, a cluster token must be provided"
}); });
} }
}); });
@@ -415,7 +415,7 @@ export const KubernetesInputForm = ({
className="w-full" className="w-full"
onValueChange={(e) => field.onChange(e)} onValueChange={(e) => field.onChange(e)}
> >
<SelectItem value={AuthMethod.Api}>Manual Token (API)</SelectItem> <SelectItem value={AuthMethod.Api}>Token (API)</SelectItem>
<SelectItem value={AuthMethod.Gateway}>Gateway</SelectItem> <SelectItem value={AuthMethod.Gateway}>Gateway</SelectItem>
</Select> </Select>
</FormControl> </FormControl>
@@ -119,7 +119,7 @@ const formSchema = z
ctx.addIssue({ ctx.addIssue({
path: ["inputs.clusterToken"], path: ["inputs.clusterToken"],
code: z.ZodIssueCode.custom, code: z.ZodIssueCode.custom,
message: "When auth method is set to Manual Token, a cluster token must be provided" message: "When auth method is set to Token, a cluster token must be provided"
}); });
} }
}); });
@@ -411,7 +411,7 @@ export const EditDynamicSecretKubernetesForm = ({
className="w-full" className="w-full"
onValueChange={(e) => field.onChange(e)} onValueChange={(e) => field.onChange(e)}
> >
<SelectItem value={AuthMethod.Api}>Manual Token (API)</SelectItem> <SelectItem value={AuthMethod.Api}>Token (API)</SelectItem>
<SelectItem value={AuthMethod.Gateway}>Gateway</SelectItem> <SelectItem value={AuthMethod.Gateway}>Gateway</SelectItem>
</Select> </Select>
</FormControl> </FormControl>