@@ -2,9 +2,10 @@ package config
2
2
3
3
import (
4
4
"fmt"
5
- "google.golang.org/appengine"
6
5
"path"
7
6
"time"
7
+
8
+ "google.golang.org/appengine"
8
9
)
9
10
10
11
const (
@@ -25,15 +26,15 @@ type DnsProvider struct {
25
26
SecretKey string `toml:"secretKey" json:"secret_key,omitempty"`
26
27
}
27
28
28
- func (p DnsProvider ) Validate () error {
29
+ func (p * DnsProvider ) Validate () error {
29
30
switch p .Type {
30
31
case DnsProviderTypeCloudflare :
31
32
if p .Email == "" || p .APIKey == "" {
32
- return fmt .Errorf ("DnsProvider Cloudflare: empty email or key " )
33
+ return fmt .Errorf ("DnsProvider Cloudflare: empty Email or APIKey " )
33
34
}
34
35
case DnsProviderTypeTencentCloud :
35
36
if p .SecretID == "" || p .SecretKey == "" {
36
- return fmt .Errorf ("DnsProvider TencentCloud: empty email or key " )
37
+ return fmt .Errorf ("DnsProvider TencentCloud: empty SecretID or SecretKey " )
37
38
}
38
39
}
39
40
return nil
@@ -44,7 +45,8 @@ type ServerConfigT struct {
44
45
45
46
DnsProvider DnsProvider `toml:"DnsProvider" json:"dns_provider,omitempty"`
46
47
47
- HttpServer HttpServerConfig `toml:"HttpServer" json:"http_server,omitempty"`
48
+ HttpServer HttpServerConfig `toml:"HttpServer" json:"http_server,omitempty"`
49
+ GRPCSDSServer GRPCServerConfig `toml:"gRPCSDSServer" json:"grpc_sds_server,omitempty"`
48
50
}
49
51
50
52
type ACMEConfig struct {
@@ -59,7 +61,7 @@ type ACMEConfig struct {
59
61
RenewTimeLeftDuration time.Duration `toml:"-" json:"-"`
60
62
}
61
63
62
- func (c ACMEConfig ) Validate () error {
64
+ func (c * ACMEConfig ) Validate () error {
63
65
if len (c .AllowedDomains ) == 0 {
64
66
return fmt .Errorf ("AllowedDomains is empty" )
65
67
}
@@ -75,19 +77,33 @@ type HttpServerConfig struct {
75
77
Token string `toml:"token" json:"token,omitempty"`
76
78
}
77
79
78
- func (c HttpServerConfig ) Validate () error {
80
+ func (c * HttpServerConfig ) Validate () error {
81
+ if ! c .Enabled {
82
+ return nil
83
+ }
84
+
79
85
if c .Secure && len (c .Names ) == 0 {
80
86
return fmt .Errorf ("secure http server with no name" )
81
87
}
82
88
return nil
83
89
}
84
90
85
- // type GRPCServerConfig struct {
86
- // Listen string `toml:"listen"`
87
- // Secure bool `toml:"secure"`
88
- // Name string `toml:"name"`
89
- // Token string `toml:"token"`
90
- // }
91
+ type GRPCServerConfig struct {
92
+ Enabled bool `toml:"enabled" json:"enabled,omitempty"`
93
+ Listen string `toml:"listen" json:"listen,omitempty"`
94
+ Names []string `toml:"names" json:"names,omitempty"`
95
+ }
96
+
97
+ func (c * GRPCServerConfig ) Validate () error {
98
+ if ! c .Enabled {
99
+ return nil
100
+ }
101
+
102
+ if len (c .Names ) == 0 {
103
+ return fmt .Errorf ("no grpc server name" )
104
+ }
105
+ return nil
106
+ }
91
107
92
108
func (c * ServerConfigT ) SetDefault () {
93
109
c .ACME = ACMEConfig {
@@ -101,6 +117,10 @@ func (c *ServerConfigT) SetDefault() {
101
117
APIPath : "/" ,
102
118
Secure : false ,
103
119
}
120
+
121
+ c .GRPCSDSServer = GRPCServerConfig {
122
+ Listen : ":10002" ,
123
+ }
104
124
}
105
125
106
126
func (c * ServerConfigT ) Validate () error {
@@ -118,6 +138,10 @@ func (c *ServerConfigT) Validate() error {
118
138
ret = append (ret , err )
119
139
}
120
140
141
+ if err := c .GRPCSDSServer .Validate (); err != nil {
142
+ ret = append (ret , err )
143
+ }
144
+
121
145
if len (ret ) > 0 {
122
146
return ret
123
147
}
@@ -132,11 +156,6 @@ type ClientConfigT struct {
132
156
StandbyServer ClientHttpServer `toml:"StandbyServer" json:"standby_server,omitempty"`
133
157
} `toml:"Http" json:"http,omitempty"`
134
158
135
- // GRPC struct {
136
- // MainServer ClientGRPCServer `toml:"MainServer"`
137
- // StandbyServer ClientGRPCServer `toml:"StandbyServer"`
138
- // } `toml:"GRPC"`
139
-
140
159
Certifications []ClientCertification `toml:"Certifications" json:"certifications,omitempty"`
141
160
}
142
161
@@ -151,12 +170,6 @@ type ClientHttpServer struct {
151
170
Token string `toml:"token" json:"token,omitempty"`
152
171
}
153
172
154
- // type ClientGRPCServer struct {
155
- // Secure bool `toml:"secure"`
156
- // Server string `toml:"server"`
157
- // Token string `toml:"token"`
158
- // }
159
-
160
173
type ClientCertification struct {
161
174
Name string `toml:"name" json:"name,omitempty"`
162
175
SavePath string `toml:"savePath" json:"save_path,omitempty"`
0 commit comments