feat(web-probe): add semantic YAML origins
This commit is contained in:
@@ -127,19 +127,28 @@ export interface HwlabRuntimeWebProbeServiceOriginSpec {
|
||||
readonly namespace: string;
|
||||
readonly port: number;
|
||||
readonly scheme: "http" | "https";
|
||||
readonly browserProxyMode?: "auto" | "direct";
|
||||
}
|
||||
|
||||
export interface HwlabRuntimeWebProbePublicOriginSpec {
|
||||
readonly mode: "public";
|
||||
readonly baseUrl?: string;
|
||||
readonly browserProxyMode?: "auto" | "direct";
|
||||
}
|
||||
|
||||
export type HwlabRuntimeWebProbeOriginSpec = HwlabRuntimeWebProbeServiceOriginSpec | HwlabRuntimeWebProbePublicOriginSpec;
|
||||
export type HwlabRuntimeWebProbeOriginName = "internal" | "public";
|
||||
|
||||
export interface HwlabRuntimeWebProbeOriginsSpec {
|
||||
readonly internal: HwlabRuntimeWebProbeServiceOriginSpec;
|
||||
readonly public: HwlabRuntimeWebProbePublicOriginSpec;
|
||||
}
|
||||
|
||||
export interface HwlabRuntimeWebProbeSpec {
|
||||
readonly browserProxyMode?: "auto" | "direct";
|
||||
readonly playwrightBrowsersPath?: string;
|
||||
readonly defaultOrigin?: HwlabRuntimeWebProbeOriginSpec;
|
||||
readonly defaultOrigin?: HwlabRuntimeWebProbeOriginName;
|
||||
readonly origins?: HwlabRuntimeWebProbeOriginsSpec;
|
||||
readonly authLogin?: HwlabRuntimeWebProbeAuthLoginSpec;
|
||||
readonly alertThresholds?: HwlabRuntimeWebProbeAlertThresholdsSpec;
|
||||
readonly browserFreezePolicy?: HwlabRuntimeWebProbeBrowserFreezePolicySpec;
|
||||
@@ -1267,10 +1276,23 @@ function webProbeConfig(value: unknown, path: string): HwlabRuntimeWebProbeSpec
|
||||
browserProxyMode = rawBrowserProxyMode;
|
||||
}
|
||||
const playwrightBrowsersPath = optionalStringField(raw, "playwrightBrowsersPath", path);
|
||||
const defaultOriginRaw = optionalStringField(raw, "defaultOrigin", path);
|
||||
let defaultOrigin: HwlabRuntimeWebProbeOriginName | undefined;
|
||||
if (defaultOriginRaw !== undefined) {
|
||||
if (defaultOriginRaw !== "internal" && defaultOriginRaw !== "public") {
|
||||
throw new Error(`${path}.defaultOrigin must be internal or public`);
|
||||
}
|
||||
defaultOrigin = defaultOriginRaw;
|
||||
}
|
||||
const origins = raw.origins === undefined ? undefined : webProbeOriginsConfig(raw.origins, `${path}.origins`);
|
||||
if (defaultOrigin !== undefined && origins === undefined) {
|
||||
throw new Error(`${path}.origins must declare internal and public when defaultOrigin is set`);
|
||||
}
|
||||
return {
|
||||
...(browserProxyMode === undefined ? {} : { browserProxyMode }),
|
||||
...(playwrightBrowsersPath === undefined ? {} : { playwrightBrowsersPath }),
|
||||
...(raw.defaultOrigin === undefined ? {} : { defaultOrigin: webProbeOriginConfig(raw.defaultOrigin, `${path}.defaultOrigin`) }),
|
||||
...(defaultOrigin === undefined ? {} : { defaultOrigin }),
|
||||
...(origins === undefined ? {} : { origins }),
|
||||
...(raw.authLogin === undefined ? {} : { authLogin: webProbeAuthLoginConfig(raw.authLogin, `${path}.authLogin`) }),
|
||||
...(raw.alertThresholds === undefined ? {} : { alertThresholds: webProbeAlertThresholdsConfig(raw.alertThresholds, `${path}.alertThresholds`) }),
|
||||
...(raw.browserFreezePolicy === undefined ? {} : { browserFreezePolicy: webProbeBrowserFreezePolicyConfig(raw.browserFreezePolicy, `${path}.browserFreezePolicy`) }),
|
||||
@@ -1279,6 +1301,18 @@ function webProbeConfig(value: unknown, path: string): HwlabRuntimeWebProbeSpec
|
||||
};
|
||||
}
|
||||
|
||||
function webProbeOriginsConfig(value: unknown, path: string): HwlabRuntimeWebProbeOriginsSpec {
|
||||
const raw = asRecord(value, path);
|
||||
for (const key of Object.keys(raw)) {
|
||||
if (key !== "internal" && key !== "public") throw new Error(`${path}.${key} is not a supported web-probe origin`);
|
||||
}
|
||||
const internal = webProbeOriginConfig(raw.internal, `${path}.internal`);
|
||||
const publicOrigin = webProbeOriginConfig(raw.public, `${path}.public`);
|
||||
if (internal.mode !== "k8s-service-cluster-ip") throw new Error(`${path}.internal.mode must be k8s-service-cluster-ip`);
|
||||
if (publicOrigin.mode !== "public") throw new Error(`${path}.public.mode must be public`);
|
||||
return { internal, public: publicOrigin };
|
||||
}
|
||||
|
||||
function webProbeRealtimeFanoutProfilesConfig(value: unknown, path: string): Readonly<Record<string, HwlabRuntimeWebProbeRealtimeFanoutProfileSpec>> {
|
||||
const raw = asRecord(value, path);
|
||||
const entries = Object.entries(raw).map(([id, item]) => {
|
||||
@@ -1510,10 +1544,19 @@ function webProbeAlertThresholdsConfig(value: unknown, path: string): HwlabRunti
|
||||
function webProbeOriginConfig(value: unknown, path: string): HwlabRuntimeWebProbeOriginSpec {
|
||||
const raw = asRecord(value, path);
|
||||
const mode = stringField(raw, "mode", path);
|
||||
const browserProxyModeRaw = optionalStringField(raw, "browserProxyMode", path);
|
||||
let browserProxyMode: "auto" | "direct" | undefined;
|
||||
if (browserProxyModeRaw !== undefined) {
|
||||
if (browserProxyModeRaw !== "auto" && browserProxyModeRaw !== "direct") {
|
||||
throw new Error(`${path}.browserProxyMode must be auto or direct`);
|
||||
}
|
||||
browserProxyMode = browserProxyModeRaw;
|
||||
}
|
||||
if (mode === "public") {
|
||||
return {
|
||||
mode,
|
||||
...(raw.baseUrl === undefined ? {} : { baseUrl: stringField(raw, "baseUrl", path).replace(/\/+$/u, "") }),
|
||||
...(browserProxyMode === undefined ? {} : { browserProxyMode }),
|
||||
};
|
||||
}
|
||||
if (mode !== "k8s-service-cluster-ip") throw new Error(`${path}.mode must be public or k8s-service-cluster-ip`);
|
||||
@@ -1525,6 +1568,7 @@ function webProbeOriginConfig(value: unknown, path: string): HwlabRuntimeWebProb
|
||||
namespace: stringField(raw, "namespace", path),
|
||||
port: numberField(raw, "port", path),
|
||||
scheme,
|
||||
...(browserProxyMode === undefined ? {} : { browserProxyMode }),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user