Add a config field to configure entity validation

This adds a new config field that can be used to configure entity
validation. It defaults to false to ensure backwards compatibility.
It is not permitted when catalog paths contain wildcards, due to
limitations with how the GraphQL query will work.

Signed-off-by: Nikolas Skoufis <nskoufis@seek.com.au>
This commit is contained in:
Nikolas Skoufis
2022-10-10 16:32:19 +11:00
parent 1d51703169
commit 1416e69de9
2 changed files with 49 additions and 0 deletions
@@ -101,6 +101,7 @@ describe('readProviderConfigs', () => {
exclude: undefined,
},
},
validateLocationsExist: false,
});
expect(providerConfigs[1]).toEqual({
id: 'providerCustomCatalogPath',
@@ -115,6 +116,7 @@ describe('readProviderConfigs', () => {
exclude: undefined,
},
},
validateLocationsExist: false,
});
expect(providerConfigs[2]).toEqual({
id: 'providerWithRepositoryFilter',
@@ -129,6 +131,7 @@ describe('readProviderConfigs', () => {
exclude: undefined,
},
},
validateLocationsExist: false,
});
expect(providerConfigs[3]).toEqual({
id: 'providerWithBranchFilter',
@@ -143,6 +146,7 @@ describe('readProviderConfigs', () => {
exclude: undefined,
},
},
validateLocationsExist: false,
});
expect(providerConfigs[4]).toEqual({
id: 'providerWithTopicFilter',
@@ -157,6 +161,7 @@ describe('readProviderConfigs', () => {
exclude: ['backstage-exclude'],
},
},
validateLocationsExist: false,
});
expect(providerConfigs[5]).toEqual({
id: 'providerWithHost',
@@ -171,6 +176,38 @@ describe('readProviderConfigs', () => {
exclude: undefined,
},
},
validateLocationsExist: false,
});
});
it('defaults validateLocationsExist to false', () => {
const config = new ConfigReader({
catalog: {
providers: {
github: {
organization: 'test-org',
},
},
},
});
const providerConfigs = readProviderConfigs(config);
expect(providerConfigs[0].validateLocationsExist).toEqual(false);
});
it('throws an error when a wildcard catalog path is configured with validation of locations', () => {
const config = new ConfigReader({
catalog: {
providers: {
github: {
organization: 'test-org',
validateLocationsExist: true,
catalogPath: '/*/catalog-info.yaml',
},
},
},
});
expect(() => readProviderConfigs(config)).toThrow();
});
});
@@ -29,6 +29,7 @@ export type GitHubEntityProviderConfig = {
branch?: string;
topic?: GithubTopicFilters;
};
validateLocationsExist: boolean;
};
export type GithubTopicFilters = {
@@ -72,6 +73,16 @@ function readProviderConfig(
const topicFilterExclude = config?.getOptionalStringArray(
'filters.topic.exclude',
);
const validateLocationsExist =
config?.getOptionalBoolean('validateLocationsExist') ?? false;
const catalogPathContainsWildcard = catalogPath.includes('*');
if (validateLocationsExist && catalogPathContainsWildcard) {
throw Error(
`Error while processing GitHub provider config. The catalog path ${catalogPath} contains a wildcard, which is incompatible with validation of locations existing before emitting them. Ensure that validateLocationsExist is set to false.`,
);
}
return {
id,
@@ -88,6 +99,7 @@ function readProviderConfig(
exclude: topicFilterExclude,
},
},
validateLocationsExist,
};
}
/**