async function assertValidGkeConfigMapFile()

in src/poller/poller-core/config-validator.js [145:189]


async function assertValidGkeConfigMapFile(configValidator, filename) {
  let configMap;

  try {
    const configText = await fs.readFile(filename, 'utf-8');
    configMap = /** @type {any} */ (yaml.load(configText));
  } catch (e) {
    console.error(`Could not parse YAML from ${filename}: ${e}`);
    throw e;
  }

  if (configMap.kind !== 'ConfigMap') {
    console.error(`${filename} is not a GKE ConfigMap`);
    throw new Error(`${filename} is not a GKE ConfigMap`);
  }

  let success = true;
  for (const configMapFile of Object.keys(configMap.data)) {
    const configMapData = configMap.data[configMapFile];
    try {
      const memorystoreConfig = yaml.load(configMapData);
      await configValidator.parseAndAssertValidConfig(
        JSON.stringify(memorystoreConfig),
      );
    } catch (e) {
      if (e instanceof ValidationError) {
        console.error(
          `Validation of configMap entry data.${configMapFile} in file ${filename} failed:\n${e.message}`,
        );
      } else if (e instanceof yaml.YAMLException) {
        console.error(
          `Could not parse YAML from value data.${configMapFile} in ${filename}: ${e}`,
        );
      } else {
        console.error(
          `Processing of configMap entry data.${configMapFile} in file ${filename} failed: ${e}`,
        );
      }
      success = false;
    }
  }
  if (!success) {
    throw new Error(`${filename} Failed validation`);
  }
}