Merge pull request #25585 from backstage/rugvip/nopts
backend-defaults: deprecate config service options
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/backend-defaults': patch
|
||||
---
|
||||
|
||||
Refactor of `rootConfigServiceFactory` to allow it to be constructed with options, but without declaring options via `createServiceFactory`.
|
||||
@@ -60,3 +60,34 @@ backend.add(
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
For more advanced customization, there are several APIs from the `@backstage/config-loader` package that allow you to customize the implementation of the config service. The default implementation uses the `ConfigSources.default` method, which has the same options as the `rootConfigServiceFactory` function. You can use these to create your own config service implementation:
|
||||
|
||||
```ts
|
||||
import { ConfigSources } from '@backstage/config-loader';
|
||||
import { createServiceFactory } from '@backstage/backend-plugin-api';
|
||||
|
||||
const backend = createBackend();
|
||||
|
||||
backend.add(
|
||||
createServiceFactory({
|
||||
service: coreServices.rootConfig,
|
||||
deps: {},
|
||||
async factory() {
|
||||
const source = ConfigSources.default({
|
||||
argv: [
|
||||
'--config',
|
||||
'/backstage/app-config.development.yaml',
|
||||
'--config',
|
||||
'/backstage/app-config.yaml',
|
||||
],
|
||||
remote: { reloadIntervalSeconds: 60 },
|
||||
});
|
||||
console.log(`Loading config from ${source}`);
|
||||
return await ConfigSources.toConfig(source);
|
||||
},
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
You can also use other config source such as `StaticConfigSource` and combine them with other sources using `ConfigSources.merge(...)`. You can also create your own config source by implementing the `ConfigSource` interface.
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ConfigSchema } from '@backstage/config-loader';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { RemoteConfigSourceOptions } from '@backstage/config-loader';
|
||||
import { RootConfigService } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactoryCompat } from '@backstage/backend-plugin-api';
|
||||
import { ServiceFactory } from '@backstage/backend-plugin-api';
|
||||
|
||||
// @public (undocumented)
|
||||
export function createConfigSecretEnumerator(options: {
|
||||
@@ -26,11 +26,10 @@ export interface RootConfigFactoryOptions {
|
||||
}
|
||||
|
||||
// @public (undocumented)
|
||||
export const rootConfigServiceFactory: ServiceFactoryCompat<
|
||||
RootConfigService,
|
||||
'root',
|
||||
RootConfigFactoryOptions
|
||||
>;
|
||||
export const rootConfigServiceFactory: ((
|
||||
options?: RootConfigFactoryOptions,
|
||||
) => ServiceFactory<RootConfigService, 'root'>) &
|
||||
ServiceFactory<RootConfigService, 'root'>;
|
||||
|
||||
// (No @packageDocumentation comment for this package)
|
||||
```
|
||||
|
||||
@@ -45,11 +45,10 @@ export interface RootConfigFactoryOptions {
|
||||
watch?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const rootConfigServiceFactory = createServiceFactory(
|
||||
(options?: RootConfigFactoryOptions) => ({
|
||||
export const rootConfigServiceFactoryWithOptions = (
|
||||
options?: RootConfigFactoryOptions,
|
||||
) =>
|
||||
createServiceFactory({
|
||||
service: coreServices.rootConfig,
|
||||
deps: {},
|
||||
async factory() {
|
||||
@@ -61,5 +60,12 @@ export const rootConfigServiceFactory = createServiceFactory(
|
||||
console.log(`Loading config from ${source}`);
|
||||
return await ConfigSources.toConfig(source);
|
||||
},
|
||||
}),
|
||||
})();
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export const rootConfigServiceFactory = Object.assign(
|
||||
rootConfigServiceFactoryWithOptions,
|
||||
rootConfigServiceFactoryWithOptions(),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user