Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to hard-validate a configuration file, which can be used in CI, so a bad config file is not deployed #250

Closed
lyricnz opened this issue Mar 7, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@lyricnz
Copy link
Contributor

lyricnz commented Mar 7, 2024

No description provided.

@lyricnz lyricnz added the enhancement New feature or request label Mar 28, 2024
@lyricnz
Copy link
Contributor Author

lyricnz commented Jun 27, 2024

Here's a script that loads the configuration file, then explicitly checks that there are no file-paths configured in the config

import { logger } from './lib/logger.js';

import environ from './lib/environ.js';
import { RevolverConfig } from './lib/config.js';

/**
 * Validate the configuration provided by $CONFIG_FILE environment variable
 * @returns a parsed and validated configuration object
 */
async function validateConfig(): Promise<object> {
  // Note: configuration is not especially strict (unknown keys are ignored/stripped)
  const config = await (environ.configPath
    ? RevolverConfig.readConfigFromFile(environ.configPath)
    : RevolverConfig.readConfigFromS3(environ.configBucket!, environ.configKey!));

  // Check that NONE of the file-output parameters are specified
  const filePaths = [
    config.defaults.settings.resourceLog?.json?.file,
    config.defaults.settings.resourceLog?.html?.file,
    config.defaults.settings.resourceLog?.csv?.file,
    config.defaults.settings.auditLog?.html?.file,
    config.defaults.settings.auditLog?.csv?.file,
    config.defaults.settings.auditLog?.json?.file,
    config.defaults.settings.localResourcesFile,
    config.defaults.settings.localOrgAccountsFile,
    config.defaults.settings.localOrgAccountsWriteFile,
  ];
  const found = filePaths.filter((p) => p !== undefined);
  if (found.length > 0) {
    throw Error(`Found file-paths specified in config file: ${found}`);
  }

  return config;
}

validateConfig().then((config) => logger.info('Dumping validated configuration', config));

@lyricnz
Copy link
Contributor Author

lyricnz commented Sep 25, 2024

@lyricnz lyricnz closed this as completed Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant