storageconfigloader

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

README

Caddy Config Loader from Storage

Caddy supports dynamic config loading as part of an experimental feature that was introduced in v2.4.0. This module tells Caddy to load its configuration from any Caddy storage module. This means it's possible to store Caddy configuration in any caddy-compatible storage, e.g. database, s3, file_system, memory, encrypted, or any module that's part of the caddy.storage. namespace, and then load it into Caddy dynamically. This is useful for use-cases where you want to store your Caddy configuration in a database, or any form of shared location with multiple Caddy instances.

Example

This configuration file combination eventually configures Caddy to respond with `OK`. Store this configuration file in caddy storage under the key `config/caddy.json`
{
	"admin": {
		"listen": "localhost:2999"
	},
	"apps": {
		"http": {
			"http_port": 9080,
			"https_port": 9443,
			"servers": {
				"srv0": {
					"listen": [
						":8443"
					],
					"routes": [
						{
							"match": [
								{
									"host": [
										"localhost"
									]
								}
							],
							"handle": [
								{
									"handler": "subroute",
									"routes": [
										{
											"handle": [
												{
													"body": "OK!",
													"handler": "static_response"
												}
											]
										}
									]
								}
							],
							"terminal": true
						}
					]
				}
			}
		},
		"pki": {
			"certificate_authorities": {
				"local": {
					"install_trust": false
				}
			}
		}
	}
}

Run Caddy with the following config:

{
	"admin": {
		"listen":"localhost:2019",
		"config": {
			"load": {
				"module": "storage"
			}
		}
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StorageLoader

type StorageLoader struct {
	// StorageRaw is a storage module that defines how/where Caddy
	// stores assets (such as TLS certificates). The default storage
	// module is `caddy.storage.file_system` (the local file system),
	// and the default path
	// [depends on the OS and environment](/docs/conventions#data-directory).
	StorageRaw json.RawMessage `json:"storage,omitempty" caddy:"namespace=caddy.storage inline_key=module"`

	// The storage key at which the configuration is to be found
	Key string `json:"key,omitempty"`

	// The adapter to use to convert the storage's contents to Caddy JSON.
	Adapter string `json:"adapter,omitempty"`
	// contains filtered or unexported fields
}

StorageLoader is a dynamic configuration loader that reads the configuration from a Caddy storage. If the storage is not configured, the default storage is used, which may be the file-system if none is configured If the `key` is not configured, the default key is `config/caddy.json`.

func (*StorageLoader) CaddyModule

func (*StorageLoader) CaddyModule() caddy.ModuleInfo

CaddyModule implements caddy.Module.

func (*StorageLoader) LoadConfig

func (sl *StorageLoader) LoadConfig(ctx caddy.Context) ([]byte, error)

LoadConfig reads the configuration from the storage

func (*StorageLoader) Provision

func (sl *StorageLoader) Provision(ctx caddy.Context) error

Provision implements caddy.Provisioner.

func (*StorageLoader) Validate added in v1.0.0

func (sl *StorageLoader) Validate() error

Validate checks for the prerequisites of the module, e.g. the adapter if configured.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL