From 8fdc5c54d5dd07fe58f11838c2f33dd592891190 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 --- .changeset/sixty-panthers-matter.md | 5 +++++ .../src/validators/kubernetes-schema/schemaLoader.ts | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .changeset/sixty-panthers-matter.md diff --git a/.changeset/sixty-panthers-matter.md b/.changeset/sixty-panthers-matter.md new file mode 100644 index 000000000..3ec181d55 --- /dev/null +++ b/.changeset/sixty-panthers-matter.md @@ -0,0 +1,5 @@ +--- +"@monokle/validation": patch +--- + +Add schema loader config 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};