parseImagesSection function

ImageRegistryConfig? parseImagesSection(
  1. Object? node
)

Parses the images: section (session image registry, issue #171): registry (kill switch) and maxPerRequest (per-request unique-image cap). Strict — a bad schema throws ConfigException instead of silently keeping the defaults. Public so the settings flow's reload-after-write (issue #395) reuses the same parser the boot runs.

Implementation

ImageRegistryConfig? parseImagesSection(Object? node) {
  if (node == null) return null;
  if (node is! YamlMap) {
    throw ConfigException('images must be a map, got: $node');
  }
  bool readBool(String key) {
    final value = node[key];
    if (value is! bool) {
      throw ConfigException('"images.$key" must be a boolean');
    }
    return value;
  }

  int readPositiveInt(String key) {
    final value = node[key];
    if (value is! int || value <= 0) {
      throw ConfigException('"images.$key" must be a positive integer');
    }
    return value;
  }

  bool? registry;
  int? maxPerRequest;
  for (final key in node.keys) {
    switch (key) {
      case 'registry':
        registry = readBool('$key');
      case 'maxPerRequest':
        maxPerRequest = readPositiveInt('$key');
      default:
        throw ConfigException('unknown "images" key: $key');
    }
  }
  if (registry == null && maxPerRequest == null) return null;
  return ImageRegistryConfig(
    enabled: registry ?? true,
    maxPerRequest: maxPerRequest ?? defaultMaxImagesPerRequest,
  );
}