Merge pull request #16643 from RobotSail/async-config
Asynchronous configuration / config merging
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@backstage/backend-app-api': patch
|
||||
'@backstage/backend-common': patch
|
||||
---
|
||||
|
||||
Allow an additionalConfig to be provided to loadBackendConfig that fetches config values during runtime.
|
||||
@@ -5,6 +5,7 @@
|
||||
```ts
|
||||
/// <reference types="node" />
|
||||
|
||||
import type { AppConfig } from '@backstage/config';
|
||||
import { BackendFeature } from '@backstage/backend-plugin-api';
|
||||
import { CacheClient } from '@backstage/backend-common';
|
||||
import { Config } from '@backstage/config';
|
||||
@@ -178,6 +179,7 @@ export const lifecycleServiceFactory: () => ServiceFactory<
|
||||
export function loadBackendConfig(options: {
|
||||
remote?: LoadConfigOptionsRemote;
|
||||
argv: string[];
|
||||
additionalConfigs?: AppConfig[];
|
||||
}): Promise<{
|
||||
config: Config;
|
||||
}>;
|
||||
|
||||
@@ -24,7 +24,8 @@ import {
|
||||
ConfigTarget,
|
||||
LoadConfigOptionsRemote,
|
||||
} from '@backstage/config-loader';
|
||||
import { Config, ConfigReader } from '@backstage/config';
|
||||
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';
|
||||
@@ -70,6 +71,7 @@ export async function createConfigSecretEnumerator(options: {
|
||||
export async function loadBackendConfig(options: {
|
||||
remote?: LoadConfigOptionsRemote;
|
||||
argv: string[];
|
||||
additionalConfigs?: AppConfig[];
|
||||
}): Promise<{ config: Config }> {
|
||||
const args = parseArgs(options.argv);
|
||||
|
||||
@@ -92,8 +94,11 @@ export async function loadBackendConfig(options: {
|
||||
console.info(
|
||||
`Reloaded config from ${newConfigs.map(c => c.context).join(', ')}`,
|
||||
);
|
||||
|
||||
config.setConfig(ConfigReader.fromConfigs(newConfigs));
|
||||
const configsToMerge = [...newConfigs];
|
||||
if (options.additionalConfigs) {
|
||||
configsToMerge.push(...options.additionalConfigs);
|
||||
}
|
||||
config.setConfig(ConfigReader.fromConfigs(configsToMerge));
|
||||
},
|
||||
stopSignal: new Promise(resolve => {
|
||||
if (currentCancelFunc) {
|
||||
@@ -109,12 +114,15 @@ export async function loadBackendConfig(options: {
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
console.info(
|
||||
`Loaded config from ${appConfigs.map(c => c.context).join(', ')}`,
|
||||
);
|
||||
|
||||
config.setConfig(ConfigReader.fromConfigs(appConfigs));
|
||||
const finalAppConfigs = [...appConfigs];
|
||||
if (options.additionalConfigs) {
|
||||
finalAppConfigs.push(...options.additionalConfigs);
|
||||
}
|
||||
config.setConfig(ConfigReader.fromConfigs(finalAppConfigs));
|
||||
|
||||
return { config };
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="webpack-env" />
|
||||
|
||||
import { AppConfig } from '@backstage/config';
|
||||
import { AwsCredentialsManager } from '@backstage/integration-aws-node';
|
||||
import { AwsS3Integration } from '@backstage/integration';
|
||||
import { AzureIntegration } from '@backstage/integration';
|
||||
@@ -533,6 +534,7 @@ export const legacyPlugin: (
|
||||
export function loadBackendConfig(options: {
|
||||
logger: LoggerService;
|
||||
remote?: LoadConfigOptionsRemote;
|
||||
additionalConfig?: AppConfig;
|
||||
argv: string[];
|
||||
}): Promise<Config>;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
loadBackendConfig as newLoadBackendConfig,
|
||||
} from '@backstage/backend-app-api';
|
||||
import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
import { Config } from '@backstage/config';
|
||||
import { AppConfig, Config } from '@backstage/config';
|
||||
import { LoadConfigOptionsRemote } from '@backstage/config-loader';
|
||||
import { setRootLoggerRedactionList } from './logging/createRootLogger';
|
||||
|
||||
@@ -34,6 +34,7 @@ export async function loadBackendConfig(options: {
|
||||
logger: LoggerService;
|
||||
// process.argv or any other overrides
|
||||
remote?: LoadConfigOptionsRemote;
|
||||
additionalConfig?: AppConfig;
|
||||
argv: string[];
|
||||
}): Promise<Config> {
|
||||
const secretEnumerator = await createConfigSecretEnumerator({
|
||||
|
||||
Reference in New Issue
Block a user