Fix review comment: don't use ConfigSchemaPackageEntry nor make it public.
Signed-off-by: David Festal <dfestal@redhat.com>
This commit is contained in:
@@ -9,7 +9,6 @@ import type { AppConfig } from '@backstage/config';
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { CacheClient } from '@backstage/backend-common';
|
||||
import { Config } from '@backstage/config';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import { CorsOptions } from 'cors';
|
||||
import { DiscoveryService } from '@backstage/backend-plugin-api';
|
||||
import { ErrorRequestHandler } from 'express';
|
||||
@@ -65,7 +64,9 @@ export const cacheServiceFactory: () => ServiceFactory<CacheClient, 'plugin'>;
|
||||
export function createConfigSecretEnumerator(options: {
|
||||
logger: LoggerService;
|
||||
dir?: string;
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: {
|
||||
[context: string]: JsonObject;
|
||||
};
|
||||
}): Promise<(config: Config) => Iterable<string>>;
|
||||
|
||||
// @public
|
||||
|
||||
@@ -23,19 +23,19 @@ import {
|
||||
loadConfig,
|
||||
ConfigTarget,
|
||||
LoadConfigOptionsRemote,
|
||||
ConfigSchemaPackageEntry,
|
||||
} from '@backstage/config-loader';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import type { Config, AppConfig } from '@backstage/config';
|
||||
import { getPackages } from '@manypkg/get-packages';
|
||||
import { ObservableConfigProxy } from './ObservableConfigProxy';
|
||||
import { isValidUrl } from '../lib/urls';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/** @public */
|
||||
export async function createConfigSecretEnumerator(options: {
|
||||
logger: LoggerService;
|
||||
dir?: string;
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: { [context: string]: JsonObject };
|
||||
}): Promise<(config: Config) => Iterable<string>> {
|
||||
const { logger, dir = process.cwd() } = options;
|
||||
const { packages } = await getPackages(dir);
|
||||
|
||||
+11
-17
@@ -22,15 +22,12 @@ import {
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { schemaDiscoveryServiceRef } from '@backstage/backend-plugin-api/alpha';
|
||||
import {
|
||||
ConfigSchemaPackageEntry,
|
||||
ConfigSources,
|
||||
StaticConfigSource,
|
||||
} from '@backstage/config-loader';
|
||||
import { ConfigSources, StaticConfigSource } from '@backstage/config-loader';
|
||||
import { transports } from 'winston';
|
||||
import { rootLifecycleServiceFactory } from '../rootLifecycle';
|
||||
import { lifecycleServiceFactory } from '../lifecycle';
|
||||
import { loggerServiceFactory } from '../logger';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
describe('rootLogger', () => {
|
||||
describe('rootLoggerServiceFactory', () => {
|
||||
@@ -46,20 +43,17 @@ describe('rootLogger', () => {
|
||||
},
|
||||
};
|
||||
|
||||
const additionalSchemas = [
|
||||
{
|
||||
path: 'test',
|
||||
value: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
secretValue: {
|
||||
type: 'string',
|
||||
visibility: 'secret',
|
||||
},
|
||||
const additionalSchemas = {
|
||||
test: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
secretValue: {
|
||||
type: 'string',
|
||||
visibility: 'secret',
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
const logs: string[] = [];
|
||||
jest
|
||||
@@ -97,7 +91,7 @@ describe('rootLogger', () => {
|
||||
},
|
||||
factory: async () => ({
|
||||
getAdditionalSchemas: async (): Promise<{
|
||||
schemas: Array<ConfigSchemaPackageEntry>;
|
||||
schemas: { [context: string]: JsonObject };
|
||||
}> => ({
|
||||
schemas: additionalSchemas,
|
||||
}),
|
||||
|
||||
@@ -20,7 +20,6 @@ import { CacheService as CacheClient } from '@backstage/backend-plugin-api';
|
||||
import { CacheServiceOptions as CacheClientOptions } from '@backstage/backend-plugin-api';
|
||||
import { CacheServiceSetOptions as CacheClientSetOptions } from '@backstage/backend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import cors from 'cors';
|
||||
import Docker from 'dockerode';
|
||||
import { ErrorRequestHandler } from 'express';
|
||||
@@ -33,6 +32,7 @@ import { GitLabIntegration } from '@backstage/integration';
|
||||
import { HostDiscovery as HostDiscovery_2 } from '@backstage/backend-app-api';
|
||||
import { IdentityService } from '@backstage/backend-plugin-api';
|
||||
import { isChildPath } from '@backstage/cli-common';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { Knex } from 'knex';
|
||||
import knexFactory from 'knex';
|
||||
import { KubeConfig } from '@kubernetes/client-node';
|
||||
@@ -561,7 +561,9 @@ export function loadBackendConfig(options: {
|
||||
logger: LoggerService;
|
||||
remote?: LoadConfigOptionsRemote;
|
||||
additionalConfigs?: AppConfig[];
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: {
|
||||
[context: string]: JsonObject;
|
||||
};
|
||||
argv: string[];
|
||||
watch?: boolean;
|
||||
}): Promise<Config>;
|
||||
|
||||
@@ -36,20 +36,17 @@ describe('config', () => {
|
||||
},
|
||||
];
|
||||
|
||||
const additionalSchemas = [
|
||||
{
|
||||
path: 'test',
|
||||
value: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
secretValue: {
|
||||
type: 'string',
|
||||
visibility: 'secret',
|
||||
},
|
||||
const additionalSchemas = {
|
||||
test: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
secretValue: {
|
||||
type: 'string',
|
||||
visibility: 'secret',
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
const logs: string[] = [];
|
||||
jest
|
||||
|
||||
@@ -20,11 +20,9 @@ import {
|
||||
} from '@backstage/backend-app-api';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { AppConfig, Config } from '@backstage/config';
|
||||
import {
|
||||
ConfigSchemaPackageEntry,
|
||||
LoadConfigOptionsRemote,
|
||||
} from '@backstage/config-loader';
|
||||
import { LoadConfigOptionsRemote } from '@backstage/config-loader';
|
||||
import { setRootLoggerRedactionList } from './logging/createRootLogger';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/**
|
||||
* Load configuration for a Backend.
|
||||
@@ -38,7 +36,7 @@ export async function loadBackendConfig(options: {
|
||||
// process.argv or any other overrides
|
||||
remote?: LoadConfigOptionsRemote;
|
||||
additionalConfigs?: AppConfig[];
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: { [context: string]: JsonObject };
|
||||
argv: string[];
|
||||
watch?: boolean;
|
||||
}): Promise<Config> {
|
||||
|
||||
@@ -28,9 +28,9 @@ import {
|
||||
createServiceFactory,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { schemaDiscoveryServiceRef } from '@backstage/backend-plugin-api/alpha';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import { findPaths } from '@backstage/cli-common';
|
||||
import { gatherDynamicPluginsSchemas } from './schemas';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
export interface DynamicPluginScannerOptions {
|
||||
config: Config;
|
||||
@@ -350,11 +350,11 @@ export const schemaDiscoveryServiceFactory = createServiceFactory(
|
||||
config: coreServices.rootConfig,
|
||||
},
|
||||
factory({ config }) {
|
||||
let schemas: ConfigSchemaPackageEntry[] | undefined;
|
||||
let schemas: { [context: string]: JsonObject } | undefined;
|
||||
|
||||
return {
|
||||
async getAdditionalSchemas(): Promise<{
|
||||
schemas: Array<ConfigSchemaPackageEntry>;
|
||||
schemas: { [context: string]: JsonObject };
|
||||
}> {
|
||||
if (schemas) {
|
||||
return {
|
||||
|
||||
@@ -15,20 +15,20 @@
|
||||
*/
|
||||
|
||||
import { ScannedPluginPackage } from '@backstage/backend-dynamic-feature-service';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
import * as url from 'url';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
export async function gatherDynamicPluginsSchemas(
|
||||
packages: ScannedPluginPackage[],
|
||||
logger: LoggerService,
|
||||
schemaLocator: (pluginPackage: ScannedPluginPackage) => string = () =>
|
||||
path.join('dist', 'configSchema.json'),
|
||||
): Promise<ConfigSchemaPackageEntry[]> {
|
||||
const allSchemas: { value: any; path: string }[] = [];
|
||||
): Promise<{ [context: string]: JsonObject }> {
|
||||
const allSchemas: { [context: string]: JsonObject } = {};
|
||||
|
||||
for (const pluginPackage of packages) {
|
||||
let schemaLocation = schemaLocator(pluginPackage);
|
||||
@@ -61,10 +61,7 @@ export async function gatherDynamicPluginsSchemas(
|
||||
continue;
|
||||
}
|
||||
|
||||
allSchemas.push({
|
||||
path: schemaLocation,
|
||||
value: serialized,
|
||||
});
|
||||
allSchemas[schemaLocation] = serialized;
|
||||
}
|
||||
|
||||
return allSchemas;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
```ts
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { ServiceRef } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @alpha (undocumented)
|
||||
@@ -25,7 +25,9 @@ export const featureDiscoveryServiceRef: ServiceRef<
|
||||
export interface SchemaDiscoveryService {
|
||||
// (undocumented)
|
||||
getAdditionalSchemas(): Promise<{
|
||||
schemas: Array<ConfigSchemaPackageEntry>;
|
||||
schemas: {
|
||||
[context: string]: JsonObject;
|
||||
};
|
||||
}>;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
createServiceFactory,
|
||||
createServiceRef,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/** @alpha */
|
||||
export interface FeatureDiscoveryService {
|
||||
@@ -39,7 +39,9 @@ export const featureDiscoveryServiceRef =
|
||||
|
||||
/** @alpha */
|
||||
export interface SchemaDiscoveryService {
|
||||
getAdditionalSchemas(): Promise<{ schemas: Array<ConfigSchemaPackageEntry> }>;
|
||||
getAdditionalSchemas(): Promise<{
|
||||
schemas: { [context: string]: JsonObject };
|
||||
}>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,7 +61,7 @@ export const schemaDiscoveryServiceRef =
|
||||
factory() {
|
||||
return {
|
||||
async getAdditionalSchemas() {
|
||||
return { schemas: [] };
|
||||
return { schemas: {} };
|
||||
},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -45,12 +45,6 @@ export type ConfigSchema = {
|
||||
serialize(): JsonObject;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type ConfigSchemaPackageEntry = {
|
||||
value: JsonObject;
|
||||
path: string;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type ConfigSchemaProcessingOptions = {
|
||||
visibility?: ConfigVisibility[];
|
||||
@@ -199,7 +193,9 @@ export type LoadConfigSchemaOptions = (
|
||||
}
|
||||
) & {
|
||||
noUndeclaredProperties?: boolean;
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: {
|
||||
[context: string]: JsonObject;
|
||||
};
|
||||
};
|
||||
|
||||
// @public
|
||||
|
||||
@@ -27,7 +27,6 @@ export type {
|
||||
ConfigVisibility,
|
||||
LoadConfigSchemaOptions,
|
||||
TransformFunc,
|
||||
ConfigSchemaPackageEntry,
|
||||
} from './schema';
|
||||
export { loadConfig } from './loader';
|
||||
export type {
|
||||
|
||||
@@ -142,17 +142,14 @@ describe('loadConfigSchema', () => {
|
||||
},
|
||||
],
|
||||
},
|
||||
additionalSchemas: [
|
||||
{
|
||||
path: 'additionalSchema',
|
||||
value: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
additionalKey: { type: 'string', visibility: 'frontend' },
|
||||
},
|
||||
additionalSchemas: {
|
||||
additionalSchema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
additionalKey: { type: 'string', visibility: 'frontend' },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
expect(schema.serialize()).toEqual({
|
||||
|
||||
@@ -43,7 +43,7 @@ export type LoadConfigSchemaOptions =
|
||||
}
|
||||
) & {
|
||||
noUndeclaredProperties?: boolean;
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: { [context: string]: JsonObject };
|
||||
};
|
||||
|
||||
function errorsToError(errors: ValidationError[]): Error {
|
||||
@@ -84,7 +84,16 @@ export async function loadConfigSchema(
|
||||
}
|
||||
schemas = serialized.schemas as ConfigSchemaPackageEntry[];
|
||||
}
|
||||
schemas.push(...(options.additionalSchemas || []));
|
||||
if (options.additionalSchemas) {
|
||||
schemas.push(
|
||||
...Object.keys(options.additionalSchemas).map(context => {
|
||||
return {
|
||||
path: context,
|
||||
value: options.additionalSchemas![context],
|
||||
};
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const validate = compileConfigSchemas(schemas, {
|
||||
noUndeclaredProperties: options.noUndeclaredProperties,
|
||||
|
||||
@@ -18,9 +18,7 @@ import { AppConfig } from '@backstage/config';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
/**
|
||||
* A sub-set of configuration schema for a given package.
|
||||
*
|
||||
* @public
|
||||
* An sub-set of configuration schema.
|
||||
*/
|
||||
export type ConfigSchemaPackageEntry = {
|
||||
/**
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
```ts
|
||||
import { Config } from '@backstage/config';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import express from 'express';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { Logger } from 'winston';
|
||||
import { PluginDatabaseManager } from '@backstage/backend-common';
|
||||
|
||||
@@ -14,7 +14,9 @@ export function createRouter(options: RouterOptions): Promise<express.Router>;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface RouterOptions {
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: {
|
||||
[context: string]: JsonObject;
|
||||
};
|
||||
appPackageName: string;
|
||||
// (undocumented)
|
||||
config: Config;
|
||||
|
||||
@@ -20,7 +20,6 @@ import { Logger } from 'winston';
|
||||
import { AppConfig, Config } from '@backstage/config';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { loadConfigSchema, readEnvConfig } from '@backstage/config-loader';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
|
||||
type InjectOptions = {
|
||||
appConfigs: AppConfig[];
|
||||
@@ -75,7 +74,7 @@ type ReadOptions = {
|
||||
env: { [name: string]: string | undefined };
|
||||
appDistDir: string;
|
||||
config: Config;
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: { [context: string]: JsonObject };
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -37,7 +37,7 @@ import {
|
||||
CACHE_CONTROL_NO_CACHE,
|
||||
CACHE_CONTROL_REVALIDATE_CACHE,
|
||||
} from '../lib/headers';
|
||||
import { ConfigSchemaPackageEntry } from '@backstage/config-loader';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
|
||||
// express uses mime v1 while we only have types for mime v2
|
||||
type Mime = { lookup(arg0: string): string };
|
||||
@@ -89,14 +89,14 @@ export interface RouterOptions {
|
||||
|
||||
/**
|
||||
*
|
||||
* Provides a list of additional config schemas, in addition to the serialized schemas
|
||||
* Provides a map of additional config schemas, in addition to the serialized schemas
|
||||
* generated during the application build.
|
||||
* This is useful when additional plugins are dynamically loaded in the application at start,
|
||||
* which were not part of the application build. This option allows feeding the corresponding
|
||||
* JSON schemas.
|
||||
*
|
||||
*/
|
||||
additionalSchemas?: ConfigSchemaPackageEntry[];
|
||||
additionalSchemas?: { [context: string]: JsonObject };
|
||||
}
|
||||
|
||||
/** @public */
|
||||
|
||||
Reference in New Issue
Block a user