aboutsummaryrefslogtreecommitdiff
path: root/cmd/acmed/config.go
blob: 4130aabc5748611d84d2e9adea5162c7c9a82651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main

import (
	"crypto/rsa"

	"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
	Provider  string
	Account   string
	Basedir   string
	KeySize   int
}

type provider struct {
	Directory string
}

type account struct {
	Mail    string
	Phone   string
	Key     string
	KeySize int
	key     *rsa.PrivateKey `toml:"-"`
}

type hook struct {
	CMD string
}

type desire struct {
	Provider string
	Account  string
	Altnames []string
	Key      string
	KeySize  int
	Cert     string
	Webroot  string
	Hooks    []string
	key      *rsa.PrivateKey `toml:"-"`
}

func LoadConfig(fname string) (*Config, error) {
	c := &Config{}
	_, err := toml.DecodeFile(fname, c)
	return c, err
}

type Keychain interface {
	Path() string
	Size() int
}

func (d desire) Path() string  { return d.Key }
func (d desire) Size() int     { return d.KeySize }
func (a account) Path() string { return a.Key }
func (a account) Size() int    { return a.KeySize }