From b938499a5229f2daf77b44da960db5ec15cc3de8 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Fri, 26 Feb 2016 00:12:43 +0100 Subject: Alter config format --- cmd/acme/config.go | 91 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 41 deletions(-) (limited to 'cmd/acme/config.go') diff --git a/cmd/acme/config.go b/cmd/acme/config.go index e7a95a9..85d6600 100644 --- a/cmd/acme/config.go +++ b/cmd/acme/config.go @@ -2,6 +2,7 @@ package main import ( "errors" + "fmt" "io/ioutil" "os/user" "path" @@ -22,22 +23,24 @@ type Config struct { ListenTLS string BaseDir string KeySize int - Provider map[string]string - Account map[string]account - Desire map[string]desire + Provider []provider Hook map[string]string } +type provider struct { + Directory string + Account []account +} + type account struct { Mail string Phone string KeySize int KeyFile string + Desire []desire } type desire struct { - Provider string - Account string Altnames []string KeySize int KeyFile string @@ -55,6 +58,15 @@ var ( errNoMail = errors.New("no mail specified") ) +func Dump(c *Config) error { + out, err := yaml.Marshal(c) + if err != nil { + return err + } + fmt.Println(string(out)) + return nil +} + func LoadConfig(fname string) (*Config, error) { conf, err := ioutil.ReadFile(fname) if err != nil { @@ -79,44 +91,41 @@ func LoadConfig(fname string) (*Config, error) { if c.KeySize == 0 { c.KeySize = defKeySize } - for k, v := range c.Account { - if v.KeySize == 0 { - v.KeySize = c.KeySize - } - if v.Mail == "" { - return nil, errNoMail - } - if v.KeyFile == "" { - return nil, errNoKey - } - if c.BaseDir != "" { - v.KeyFile = path.Join(c.BaseDir, v.KeyFile) - } - c.Account[k] = v - } - for k, v := range c.Desire { - if v.Provider == "" { - return nil, errNoProvider - } - if v.Account == "" { - return nil, errNoAccount - } - if v.KeySize == 0 { - v.KeySize = c.KeySize - } - if v.KeyFile == "" { - return nil, errNoKey - } - if v.CrtFile == "" { - return nil, errNoCrt - } - if c.BaseDir != "" { - v.KeyFile = path.Join(c.BaseDir, v.KeyFile) - v.CrtFile = path.Join(c.BaseDir, v.CrtFile) + for _, pro := range c.Provider { + for i, acc := range pro.Account { + if acc.KeySize == 0 { + acc.KeySize = c.KeySize + } + if acc.Mail == "" { + return nil, errNoMail + } + if acc.KeyFile == "" { + return nil, errNoKey + } + if c.BaseDir != "" { + acc.KeyFile = path.Join(c.BaseDir, acc.KeyFile) + } + pro.Account[i] = acc + for i, des := range acc.Desire { + if des.KeySize == 0 { + des.KeySize = c.KeySize + } + if des.KeyFile == "" { + return nil, errNoKey + } + if des.CrtFile == "" { + return nil, errNoCrt + } + if c.BaseDir != "" { + des.KeyFile = path.Join(c.BaseDir, des.KeyFile) + des.CrtFile = path.Join(c.BaseDir, des.CrtFile) + } + des.Altnames = checkWWW(des.Altnames) + acc.Desire[i] = des + } } - v.Altnames = checkWWW(v.Altnames) - c.Desire[k] = v } + return c, nil } -- cgit v1.2.3