Caddy.ConfigManager.Behaviour behaviour (Caddy v2.3.1)

View Source

Behaviour for ConfigManager, enabling Mox-based testing.

Defines the contract for configuration management operations that coordinate between in-memory and runtime Caddy config.

Summary

Callbacks

Apply JSON config directly to running Caddy

Apply JSON config to running Caddy at specific path

Check if in-memory and runtime configs are in sync

Get configuration from specified source

Get in-memory config in specified format

Get JSON config from running Caddy

Get JSON config from running Caddy at specific path

Rollback to last known good config

Set Caddyfile in memory with optional sync to Caddy

Pull running Caddy config to memory

Push in-memory config to running Caddy

Push in-memory config to running Caddy with options

Validate config without applying

Types

source()

@type source() :: :memory | :runtime | :both

sync_opts()

@type sync_opts() :: keyword()

sync_status()

@type sync_status() :: :in_sync | {:drift_detected, map()}

Callbacks

apply_runtime_config(config)

@callback apply_runtime_config(config :: map()) :: :ok | {:error, term()}

Apply JSON config directly to running Caddy

apply_runtime_config(path, config)

@callback apply_runtime_config(path :: String.t(), config :: map()) ::
  :ok | {:error, term()}

Apply JSON config to running Caddy at specific path

check_sync_status()

@callback check_sync_status() :: {:ok, sync_status()}

Check if in-memory and runtime configs are in sync

get_config(source)

@callback get_config(source :: source()) :: {:ok, map()} | {:error, term()}

Get configuration from specified source

get_memory_config(format)

@callback get_memory_config(format :: :caddyfile | :json) ::
  {:ok, binary() | map()} | {:error, term()}

Get in-memory config in specified format

get_runtime_config()

@callback get_runtime_config() :: {:ok, map()} | {:error, term()}

Get JSON config from running Caddy

get_runtime_config(path)

@callback get_runtime_config(path :: String.t()) :: {:ok, map()} | {:error, term()}

Get JSON config from running Caddy at specific path

rollback()

@callback rollback() :: :ok | {:error, term()}

Rollback to last known good config

set_caddyfile(caddyfile, opts)

@callback set_caddyfile(caddyfile :: binary(), opts :: sync_opts()) ::
  :ok | {:error, term()}

Set Caddyfile in memory with optional sync to Caddy

sync_from_caddy()

@callback sync_from_caddy() :: :ok | {:error, term()}

Pull running Caddy config to memory

sync_to_caddy()

@callback sync_to_caddy() :: :ok | {:error, term()}

Push in-memory config to running Caddy

sync_to_caddy(opts)

@callback sync_to_caddy(opts :: sync_opts()) :: :ok | {:error, term()}

Push in-memory config to running Caddy with options

validate_config(caddyfile)

@callback validate_config(caddyfile :: binary()) :: :ok | {:error, term()}

Validate config without applying