Caddy.ConfigProvider (Caddy v2.3.1)
View SourceAgent-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
Convert caddyfile to JSON
Add an additional (snippet, matcher, etc.)
Add a site configuration
@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.
@spec backup_config() :: :ok | {:error, term()}
Backup current configuration
Returns a specification to start this module under a supervisor.
See Supervisor.
Get config value by key
@spec get_additional(binary()) :: Caddy.Config.additional() | nil
Get an additional by name
@spec get_additionals() :: [Caddy.Config.additional()]
Get all additionals
@spec get_caddyfile() :: binary()
Get the assembled Caddyfile content from 3 parts
@spec get_config() :: Caddy.Config.t()
Get current configuration
@spec get_global() :: binary()
Get global options content
@spec get_site(binary()) :: Caddy.Config.site() | nil
Get a site by address
@spec get_sites() :: [Caddy.Config.site()]
Get all sites
@spec init(keyword()) :: Caddy.Config.t()
Initialize configuration
@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.
@spec remove_additional(binary()) :: :ok
Remove an additional by name
@spec remove_site(binary()) :: :ok
Remove a site by address
@spec restore_config() :: {:ok, Caddy.Config.t()} | {:error, term()}
Restore configuration from backup
@spec save_config() :: :ok | {:error, term()}
Save current configuration
Set Caddy binary path
Set binary path and restart server
@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.
@spec set_config(Caddy.Config.t()) :: :ok | {:error, term()}
Replace current configuration
@spec set_global(binary()) :: :ok
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