Merge pull request #18838 from backstage/vinzscam/root-config-service
Rename ConfigService to RootConfigService
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 { ConfigService } from '@backstage/backend-plugin-api';
|
||||
import { CorsOptions } from 'cors';
|
||||
import { ErrorRequestHandler } from 'express';
|
||||
import { Express as Express_2 } from 'express';
|
||||
@@ -30,6 +29,7 @@ import { PluginEndpointDiscovery } from '@backstage/backend-common';
|
||||
import { RemoteConfigSourceOptions } from '@backstage/config-loader';
|
||||
import { RequestHandler } from 'express';
|
||||
import { RequestListener } from 'http';
|
||||
import { RootConfigService } from '@backstage/backend-plugin-api';
|
||||
import { RootHttpRouterService } from '@backstage/backend-plugin-api';
|
||||
import { RootLifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { RootLoggerService } from '@backstage/backend-plugin-api';
|
||||
@@ -53,17 +53,6 @@ export interface Backend {
|
||||
// @public (undocumented)
|
||||
export const cacheServiceFactory: () => ServiceFactory<CacheClient, 'plugin'>;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface ConfigFactoryOptions {
|
||||
argv?: string[];
|
||||
remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export const configServiceFactory: (
|
||||
options?: ConfigFactoryOptions | undefined,
|
||||
) => ServiceFactory<ConfigService, 'root'>;
|
||||
|
||||
// @public (undocumented)
|
||||
export function createConfigSecretEnumerator(options: {
|
||||
logger: LoggerService;
|
||||
@@ -224,7 +213,7 @@ export interface MiddlewareFactoryErrorOptions {
|
||||
// @public
|
||||
export interface MiddlewareFactoryOptions {
|
||||
// (undocumented)
|
||||
config: ConfigService;
|
||||
config: RootConfigService;
|
||||
// (undocumented)
|
||||
logger: LoggerService;
|
||||
}
|
||||
@@ -244,12 +233,23 @@ export function readHelmetOptions(config?: Config): HelmetOptions;
|
||||
// @public
|
||||
export function readHttpServerOptions(config?: Config): HttpServerOptions;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface RootConfigFactoryOptions {
|
||||
argv?: string[];
|
||||
remote?: Pick<RemoteConfigSourceOptions, 'reloadInterval'>;
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export const rootConfigServiceFactory: (
|
||||
options?: RootConfigFactoryOptions | undefined,
|
||||
) => ServiceFactory<RootConfigService, 'root'>;
|
||||
|
||||
// @public (undocumented)
|
||||
export interface RootHttpRouterConfigureContext {
|
||||
// (undocumented)
|
||||
app: Express_2;
|
||||
// (undocumented)
|
||||
config: ConfigService;
|
||||
config: RootConfigService;
|
||||
// (undocumented)
|
||||
lifecycle: LifecycleService;
|
||||
// (undocumented)
|
||||
|
||||
@@ -14,12 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ConfigService } from '@backstage/backend-plugin-api';
|
||||
import { ConfigReader } from '@backstage/config';
|
||||
import { Config, ConfigReader } from '@backstage/config';
|
||||
import { JsonValue } from '@backstage/types';
|
||||
|
||||
export class ObservableConfigProxy implements ConfigService {
|
||||
private config: ConfigService = new ConfigReader({});
|
||||
export class ObservableConfigProxy implements Config {
|
||||
private config: Config = new ConfigReader({});
|
||||
|
||||
private readonly subscribers: (() => void)[] = [];
|
||||
|
||||
@@ -32,7 +31,7 @@ export class ObservableConfigProxy implements ConfigService {
|
||||
}
|
||||
}
|
||||
|
||||
setConfig(config: ConfigService) {
|
||||
setConfig(config: Config) {
|
||||
if (this.parent) {
|
||||
throw new Error('immutable');
|
||||
}
|
||||
@@ -62,9 +61,9 @@ export class ObservableConfigProxy implements ConfigService {
|
||||
};
|
||||
}
|
||||
|
||||
private select(required: true): ConfigService;
|
||||
private select(required: false): ConfigService | undefined;
|
||||
private select(required: boolean): ConfigService | undefined {
|
||||
private select(required: true): Config;
|
||||
private select(required: false): Config | undefined;
|
||||
private select(required: boolean): Config | undefined {
|
||||
if (this.parent && this.parentKey) {
|
||||
if (required) {
|
||||
return this.parent.select(true).getConfig(this.parentKey);
|
||||
@@ -87,19 +86,19 @@ export class ObservableConfigProxy implements ConfigService {
|
||||
getOptional<T = JsonValue>(key?: string): T | undefined {
|
||||
return this.select(false)?.getOptional(key);
|
||||
}
|
||||
getConfig(key: string): ConfigService {
|
||||
getConfig(key: string): Config {
|
||||
return new ObservableConfigProxy(this, key);
|
||||
}
|
||||
getOptionalConfig(key: string): ConfigService | undefined {
|
||||
getOptionalConfig(key: string): Config | undefined {
|
||||
if (this.select(false)?.has(key)) {
|
||||
return new ObservableConfigProxy(this, key);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
getConfigArray(key: string): ConfigService[] {
|
||||
getConfigArray(key: string): Config[] {
|
||||
return this.select(true).getConfigArray(key);
|
||||
}
|
||||
getOptionalConfigArray(key: string): ConfigService[] | undefined {
|
||||
getOptionalConfigArray(key: string): Config[] | undefined {
|
||||
return this.select(false)?.getOptionalConfigArray(key);
|
||||
}
|
||||
getNumber(key: string): number {
|
||||
|
||||
@@ -14,7 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ConfigService, LoggerService } from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
RootConfigService,
|
||||
LoggerService,
|
||||
} from '@backstage/backend-plugin-api';
|
||||
import {
|
||||
Request,
|
||||
Response,
|
||||
@@ -47,7 +50,7 @@ import { NotImplementedError } from '@backstage/errors';
|
||||
* @public
|
||||
*/
|
||||
export interface MiddlewareFactoryOptions {
|
||||
config: ConfigService;
|
||||
config: RootConfigService;
|
||||
logger: LoggerService;
|
||||
}
|
||||
|
||||
@@ -78,7 +81,7 @@ export interface MiddlewareFactoryErrorOptions {
|
||||
* @public
|
||||
*/
|
||||
export class MiddlewareFactory {
|
||||
#config: ConfigService;
|
||||
#config: RootConfigService;
|
||||
#logger: LoggerService;
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import {
|
||||
export const cacheServiceFactory = createServiceFactory({
|
||||
service: coreServices.cache,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
plugin: coreServices.pluginMetadata,
|
||||
},
|
||||
async createRootContext({ config }) {
|
||||
|
||||
@@ -14,5 +14,5 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { configServiceFactory } from './configServiceFactory';
|
||||
export type { ConfigFactoryOptions } from './configServiceFactory';
|
||||
export { rootConfigServiceFactory } from './rootConfigServiceFactory';
|
||||
export type { RootConfigFactoryOptions } from './rootConfigServiceFactory';
|
||||
|
||||
+4
-4
@@ -24,7 +24,7 @@ import {
|
||||
} from '@backstage/config-loader';
|
||||
|
||||
/** @public */
|
||||
export interface ConfigFactoryOptions {
|
||||
export interface RootConfigFactoryOptions {
|
||||
/**
|
||||
* Process arguments to use instead of the default `process.argv()`.
|
||||
*/
|
||||
@@ -37,9 +37,9 @@ export interface ConfigFactoryOptions {
|
||||
}
|
||||
|
||||
/** @public */
|
||||
export const configServiceFactory = createServiceFactory(
|
||||
(options?: ConfigFactoryOptions) => ({
|
||||
service: coreServices.config,
|
||||
export const rootConfigServiceFactory = createServiceFactory(
|
||||
(options?: RootConfigFactoryOptions) => ({
|
||||
service: coreServices.rootConfig,
|
||||
deps: {},
|
||||
async factory() {
|
||||
const source = ConfigSources.default({
|
||||
+1
-1
@@ -25,7 +25,7 @@ import { ConfigReader } from '@backstage/config';
|
||||
export const databaseServiceFactory = createServiceFactory({
|
||||
service: coreServices.database,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
lifecycle: coreServices.lifecycle,
|
||||
pluginMetadata: coreServices.pluginMetadata,
|
||||
},
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import {
|
||||
export const discoveryServiceFactory = createServiceFactory({
|
||||
service: coreServices.discovery,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
},
|
||||
async factory({ config }) {
|
||||
return HostDiscovery.fromConfig(config);
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import { ServerPermissionClient } from '@backstage/plugin-permission-node';
|
||||
export const permissionsServiceFactory = createServiceFactory({
|
||||
service: coreServices.permissions,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
discovery: coreServices.discovery,
|
||||
tokenManager: coreServices.tokenManager,
|
||||
},
|
||||
|
||||
+3
-3
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
ConfigService,
|
||||
RootConfigService,
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
LifecycleService,
|
||||
@@ -36,7 +36,7 @@ export interface RootHttpRouterConfigureContext {
|
||||
app: Express;
|
||||
middleware: MiddlewareFactory;
|
||||
routes: RequestHandler;
|
||||
config: ConfigService;
|
||||
config: RootConfigService;
|
||||
logger: LoggerService;
|
||||
lifecycle: LifecycleService;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ export const rootHttpRouterServiceFactory = createServiceFactory(
|
||||
(options?: RootHttpRouterFactoryOptions) => ({
|
||||
service: coreServices.rootHttpRouter,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
rootLogger: coreServices.rootLogger,
|
||||
lifecycle: coreServices.rootLifecycle,
|
||||
},
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import { createConfigSecretEnumerator } from '../../../config';
|
||||
export const rootLoggerServiceFactory = createServiceFactory({
|
||||
service: coreServices.rootLogger,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
},
|
||||
async factory({ config }) {
|
||||
const logger = WinstonLogger.create({
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import { ServerTokenManager } from '@backstage/backend-common';
|
||||
export const tokenManagerServiceFactory = createServiceFactory({
|
||||
service: coreServices.tokenManager,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
logger: coreServices.rootLogger,
|
||||
},
|
||||
createRootContext({ config, logger }) {
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ import {
|
||||
export const urlReaderServiceFactory = createServiceFactory({
|
||||
service: coreServices.urlReader,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
logger: coreServices.logger,
|
||||
},
|
||||
async factory({ config, logger }) {
|
||||
|
||||
@@ -18,7 +18,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 { ConfigService } from '@backstage/backend-plugin-api';
|
||||
import cors from 'cors';
|
||||
import Docker from 'dockerode';
|
||||
import { ErrorRequestHandler } from 'express';
|
||||
@@ -51,6 +50,7 @@ import { ReadTreeResponseFile } from '@backstage/backend-plugin-api';
|
||||
import { ReadUrlOptions } from '@backstage/backend-plugin-api';
|
||||
import { ReadUrlResponse } from '@backstage/backend-plugin-api';
|
||||
import { RequestHandler } from 'express';
|
||||
import { RootConfigService } from '@backstage/backend-plugin-api';
|
||||
import { Router } from 'express';
|
||||
import { SchedulerService } from '@backstage/backend-plugin-api';
|
||||
import { SearchOptions } from '@backstage/backend-plugin-api';
|
||||
@@ -525,7 +525,7 @@ export const legacyPlugin: (
|
||||
TransformedEnv<
|
||||
{
|
||||
cache: CacheClient;
|
||||
config: ConfigService;
|
||||
config: RootConfigService;
|
||||
database: PluginDatabaseManager;
|
||||
discovery: PluginEndpointDiscovery;
|
||||
logger: LoggerService;
|
||||
|
||||
@@ -108,7 +108,7 @@ export function makeLegacyPlugin<
|
||||
export const legacyPlugin = makeLegacyPlugin(
|
||||
{
|
||||
cache: coreServices.cache,
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
database: coreServices.database,
|
||||
discovery: coreServices.discovery,
|
||||
logger: coreServices.logger,
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import {
|
||||
Backend,
|
||||
cacheServiceFactory,
|
||||
configServiceFactory,
|
||||
rootConfigServiceFactory,
|
||||
createSpecializedBackend,
|
||||
databaseServiceFactory,
|
||||
discoveryServiceFactory,
|
||||
@@ -40,7 +40,7 @@ import {
|
||||
|
||||
export const defaultServiceFactories = [
|
||||
cacheServiceFactory(),
|
||||
configServiceFactory(),
|
||||
rootConfigServiceFactory(),
|
||||
databaseServiceFactory(),
|
||||
discoveryServiceFactory(),
|
||||
httpRouterServiceFactory(),
|
||||
|
||||
@@ -93,13 +93,10 @@ export type CacheServiceSetOptions = {
|
||||
ttl?: number;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export interface ConfigService extends Config {}
|
||||
|
||||
// @public
|
||||
export namespace coreServices {
|
||||
const cache: ServiceRef<CacheService, 'plugin'>;
|
||||
const config: ServiceRef<ConfigService, 'root'>;
|
||||
const rootConfig: ServiceRef<RootConfigService, 'root'>;
|
||||
const database: ServiceRef<DatabaseService, 'plugin'>;
|
||||
const discovery: ServiceRef<DiscoveryService, 'plugin'>;
|
||||
const httpRouter: ServiceRef<HttpRouterService, 'plugin'>;
|
||||
@@ -380,6 +377,9 @@ export type ReadUrlResponse = {
|
||||
lastModifiedAt?: Date;
|
||||
};
|
||||
|
||||
// @public (undocumented)
|
||||
export interface RootConfigService extends Config {}
|
||||
|
||||
// @public (undocumented)
|
||||
export interface RootHttpRouterService {
|
||||
use(path: string, handler: Handler): void;
|
||||
|
||||
+1
-1
@@ -19,4 +19,4 @@ import { Config } from '@backstage/config';
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface ConfigService extends Config {}
|
||||
export interface RootConfigService extends Config {}
|
||||
@@ -32,13 +32,13 @@ export namespace coreServices {
|
||||
});
|
||||
|
||||
/**
|
||||
* The service reference for the root scoped {@link ConfigService}.
|
||||
* The service reference for the root scoped {@link RootConfigService}.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const config = createServiceRef<
|
||||
import('./ConfigService').ConfigService
|
||||
>({ id: 'core.config', scope: 'root' });
|
||||
export const rootConfig = createServiceRef<
|
||||
import('./RootConfigService').RootConfigService
|
||||
>({ id: 'core.rootConfig', scope: 'root' });
|
||||
|
||||
/**
|
||||
* The service reference for the plugin scoped {@link DatabaseService}.
|
||||
|
||||
@@ -20,7 +20,7 @@ export type {
|
||||
CacheServiceOptions,
|
||||
CacheServiceSetOptions,
|
||||
} from './CacheService';
|
||||
export type { ConfigService } from './ConfigService';
|
||||
export type { RootConfigService } from './RootConfigService';
|
||||
export type { DatabaseService } from './DatabaseService';
|
||||
export type { DiscoveryService } from './DiscoveryService';
|
||||
export type { HttpRouterService } from './HttpRouterService';
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
import { Backend } from '@backstage/backend-app-api';
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { CacheService } from '@backstage/backend-plugin-api';
|
||||
import { ConfigService } from '@backstage/backend-plugin-api';
|
||||
import { DatabaseService } from '@backstage/backend-plugin-api';
|
||||
import { ExtendedHttpServer } from '@backstage/backend-app-api';
|
||||
import { ExtensionPoint } from '@backstage/backend-plugin-api';
|
||||
@@ -18,6 +17,7 @@ import { Knex } from 'knex';
|
||||
import { LifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { PermissionsService } from '@backstage/backend-plugin-api';
|
||||
import { RootConfigService } from '@backstage/backend-plugin-api';
|
||||
import { RootLifecycleService } from '@backstage/backend-plugin-api';
|
||||
import { SchedulerService } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
@@ -36,19 +36,6 @@ export namespace mockServices {
|
||||
factory: () => ServiceFactory<CacheService, 'plugin'>;
|
||||
}
|
||||
// (undocumented)
|
||||
export function config(options?: config.Options): ConfigService;
|
||||
// (undocumented)
|
||||
export namespace config {
|
||||
// (undocumented)
|
||||
export type Options = {
|
||||
data?: JsonObject;
|
||||
};
|
||||
const // (undocumented)
|
||||
factory: (
|
||||
options?: Options | undefined,
|
||||
) => ServiceFactory<ConfigService, 'root'>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace database {
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<DatabaseService, 'plugin'>;
|
||||
@@ -83,6 +70,19 @@ export namespace mockServices {
|
||||
factory: () => ServiceFactory<PermissionsService, 'plugin'>;
|
||||
}
|
||||
// (undocumented)
|
||||
export function rootConfig(options?: rootConfig.Options): RootConfigService;
|
||||
// (undocumented)
|
||||
export namespace rootConfig {
|
||||
// (undocumented)
|
||||
export type Options = {
|
||||
data?: JsonObject;
|
||||
};
|
||||
const // (undocumented)
|
||||
factory: (
|
||||
options?: Options | undefined,
|
||||
) => ServiceFactory<RootConfigService, 'root'>;
|
||||
}
|
||||
// (undocumented)
|
||||
export namespace rootLifecycle {
|
||||
const // (undocumented)
|
||||
factory: () => ServiceFactory<RootLifecycleService, 'root'>;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import {
|
||||
ConfigService,
|
||||
RootConfigService,
|
||||
coreServices,
|
||||
createServiceFactory,
|
||||
IdentityService,
|
||||
@@ -61,13 +61,13 @@ function simpleFactory<
|
||||
* @public
|
||||
*/
|
||||
export namespace mockServices {
|
||||
export function config(options?: config.Options): ConfigService {
|
||||
export function rootConfig(options?: rootConfig.Options): RootConfigService {
|
||||
return new ConfigReader(options?.data, 'mock-config');
|
||||
}
|
||||
export namespace config {
|
||||
export namespace rootConfig {
|
||||
export type Options = { data?: JsonObject };
|
||||
|
||||
export const factory = simpleFactory(coreServices.config, config);
|
||||
export const factory = simpleFactory(coreServices.rootConfig, rootConfig);
|
||||
}
|
||||
|
||||
export function rootLogger(options?: rootLogger.Options): LoggerService {
|
||||
|
||||
@@ -168,7 +168,7 @@ describe('TestBackend', () => {
|
||||
env.registerInit({
|
||||
deps: {
|
||||
cache: coreServices.cache,
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
database: coreServices.database,
|
||||
discovery: coreServices.discovery,
|
||||
httpRouter: coreServices.httpRouter,
|
||||
|
||||
@@ -73,7 +73,7 @@ export interface TestBackend extends Backend {
|
||||
|
||||
const defaultServiceFactories = [
|
||||
mockServices.cache.factory(),
|
||||
mockServices.config.factory(),
|
||||
mockServices.rootConfig.factory(),
|
||||
mockServices.database.factory(),
|
||||
mockServices.httpRouter.factory(),
|
||||
mockServices.identity.factory(),
|
||||
@@ -108,7 +108,7 @@ export async function startTestBackend<
|
||||
const rootHttpRouterFactory = createServiceFactory({
|
||||
service: coreServices.rootHttpRouter,
|
||||
deps: {
|
||||
config: coreServices.config,
|
||||
config: coreServices.rootConfig,
|
||||
lifecycle: coreServices.rootLifecycle,
|
||||
rootLogger: coreServices.rootLogger,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user