Skip to content

Adopt ConfigKeyKit in CelestraCloud configuration #405

Description

@leogdion

Summary

Migrate CelestraCloud's configuration layer to ConfigKeyKit, matching the pattern already used by MistDemo and BushelCloud. This work happens in the MistKit repo via the CelestraCloud subrepo.

Motivation

CelestraCloud currently hand-rolls what ConfigKeyKit was built to eliminate:

  • Sources/CelestraCloudKit/Configuration/ConfigurationKeys.swift maintains two string constants per option — a dot key and a paired ENV key (e.g. containerID = "cloudkit.container_id" + containerIDEnv = "CLOUDKIT_CONTAINER_ID"). ~14 paired constants.
  • ConfigurationLoader.loadConfiguration() hand-writes a fallback chain for every option:
    readString(forKey: ...containerID) ?? readString(forKey: ...containerIDEnv) ?? default
    ~11 of these ?? ...Env ?? default chains.

Every new option means editing both files and keeping the CLI/ENV spelling in sync by hand.

Proposed change

Replace ConfigurationKeys string-pair constants with typed ConfigKey definitions and collapse the loader's fallback chains into a single generic read(_:) that iterates ConfigKeySource.allCases (the helper BushelCloud already wrote).

let containerID = ConfigKey("cloudkit.container_id", default: CloudKitConfiguration.defaultContainerID)
containerID.key(for: .commandLine)  // "cloudkit.container_id"
containerID.key(for: .environment)  // "CLOUDKIT_CONTAINER_ID"

Why CelestraCloud is a clean fit

Unlike BushelCloud (which needed a bushelPrefixed helper because its env vars are BUSHEL_*), CelestraCloud's env vars are CLOUDKIT_* and UPDATE_* — which StandardNamingStyle derives directly from the base key's first segment (cloudkit.container_idCLOUDKIT_CONTAINER_ID, update.delayUPDATE_DELAY). So plain ConfigKey(base, default:) produces the exact spellings already in use — no prefix helper / ConfigKey+CELESTRA.swift needed, and no behavior change for users.

Scope

Touches three files:

  • Package.swift — add the ConfigKeyKit product dependency.
  • Sources/CelestraCloudKit/Configuration/ConfigurationKeys.swift — replace string-pair constants with typed ConfigKey definitions.
  • Sources/CelestraCloudKit/Configuration/ConfigurationLoader.swift — collapse ?? ...Env ?? default chains into generic read(_:) helpers (model on BushelCloud's loader).

The provider stack (CommandLineArgumentsProvider + EnvironmentVariablesProvider) stays identical; ConfigKeyKit pairs with swift-configuration rather than replacing it.

Watch-outs

  • Update.jsonOutputPath's CLI key is currently "update.json-output-path" (kebab inside a dot key) while the others use snake case. ConfigKeyKit's naming style would normalize it to update.json_output_path — confirm that's acceptable before migrating.
  • Run swift build and the existing config tests to confirm CLI > ENV > default parity is preserved.

References

  • ConfigKeyKit: https://github.com/brightdigit/ConfigKeyKit
  • Prior adopters: MistDemo (Examples/MistDemo/Sources/MistDemoKit/Configuration/), BushelCloud (Sources/BushelCloudKit/Configuration/ConfigurationLoader.swift)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions