-
Notifications
You must be signed in to change notification settings - Fork 0
/
cert_repo_context.go
83 lines (65 loc) · 1.52 KB
/
cert_repo_context.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package contexts
import (
"time"
"github.com/bitwormhole/git-acme-commands/app/config"
"github.com/starter-go/afs"
)
// CertRepoContext 包含关于一个证书仓库的上下文信息
type CertRepoContext struct {
Parent *GitRepoContext
// files
DomainListFile afs.Path // at '.git/../acme.config'
LocalConfigFile afs.Path // at '.git/../acme-local.config'
MainConfigFile afs.Path // at '.git/../acme-domains.list'
// config
// ConfigProperties properties.Table
MainConfig *config.VO
LocalConfig *config.VO
MixedConfig *config.VO
// domains
DomainList []*DomainListItem
Domains map[string]*DomainListItem
// time
Now time.Time
SessionTime time.Time
SessionInterval time.Duration
}
// LoadConfig ...
func (inst *CertRepoContext) LoadConfig() error {
fileM := inst.MainConfigFile
fileL := inst.LocalConfigFile
cfgM, err := config.Load(fileM)
if err != nil {
return err
}
cfgL, err := config.Load(fileL)
if err != nil {
return err
}
cfgX := config.Mix(cfgM, cfgL)
inst.MixedConfig = cfgX
inst.MainConfig = cfgM
inst.LocalConfig = cfgL
return nil
}
// LoadDomainList ...
func (inst *CertRepoContext) LoadDomainList() error {
file := inst.DomainListFile
text, err := file.GetIO().ReadText(nil)
if err != nil {
return err
}
list, err := parseDomainList(text)
if err != nil {
return err
}
table := make(map[string]*DomainListItem)
for _, item := range list {
if item.Enabled {
table[item.Domain] = item
}
}
inst.DomainList = list
inst.Domains = table
return nil
}