servers.caddy #
Caddy Module
The Caddy module provides functionalities to load, parse, merge, and export Caddyfile configurations. It is designed to handle Caddyfile directives and site blocks, allowing for flexible management and integration of Caddy server configurations.
Features
- Loading Caddyfile: Reads a Caddyfile from a given path and parses it into an intermediate data structure.
- Parsing: Converts the Caddyfile content into a structured format with site blocks, directives, matchers, and addresses.
- Merging: Combines multiple Caddyfile instances, ensuring no duplicate blocks and merging blocks for the same domain.
- Exporting: Converts the structured data back into a Caddyfile format, ready for use by the Caddy server.
- Security Configuration: Supports the parsing and exporting of OAuth2 provider configurations within the Caddyfile.
Data Structures
The module uses a set of V structs to represent the different elements of a Caddyfile, including:
- CaddyFile: Represents the entire Caddyfile, containing a list of site blocks.
- SiteBlock: Represents a site block within the Caddyfile, containing addresses and directives.
- Address: Represents a domain and port for a site block.
- Directive: Represents a directive within a site block, potentially containing matchers and sub-directives.
- Matcher: Represents matchers that can be used within directives.
- UserTransform: Represents user transformation rules in the security configuration.
- UILink: Represents UI link configurations within the security settings.
Security Configuration
The module includes support for parsing and exporting security configurations, specifically for generic OAuth2 providers. This includes handling identity providers, authentication portals, and authorization policies within the Caddyfile.
Usage
The module provides functions to:- Load a Caddyfile from a file path.
- Parse the file content into a structured format.
- Merge multiple Caddyfile instances.
- Export the structured data back into a Caddyfile format.
The module ensures that configurations are managed efficiently, avoiding duplicates and maintaining a clean, structured format for Caddy server configurations.
Notes
Some code and documentation in this module is generated by AI for efficiency. Further improvements and tests are encouraged.
fn configure #
fn configure(instance string, cfg_ Config) !Caddy[Config]
set the configuration, will make defaults for passwd & secret
fn get #
fn get(instance string) !Caddy[Config]
fn merge_caddyfiles #
fn merge_caddyfiles(file1 CaddyFile, file2 CaddyFile) CaddyFile
fn validate #
fn validate(args ValidateArgs) !
fn (Caddy[Config]) restart #
fn (mut self Caddy[Config]) restart() !
Restart the Caddy
fn (Caddy[Config]) reload #
fn (mut self Caddy[Config]) reload() !
Restart the Caddy
fn (Caddy[Config]) start #
fn (mut self Caddy[Config]) start() !
fn (Caddy[Config]) stop #
fn (mut self Caddy[Config]) stop() !
fn (Caddy[Config]) set_caddyfile #
fn (mut self Caddy[Config]) set_caddyfile(file CaddyFile) !
struct Address #
struct Address {
pub mut:
url urllib.URL @[omitempty]
description string @[omitempty]
}
struct AdminConfig #
struct AdminConfig {
pub mut:
disabled bool @[omitempty]
listen string @[omitempty]
enforce_origin bool @[omitempty]
origins []string @[omitempty]
config ConfigSettings @[omitempty]
identity IdentityConfig @[omitempty]
remote RemoteAdmin @[omitempty]
}
struct Apps #
struct Apps {
pub mut:
security security.Security
http http.HTTP
}
struct Caddy #
struct Caddy[T] {
base.BaseConfig[T]
}
import freeflowuniverse.crystallib.ui.console
struct CaddyFile #
struct CaddyFile {
pub mut:
admin AdminConfig @[omitempty]
apps Apps @[omitempty]
}
fn (CaddyFile) add_basic_auth #
fn (mut file CaddyFile) add_basic_auth(args http.BasicAuth) !
fn (CaddyFile) add_file_server #
fn (mut file CaddyFile) add_file_server(args http.FileServer) !
fn (CaddyFile) add_oauth #
fn (mut file CaddyFile) add_oauth(config security.OAuthConfig) !
fn (CaddyFile) add_reverse_proxy #
fn (mut file CaddyFile) add_reverse_proxy(args http.ReverseProxy) !
Functions for common directives
fn (CaddyFile) export #
fn (file CaddyFile) export(path_ string) !
struct Config #
struct Config {
pub mut:
homedir string = '/etc/caddy'
reset bool
file CaddyFile
plugins []string
}
struct ValidateArgs #
struct ValidateArgs {
pub:
text string
path string
}