config-loader,backend-common: do not fail backend startup on config schema errors

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-04-07 18:05:54 +02:00
parent 5454a0d34f
commit 19f6c6c32a
7 changed files with 41 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/backend-common': patch
---
The backend will no longer fail to start up when configured secrets do not match the configuration schema.
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/config-loader': minor
---
Added `ignoreSchemaErrors` to `schema.process`.
+1 -1
View File
@@ -41,7 +41,7 @@ const updateRedactionList = (
) => {
const secretAppConfigs = schema.process(configs, {
visibility: ['secret'],
withDeprecatedKeys: true,
ignoreSchemaErrors: true,
});
const secretConfig = ConfigReader.fromConfigs(secretAppConfigs);
const values = new Set<string>();
+1
View File
@@ -19,6 +19,7 @@ export type ConfigSchema = {
// @public
export type ConfigSchemaProcessingOptions = {
visibility?: ConfigVisibility[];
ignoreSchemaErrors?: boolean;
valueTransform?: TransformFunc<any>;
withFilteredKeys?: boolean;
withDeprecatedKeys?: boolean;
@@ -275,5 +275,12 @@ describe('loadConfigSchema', () => {
).toThrow(
"Config must have required property 'x a' { missingProperty=x a } at /other",
);
expect(
schema.process([{ data: { other: {} }, context: 'test' }], {
visibility: ['frontend'],
ignoreSchemaErrors: true,
}),
).toEqual([{ data: {}, context: 'test' }]);
});
});
+17 -9
View File
@@ -82,18 +82,26 @@ export async function loadConfigSchema(
return {
process(
configs: AppConfig[],
{ visibility, valueTransform, withFilteredKeys, withDeprecatedKeys } = {},
{
visibility,
valueTransform,
withFilteredKeys,
withDeprecatedKeys,
ignoreSchemaErrors,
} = {},
): AppConfig[] {
const result = validate(configs);
const visibleErrors = filterErrorsByVisibility(
result.errors,
visibility,
result.visibilityByDataPath,
result.visibilityBySchemaPath,
);
if (visibleErrors.length > 0) {
throw errorsToError(visibleErrors);
if (!ignoreSchemaErrors) {
const visibleErrors = filterErrorsByVisibility(
result.errors,
visibility,
result.visibilityByDataPath,
result.visibilityBySchemaPath,
);
if (visibleErrors.length > 0) {
throw errorsToError(visibleErrors);
}
}
let processedConfigs = configs;
@@ -117,6 +117,11 @@ export type ConfigSchemaProcessingOptions = {
*/
visibility?: ConfigVisibility[];
/**
* When set to `true`, any schema errors in the provided configuration will be ignored.
*/
ignoreSchemaErrors?: boolean;
/**
* A transform function that can be used to transform primitive configuration values
* during validation. The value returned from the transform function will be used