Marco Vito Moscaritolo 2e31a66bbd update dependencies (#20)
* update dependencies

* Update codebase to match with caddy changes in beta11
2019-12-29 14:55:01 -07:00

74 lines
1.8 KiB
Go

package caddy
import (
"encoding/json"
"fmt"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
"github.com/caddyserver/caddy/v2/modules/caddytls"
)
// StorageValues represents the config for certmagic storage providers.
type StorageValues struct {
Namespace string `json:"namespace"`
}
// Storage represents the certmagic storage configuration.
type Storage struct {
System string `json:"module"`
StorageValues
}
// Config represents a caddy2 config file.
type Config struct {
Storage Storage `json:"storage"`
Apps map[string]interface{} `json:"apps"`
}
// ControllerConfig represents ingress controller config received through cli arguments.
type ControllerConfig struct {
Email string
AutomaticTLS bool
TLSUseStaging bool
WatchNamespace string
}
// NewConfig returns a plain slate caddy2 config file.
func NewConfig(namespace string, cfg ControllerConfig) *Config {
autoPolicyBytes := json.RawMessage(fmt.Sprintf(`{"module": "acme", "email": "%v"}`, cfg.Email))
return &Config{
Storage: Storage{
System: "secret_store",
StorageValues: StorageValues{
Namespace: namespace,
},
},
Apps: map[string]interface{}{
"tls": caddytls.TLS{
Automation: &caddytls.AutomationConfig{
Policies: []caddytls.AutomationPolicy{
caddytls.AutomationPolicy{
Hosts: nil,
ManagementRaw: autoPolicyBytes,
},
},
},
CertificatesRaw: caddy.ModuleMap{},
},
"http": caddyhttp.App{
Servers: map[string]*caddyhttp.Server{
"ingress_server": &caddyhttp.Server{
AutoHTTPS: &caddyhttp.AutoHTTPSConfig{
Disabled: !cfg.AutomaticTLS,
Skip: make([]string, 0),
},
Listen: []string{":80", ":443"},
},
},
},
},
}
}