Skip to content

Commit

Permalink
feat(config): delay preset resolution until after platform initializa…
Browse files Browse the repository at this point in the history
…tion (#9415)

Delay config preset resolution in admin config until after platform initialization. This will enable resolution of private “local>…” presets to work.

BREAKING CHANGE: Config presets will be resolved after platform initialization, so from now on platform credentials cannot be placed in presets.
  • Loading branch information
rarkins committed Apr 22, 2021
1 parent e7b5be9 commit cbf8ea4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/config/index.ts
Expand Up @@ -7,7 +7,6 @@ import * as defaultsParser from './defaults';
import * as definitions from './definitions';
import * as envParser from './env';
import * as fileParser from './file';
import { resolveConfigPresets } from './presets';
import type {
GlobalConfig,
ManagerConfig,
Expand Down Expand Up @@ -47,10 +46,10 @@ export async function parseConfigs(
logger.debug('Parsing configs');

// Get configs
const defaultConfig = await resolveConfigPresets(defaultsParser.getConfig());
const fileConfig = await resolveConfigPresets(fileParser.getConfig(env));
const cliConfig = await resolveConfigPresets(cliParser.getConfig(argv));
const envConfig = await resolveConfigPresets(envParser.getConfig(env));
const defaultConfig = defaultsParser.getConfig();
const fileConfig = fileParser.getConfig(env);
const cliConfig = cliParser.getConfig(argv);
const envConfig = envParser.getConfig(env);

let config: GlobalConfig = mergeChildConfig(fileConfig, envConfig);
config = mergeChildConfig(config, cliConfig);
Expand Down
1 change: 1 addition & 0 deletions lib/constants/error-messages.ts
Expand Up @@ -12,6 +12,7 @@ export const PLATFORM_RATE_LIMIT_EXCEEDED = 'rate-limit-exceeded';

// Config Error
export const CONFIG_VALIDATION = 'config-validation';
export const CONFIG_PRESETS_INVALID = 'config-presets-invalid';
export const CONFIG_SECRETS_EXPOSED = 'config-secrets-exposed';
export const CONFIG_SECRETS_INVALID = 'config-secrets-invalid';

Expand Down
12 changes: 12 additions & 0 deletions lib/workers/global/index.ts
Expand Up @@ -5,12 +5,14 @@ import { satisfies } from 'semver';
import upath from 'upath';
import * as pkg from '../../../package.json';
import * as configParser from '../../config';
import { resolveConfigPresets } from '../../config/presets';
import { validateConfigSecrets } from '../../config/secrets';
import type {
GlobalConfig,
RenovateConfig,
RenovateRepository,
} from '../../config/types';
import { CONFIG_PRESETS_INVALID } from '../../constants/error-messages';
import { getProblems, logger, setMeta } from '../../logger';
import { setUtilConfig } from '../../util';
import * as hostRules from '../../util/host-rules';
Expand Down Expand Up @@ -70,6 +72,14 @@ function checkEnv(): void {
}
}

export async function validatePresets(config: GlobalConfig): Promise<void> {
try {
await resolveConfigPresets(config);
} catch (err) /* istanbul ignore next */ {
throw new Error(CONFIG_PRESETS_INVALID);
}
}

export async function start(): Promise<number> {
let config: GlobalConfig;
try {
Expand All @@ -78,6 +88,8 @@ export async function start(): Promise<number> {
// initialize all submodules
config = await globalInitialize(config);

await validatePresets(config);

checkEnv();

// validate secrets. Will throw and abort if invalid
Expand Down

0 comments on commit cbf8ea4

Please sign in to comment.