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:
+37
@@ -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,
|
||||
};
|
||||
}
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user