From 1d338e266441d64963d9ff93d343074f4d87bb15 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Tue, 15 Mar 2016 09:09:40 +0100 Subject: Flatten config tree --- cmd/acme/config.go | 79 ++++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 44 deletions(-) (limited to 'cmd/acme/config.go') diff --git a/cmd/acme/config.go b/cmd/acme/config.go index bec6a19..693f827 100644 --- a/cmd/acme/config.go +++ b/cmd/acme/config.go @@ -27,13 +27,9 @@ type Config struct { ListenTLS string BaseDir string KeySize int - Provider []provider - Hook map[string]string -} - -type provider struct { Directory string Account []account + Hook map[string]string } type account struct { @@ -92,52 +88,47 @@ func LoadConfig(fname string) (*Config, error) { if c.KeySize == 0 { c.KeySize = defKeySize } + if c.Directory == "" { + c.Directory = acme.LE1 + } - replace := func(s string) string { return strings.Replace(s, ".", "_", -1) } - - for i, pro := range c.Provider { - if pro.Directory == "" { - pro.Directory = acme.LE1 + for i, acc := range c.Account { + if acc.KeySize == 0 { + acc.KeySize = c.KeySize } - c.Provider[i] = pro - 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) + } + c.Account[i] = acc + for i, dom := range acc.Domain { + if dom.Gracetime != 0 { + dom.Gracetime = c.Gracetime } - if acc.Mail == "" { - return nil, errNoMail + if dom.KeySize == 0 { + dom.KeySize = c.KeySize } - if acc.KeyFile == "" { - return nil, errNoKey + if len(dom.Altnames) == 0 { + return nil, errNoAltNames } - if c.BaseDir != "" { - acc.KeyFile = path.Join(c.BaseDir, acc.KeyFile) + dom.Altnames = checkWWW(dom.Altnames) + d := dom.Altnames[0] + if dom.KeyFile == "" { + dom.KeyFile = path.Join(keyPath, d+".key") + } + if dom.CrtFile == "" { + dom.CrtFile = path.Join(crtPath, d+".pem") } - pro.Account[i] = acc - for i, dom := range acc.Domain { - if dom.Gracetime != 0 { - dom.Gracetime = c.Gracetime - } - if dom.KeySize == 0 { - dom.KeySize = c.KeySize - } - if len(dom.Altnames) == 0 { - return nil, errNoAltNames - } - dom.Altnames = checkWWW(dom.Altnames) - d := dom.Altnames[0] - if dom.KeyFile == "" { - dom.KeyFile = path.Join(keyPath, replace(d)+".key") - } - if dom.CrtFile == "" { - dom.CrtFile = path.Join(crtPath, replace(d)+".pem") - } - if c.BaseDir != "" { - dom.KeyFile = path.Join(c.BaseDir, dom.KeyFile) - dom.CrtFile = path.Join(c.BaseDir, dom.CrtFile) - } - acc.Domain[i] = dom + if c.BaseDir != "" { + dom.KeyFile = path.Join(c.BaseDir, dom.KeyFile) + dom.CrtFile = path.Join(c.BaseDir, dom.CrtFile) } + acc.Domain[i] = dom } } -- cgit v1.2.3