diff --git a/.changeset/popular-jars-serve.md b/.changeset/popular-jars-serve.md new file mode 100644 index 0000000000..6ee40195fc --- /dev/null +++ b/.changeset/popular-jars-serve.md @@ -0,0 +1,5 @@ +--- +'@backstage/catalog-model': minor +--- + +Enable adding locations for config files that does not yet exist by adding a flag to api request diff --git a/packages/catalog-model/src/location/types.ts b/packages/catalog-model/src/location/types.ts index 50e6e82a54..33e443e04f 100644 --- a/packages/catalog-model/src/location/types.ts +++ b/packages/catalog-model/src/location/types.ts @@ -17,6 +17,10 @@ export type LocationSpec = { type: string; target: string; + // When using repo importer plugin, location is being created before the component yaml file is merged to the main branch. + // This flag is then set to indicate that the file can be not present. + // default value: 'required'. + presence?: 'optional' | 'required'; }; export type Location = { diff --git a/packages/catalog-model/src/location/validation.ts b/packages/catalog-model/src/location/validation.ts index b1b91edd83..27d74b9a82 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(), + presence: yup.string(), }) .noUnknown() .required(); diff --git a/plugins/catalog-backend/src/ingestion/HigherOrderOperations.ts b/plugins/catalog-backend/src/ingestion/HigherOrderOperations.ts index 6df6d9b4b7..b1f4e40524 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.presence === 'optional') && 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..6b10541107 100644 --- a/plugins/catalog/src/api/CatalogClient.ts +++ b/plugins/catalog/src/api/CatalogClient.ts @@ -109,9 +109,15 @@ export class CatalogClient implements CatalogApi { const { location, entities } = await response.json(); - if (!location || entities.length === 0) + 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, entities,