From 130c827e50086626d0b956ccaa4eca9ae4fd7e9a Mon Sep 17 00:00:00 2001 From: Marek Calus Date: Thu, 15 Oct 2020 19:26:25 +0200 Subject: [PATCH] Enable possibility of creating pending locations --- packages/catalog-model/src/location/types.ts | 3 +++ packages/catalog-model/src/location/validation.ts | 1 + .../src/ingestion/HigherOrderOperations.ts | 2 +- plugins/catalog/src/api/CatalogClient.ts | 8 ++++++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/catalog-model/src/location/types.ts b/packages/catalog-model/src/location/types.ts index 50e6e82a54..43a0d3c692 100644 --- a/packages/catalog-model/src/location/types.ts +++ b/packages/catalog-model/src/location/types.ts @@ -17,6 +17,9 @@ export type LocationSpec = { type: string; target: string; + // When using repo importer plugin, leocation is being created before the component yaml file is merged to the main branch. + // This flag is then set to disable validation that prevents creation of location if target file does not yet exist. + pendingLocation?: true; }; export type Location = { diff --git a/packages/catalog-model/src/location/validation.ts b/packages/catalog-model/src/location/validation.ts index 5fad47bdd0..adadd3b18f 100644 --- a/packages/catalog-model/src/location/validation.ts +++ b/packages/catalog-model/src/location/validation.ts @@ -21,6 +21,7 @@ export const locationSpecSchema = yup .object({ type: yup.string().required(), target: yup.string().required(), + pendingLocation: yup.bool().oneOf([true]), }) .noUnknown(); diff --git a/plugins/catalog-backend/src/ingestion/HigherOrderOperations.ts b/plugins/catalog-backend/src/ingestion/HigherOrderOperations.ts index 6df6d9b4b7..8da65dbd85 100644 --- a/plugins/catalog-backend/src/ingestion/HigherOrderOperations.ts +++ b/plugins/catalog-backend/src/ingestion/HigherOrderOperations.ts @@ -79,7 +79,7 @@ export class HigherOrderOperations implements HigherOrderOperation { // Read the location fully, bailing on any errors const readerOutput = await this.locationReader.read(spec); - if (readerOutput.errors.length) { + if (!spec.pendingLocation && readerOutput.errors.length) { const item = readerOutput.errors[0]; throw new InputError( `Failed to read location ${item.location.type}:${item.location.target}, ${item.error}`, diff --git a/plugins/catalog/src/api/CatalogClient.ts b/plugins/catalog/src/api/CatalogClient.ts index d5ff033caa..9ba0e56bc1 100644 --- a/plugins/catalog/src/api/CatalogClient.ts +++ b/plugins/catalog/src/api/CatalogClient.ts @@ -109,8 +109,12 @@ export class CatalogClient implements CatalogApi { const { location, entities } = await response.json(); - if (!location || entities.length === 0) - throw new Error(`Location wasn't added: ${target}`); + if (!location) throw new Error(`Location wasn't added: ${target}`); + + if (entities.length === 0) + throw new Error( + `Location was added but has no entities specified yet: ${target}`, + ); return { location,