Merge pull request #3431 from bluewave-labs/fix/infra-services
fix: infra services
This commit is contained in:
3 files changed
+12
-8
No files matched your search
@@ -24,7 +24,7 @@ class MaintenanceWindowController {
|
|||||||
|
|
||||||
const monitorIDs = validatedBody.monitors;
|
const monitorIDs = validatedBody.monitors;
|
||||||
const name = validatedBody.name;
|
const name = validatedBody.name;
|
||||||
const active = validatedBody.active ? validatedBody.active : true;
|
const active = validatedBody.active ?? true;
|
||||||
const duration = validatedBody.duration;
|
const duration = validatedBody.duration;
|
||||||
const durationUnit = validatedBody.durationUnit;
|
const durationUnit = validatedBody.durationUnit;
|
||||||
const repeat = validatedBody.repeat;
|
const repeat = validatedBody.repeat;
|
||||||
|
|||||||
@@ -2,7 +2,11 @@ import { Monitor } from "@/types/monitor.js";
|
|||||||
import jmespath from "jmespath";
|
import jmespath from "jmespath";
|
||||||
type JmesPath = typeof jmespath;
|
type JmesPath = typeof jmespath;
|
||||||
|
|
||||||
export class AdvancedMatcher {
|
export interface IAdvancedMatcher {
|
||||||
|
validate<T>(payload: T, monitor: Monitor): { ok: boolean; message: string; extracted?: T | undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
export class AdvancedMatcher implements IAdvancedMatcher {
|
||||||
constructor(private jmespath: JmesPath) {}
|
constructor(private jmespath: JmesPath) {}
|
||||||
|
|
||||||
private compare(actual: unknown, expected: string, method?: string): boolean {
|
private compare(actual: unknown, expected: string, method?: string): boolean {
|
||||||
@@ -12,7 +16,7 @@ export class AdvancedMatcher {
|
|||||||
return String(actual) === expected; // Default
|
return String(actual) === expected; // Default
|
||||||
}
|
}
|
||||||
|
|
||||||
validate<T>(payload: T, monitor: Monitor): { ok: boolean; message: string; extracted?: any } {
|
validate<T>(payload: T, monitor: Monitor): { ok: boolean; message: string; extracted?: T | undefined } {
|
||||||
const { useAdvancedMatching, jsonPath, matchMethod, expectedValue } = monitor;
|
const { useAdvancedMatching, jsonPath, matchMethod, expectedValue } = monitor;
|
||||||
if (!useAdvancedMatching) return { ok: true, message: "Success" };
|
if (!useAdvancedMatching) return { ok: true, message: "Success" };
|
||||||
|
|
||||||
@@ -35,10 +39,10 @@ export class AdvancedMatcher {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const isFalsey = dataToValidate === false || dataToValidate === "false" || dataToValidate === undefined || dataToValidate === null;
|
const isFalsy = dataToValidate === false || dataToValidate === "false" || dataToValidate === undefined || dataToValidate === null;
|
||||||
return {
|
return {
|
||||||
ok: !isFalsey,
|
ok: !isFalsy,
|
||||||
message: !isFalsey ? "Success" : "Extracted value is falsey",
|
message: !isFalsy ? "Success" : "Extracted value is falsy",
|
||||||
extracted: dataToValidate,
|
extracted: dataToValidate,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { type Got, HTTPError, RequestError } from "got";
|
import { type Got, HTTPError, RequestError } from "got";
|
||||||
import { AdvancedMatcher } from "@/service/infrastructure/network/AdvancedMatcher.js";
|
import { IAdvancedMatcher } from "@/service/infrastructure/network/AdvancedMatcher.js";
|
||||||
import { IStatusProvider } from "@/service/infrastructure/network/IStatusProvider.js";
|
import { IStatusProvider } from "@/service/infrastructure/network/IStatusProvider.js";
|
||||||
import { HttpStatusPayload } from "@/types/network.js";
|
import { HttpStatusPayload } from "@/types/network.js";
|
||||||
import { MonitorStatusResponse } from "@/types/network.js";
|
import { MonitorStatusResponse } from "@/types/network.js";
|
||||||
@@ -13,7 +13,7 @@ export class HttpProvider implements IStatusProvider<HttpStatusPayload> {
|
|||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private got: Got,
|
private got: Got,
|
||||||
private advancedMatcher: AdvancedMatcher
|
private advancedMatcher: IAdvancedMatcher
|
||||||
) {
|
) {
|
||||||
const cacheable = new CacheableLookup({ maxTtl: 300, errorTtl: 30 });
|
const cacheable = new CacheableLookup({ maxTtl: 300, errorTtl: 30 });
|
||||||
this.got = got.extend({
|
this.got = got.extend({
|
||||||
|
|||||||
Reference in new issue
Block a user