Caddy.ConfigProvider (Caddy v2.3.1)

View Source

Agent-based configuration provider for Caddy reverse proxy server.

Manages Caddy configuration using simple text-based Caddyfile format. The configuration is stored as raw Caddyfile text, keeping things simple.

Summary

Functions

Convert caddyfile to JSON

Add an additional (snippet, matcher, etc.)

Add a site configuration

Append content to the Caddyfile.

Backup current configuration

Returns a specification to start this module under a supervisor.

Get config value by key

Get an additional by name

Get all additionals

Get the assembled Caddyfile content from 3 parts

Get current configuration

Get global options content

Get a site by address

Get all sites

Initialize configuration

Parse a Caddyfile text into its 3 components.

Remove an additional by name

Remove a site by address

Restore configuration from backup

Save current configuration

Set Caddy binary path

Set binary path and restart server

Set the Caddyfile content by parsing it into 3 parts.

Replace current configuration

Set global options content (without braces)

Start config agent

Update an existing additional by name, or add if not found

Update an existing site by address, or add if not found

Functions

adapt(caddyfile_text)

@spec adapt(binary()) :: {:ok, map()} | {:error, term()}

Convert caddyfile to JSON

add_additional(name, content)

@spec add_additional(binary(), binary()) :: :ok

Add an additional (snippet, matcher, etc.)

add_site(address, config)

@spec add_site(binary(), binary()) :: :ok

Add a site configuration

append_caddyfile(content)

@spec append_caddyfile(binary()) :: :ok

Append content to the Caddyfile.

Parses the content and merges with existing configuration. Site blocks are added, additionals are appended.

backup_config()

@spec backup_config() :: :ok | {:error, term()}

Backup current configuration

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(name)

@spec get(atom()) :: term()

Get config value by key

get_additional(name)

@spec get_additional(binary()) :: Caddy.Config.additional() | nil

Get an additional by name

get_additionals()

@spec get_additionals() :: [Caddy.Config.additional()]

Get all additionals

get_caddyfile()

@spec get_caddyfile() :: binary()

Get the assembled Caddyfile content from 3 parts

get_config()

@spec get_config() :: Caddy.Config.t()

Get current configuration

get_global()

@spec get_global() :: binary()

Get global options content

get_site(address)

@spec get_site(binary()) :: Caddy.Config.site() | nil

Get a site by address

get_sites()

@spec get_sites() :: [Caddy.Config.site()]

Get all sites

init(args)

@spec init(keyword()) :: Caddy.Config.t()

Initialize configuration

parse_caddyfile(caddyfile)

@spec parse_caddyfile(binary()) ::
  {binary(), [Caddy.Config.additional()], [Caddy.Config.site()]}

Parse a Caddyfile text into its 3 components.

Returns {global, additionals, sites} tuple where additionals is a list of %{name: name, content: content} maps.

remove_additional(name)

@spec remove_additional(binary()) :: :ok

Remove an additional by name

remove_site(address)

@spec remove_site(binary()) :: :ok

Remove a site by address

restore_config()

@spec restore_config() :: {:ok, Caddy.Config.t()} | {:error, term()}

Restore configuration from backup

save_config()

@spec save_config() :: :ok | {:error, term()}

Save current configuration

set_bin(caddy_bin)

@spec set_bin(binary()) :: :ok | {:error, binary()}

Set Caddy binary path

set_bin!(caddy_bin)

@spec set_bin!(binary()) :: :ok | {:error, term()}

Set binary path and restart server

set_caddyfile(caddyfile)

@spec set_caddyfile(binary()) :: :ok

Set the Caddyfile content by parsing it into 3 parts.

This provides backward compatibility - pass a complete Caddyfile text and it will be parsed into global, additionals, and sites components.

set_config(config)

@spec set_config(Caddy.Config.t()) :: :ok | {:error, term()}

Replace current configuration

set_global(content)

@spec set_global(binary()) :: :ok

Set global options content (without braces)

start_link(args)

@spec start_link(keyword()) :: {:ok, pid()} | {:error, term()}

Start config agent

update_additional(name, content)

@spec update_additional(binary(), binary()) :: :ok

Update an existing additional by name, or add if not found

update_site(address, config)

@spec update_site(binary(), binary()) :: :ok

Update an existing site by address, or add if not found