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:
@@ -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.
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/config-loader': minor
|
||||
---
|
||||
|
||||
Added `ignoreSchemaErrors` to `schema.process`.
|
||||
@@ -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>();
|
||||
|
||||
@@ -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' }]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user