LemonCore.ConfigReloader.Digest (lemon_core v0.1.0)

View Source

Change detection via source fingerprinting for the config reloader.

Computes and compares digests for config sources (files, env, secrets) to determine whether a reload is necessary.

File fingerprints combine mtime + size + content hash for reliable detection. Secret digests use metadata only (owner, name, updated_at, version) — never values.

Summary

Functions

Compare two digest sets and return the list of sources that changed.

Compute a digest for the :env source.

Compute a fingerprint for a single file path.

Compute fingerprints for a list of file paths.

Compute a full digest for the :files source.

Compute a digest for the :secrets source.

Check whether a single source digest changed.

Types

digest_set()

@type digest_set() :: %{optional(source()) => source_digest()}

file_fingerprint()

@type file_fingerprint() :: %{
  path: String.t(),
  mtime: tuple() | nil,
  size: non_neg_integer() | nil,
  hash: binary() | nil,
  status: :ok | :missing | :error
}

source()

@type source() :: :files | :env | :secrets

source_digest()

@type source_digest() :: %{
  source: source(),
  fingerprints: [file_fingerprint()] | [map()],
  computed_at_ms: non_neg_integer()
}

Functions

compare(old, new)

@spec compare(digest_set(), digest_set()) :: {[source()], digest_set()}

Compare two digest sets and return the list of sources that changed.

Returns {changed_sources, new_digest_set}.

env_digest(dotenv_path)

@spec env_digest(String.t() | nil) :: source_digest()

Compute a digest for the :env source.

Tracks the .env file fingerprint as the change signal.

file_fingerprint(path)

@spec file_fingerprint(String.t()) :: file_fingerprint()

Compute a fingerprint for a single file path.

Returns mtime, size, and a SHA-256 content hash. Missing or unreadable files are represented with status :missing or :error.

file_fingerprints(paths)

@spec file_fingerprints([String.t()]) :: [file_fingerprint()]

Compute fingerprints for a list of file paths.

files_digest(paths)

@spec files_digest([String.t()]) :: source_digest()

Compute a full digest for the :files source.

secrets_digest(secret_metadata_list)

@spec secrets_digest([map()]) :: source_digest()

Compute a digest for the :secrets source.

Uses metadata only (owner, name, updated_at, version) — secret values are never included.

source_changed?(old, new)

@spec source_changed?(source_digest() | nil, source_digest() | nil) :: boolean()

Check whether a single source digest changed.