From e68a4ed5e929a473d2d1c2cef0234ab6d30f903a Mon Sep 17 00:00:00 2001 From: Delnat Wito Date: Tue, 21 Nov 2023 10:50:02 +0100 Subject: [PATCH] feat: add schema loader config --- .../src/validators/kubernetes-schema/schemaLoader.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/validation/src/validators/kubernetes-schema/schemaLoader.ts b/packages/validation/src/validators/kubernetes-schema/schemaLoader.ts index 57364dc6c..a42d791bc 100644 --- a/packages/validation/src/validators/kubernetes-schema/schemaLoader.ts +++ b/packages/validation/src/validators/kubernetes-schema/schemaLoader.ts @@ -4,12 +4,13 @@ import {isKnownResourceKind} from '../../utils/knownResourceKinds.js'; export type FullSchema = {definitions: Record}; export type ResourceSchema = any; -const CORE_SCHEMA_BASE = 'https://plugins.monokle.com/schemas'; -const CRD_SCHEMA_BASE = 'https://plugins.monokle.com/schemas'; +const BASE_URL = 'https://plugins.monokle.com/schemas'; export class SchemaLoader { private schemaCache = new Map(); + constructor(private baseUrl = BASE_URL) {} + async getResourceSchema( schemaVersion: string, resource: Resource | undefined, @@ -49,11 +50,11 @@ export class SchemaLoader { const kind = resource.kind.toLowerCase(); const [group, apiVersion] = resource.apiVersion.split('/'); // e.g. https://plugins.monokle.com/schemas/crds/argoproj.io/v1alpha1/application.json - return `${CRD_SCHEMA_BASE}/crds/${group}/${apiVersion}/${kind}.json`; + return `${this.baseUrl}/crds/${group}/${apiVersion}/${kind}.json`; } else { const kind = resource.kind.toLowerCase(); // e.g. https://plugins.monokle.com/schemas/v1.24.2-standalone/service.json - return `${CORE_SCHEMA_BASE}/${kubernetesVersion}-standalone/${kind}.json`; + return `${this.baseUrl}/${kubernetesVersion}-standalone/${kind}.json`; } } @@ -65,7 +66,7 @@ export class SchemaLoader { const cacheKey = schemaVersion; const cachedSchema = this.schemaCache.get(cacheKey); const kubernetesVersion = this.getKubernetesVersion(schemaVersion); - const schemaUri = `${CORE_SCHEMA_BASE}/${kubernetesVersion}-standalone/definitions.json`; + const schemaUri = `${this.baseUrl}/${kubernetesVersion}-standalone/definitions.json`; if (cachedSchema) { return {schema: cachedSchema, url: schemaUri};