From cd20da69000a1b1a74a3814546c2bb204c4c0aa4 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 14 Dec 2015 18:48:45 +0100 Subject: Add config proposal --- acme.toml | 23 +++++++++++++++-------- cmd/conf/main.go | 16 ++++++++++++++++ config.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 8 deletions(-) create mode 100644 cmd/conf/main.go create mode 100644 config.go diff --git a/acme.toml b/acme.toml index 5476217..4bb71e7 100644 --- a/acme.toml +++ b/acme.toml @@ -1,13 +1,19 @@ +[defaults] +gracetime = "1 week" +listen = "localhost:8443" + [provider.lev1] directory = "https://acme-v01.api.letsencrypt.org/directory" [provider.les] directory = "https://acme-staging.api.letsencrypt.org/directory" +default = true [account.example] mail = "another@example.com" +phone = "+12025551212" key = "/etc/acme.key" -provider = "les" +default = true [hook.nginx] cmd = "sudo service nginx reload" @@ -18,19 +24,20 @@ cmd = "sudo service dovecot reload" [hook.smtpd] cmd = "sudo service smtpd reload" -[[desire]] +[desire.web] +provider = "les" +account = "example" altnames = [ "www.example.com", "example.com" ] key = "/etc/ssl/private/www_example_com.key" cert = "/etc/ssl/certs/www_example_com.pem" webroot = "/var/www/htdocs" -account = "example" -gracetime = "1 week" -hook = [ "nginx" ] +hooks = [ "nginx" ] -[[desire]] +[desire.mail] +provider = "les" +account = "example" altnames = [ "mail.example.com" ] key = "/etc/ssl/private/mail_example_com.key" cert = "/etc/ssl/certs/mail_example_com.pem" -account = "example" gracetime = "1 week" -hook = [ "dovecot", "smtpd" ] +hooks = [ "dovecot", "smtpd" ] diff --git a/cmd/conf/main.go b/cmd/conf/main.go new file mode 100644 index 0000000..fa59455 --- /dev/null +++ b/cmd/conf/main.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + + "dim13.org/acme" +) + +func main() { + c, _ := acme.LoadConfig("acme.toml") + for _, v := range c.Desire { + fmt.Println("Provider", c.Provider[v.Provider]) + fmt.Println("Account", c.Account[v.Account]) + fmt.Printf("%+v\n", v) + } +} diff --git a/config.go b/config.go new file mode 100644 index 0000000..7b3f256 --- /dev/null +++ b/config.go @@ -0,0 +1,46 @@ +package acme + +import "github.com/BurntSushi/toml" + +type Config struct { + Defaults defaults + Provider map[string]provider + Account map[string]account + Hook map[string]hook + Desire map[string]desire +} + +type defaults struct { + Gracetime string + Listen string +} + +type provider struct { + Directory string +} + +type account struct { + Mail string + Phone string + Key string +} + +type hook struct { + CMD string +} + +type desire struct { + Provider string + Account string + Altnames []string + Key string + Cert string + Webroot string + Hooks []string +} + +func LoadConfig(fname string) (*Config, error) { + c := &Config{} + _, err := toml.DecodeFile(fname, c) + return c, err +} -- cgit v1.2.3