@@ -6,14 +6,11 @@ package config
66import (
77 "errors"
88 "fmt"
9- "net/http"
109 "os"
1110 "path/filepath"
1211 "sort"
13- "strings"
1412 "time"
1513
16- consulapi "github.com/hashicorp/consul/api"
1714 "github.com/hashicorp/go-multierror"
1815 "github.com/hashicorp/hcl/v2/hclsimple"
1916 "github.com/hashicorp/nomad-autoscaler/plugins"
@@ -66,9 +63,6 @@ type Agent struct {
6663 // Telemetry is the configuration used to setup metrics collection.
6764 Telemetry * Telemetry `hcl:"telemetry,block"`
6865
69- // Consul is used to configure a consul API client
70- Consul * Consul `hcl:"consul,block"`
71-
7266 APMs []* Plugin `hcl:"apm,block"`
7367 Targets []* Plugin `hcl:"target,block"`
7468 Strategies []* Plugin `hcl:"strategy,block"`
@@ -160,166 +154,6 @@ type Nomad struct {
160154 SkipVerify bool `hcl:"skip_verify,optional"`
161155}
162156
163- // Consul contains the configuration information necessary to
164- // communicate with a Consul server.
165- type Consul struct {
166- // Addr is the HTTP endpoint address of the local Consul agent
167- //
168- // Uses Consul's default and env var.
169- Addr string `hcl:"address"`
170-
171- // TimeoutHCL is used by Consul HTTP Client
172- TimeoutHCL string `hcl:"timeout" json:"-"`
173-
174- // Token is used to provide a per-request ACL token. This options overrides
175- // the agent's default token
176- Token string `hcl:"token"`
177-
178- // Auth is the information to use for http access to Consul agent
179- Auth string `hcl:"auth"`
180-
181- // EnableSSL sets the transport scheme to talk to the Consul agent as https
182- //
183- // Uses Consul's default and env var.
184- EnableSSL * bool `hcl:"ssl"`
185-
186- // VerifySSL enables or disables SSL verification when the transport scheme
187- // for the consul api client is https
188- //
189- // Uses Consul's default and env var.
190- VerifySSL * bool `hcl:"verify_ssl"`
191-
192- // CAFile is the path to the ca certificate used for Consul communication.
193- //
194- // Uses Consul's default and env var.
195- CAFile string `hcl:"ca_file"`
196-
197- // CertFile is the path to the certificate for Consul communication
198- CertFile string `hcl:"cert_file"`
199-
200- // KeyFile is the path to the private key for Consul communication
201- KeyFile string `hcl:"key_file"`
202-
203- // Namespace sets the Consul namespace used for all calls against the
204- // Consul API. If this is unset, then we don't specify a consul namespace.
205- Namespace string `hcl:"namespace"`
206-
207- // Datacenter sets the Consul datacenter used for all calls against the
208- // Consul API. If this is unset, then we don't specify a consul datacenter.
209- Datacenter string `hcl:"datacenter"`
210- }
211-
212- func (c * Consul ) MergeWithDefault () (* consulapi.Config , error ) {
213- if c == nil {
214- return nil , nil
215- }
216-
217- cfg := consulapi .DefaultConfig ()
218-
219- if c .Addr != "" {
220- cfg .Address = c .Addr
221- }
222- if c .Token != "" {
223- cfg .Token = c .Token
224- }
225- if c .TimeoutHCL != "" {
226- d , err := time .ParseDuration (c .TimeoutHCL )
227- if err != nil {
228- return nil , fmt .Errorf ("consul->timeout can't parse time duration %s" , c .TimeoutHCL )
229- }
230- // Create a custom Client to set the timeout
231- if cfg .HttpClient == nil {
232- cfg .HttpClient = & http.Client {}
233- }
234- cfg .HttpClient .Timeout = d
235- cfg .HttpClient .Transport = cfg .Transport
236- }
237- if c .Auth != "" {
238- var username , password string
239- if strings .Contains (c .Auth , ":" ) {
240- split := strings .SplitN (c .Auth , ":" , 2 )
241- username = split [0 ]
242- password = split [1 ]
243- } else {
244- username = c .Auth
245- }
246-
247- cfg .HttpAuth = & consulapi.HttpBasicAuth {
248- Username : username ,
249- Password : password ,
250- }
251- }
252- if c .EnableSSL != nil && * c .EnableSSL {
253- cfg .Scheme = "https"
254- cfg .TLSConfig = consulapi.TLSConfig {
255- Address : cfg .Address ,
256- CAFile : c .CAFile ,
257- CertFile : c .CertFile ,
258- KeyFile : c .KeyFile ,
259- }
260- if c .VerifySSL != nil {
261- cfg .TLSConfig .InsecureSkipVerify = ! * c .VerifySSL
262- }
263- tlsConfig , err := consulapi .SetupTLSConfig (& cfg .TLSConfig )
264- if err != nil {
265- return nil , err
266- }
267- cfg .Transport .TLSClientConfig = tlsConfig
268- }
269- if c .Namespace != "" {
270- cfg .Namespace = c .Namespace
271- }
272- if c .Datacenter != "" {
273- cfg .Datacenter = c .Datacenter
274- }
275-
276- return cfg , nil
277- }
278-
279- func (c * Consul ) merge (b * Consul ) * Consul {
280- if c == nil {
281- return b
282- }
283-
284- result := * c
285-
286- if b .Addr != "" {
287- result .Addr = b .Addr
288- }
289- if b .TimeoutHCL != "" {
290- result .TimeoutHCL = b .TimeoutHCL
291- }
292- if b .Datacenter != "" {
293- result .Datacenter = b .Datacenter
294- }
295- if b .Namespace != "" {
296- result .Namespace = b .Namespace
297- }
298- if b .Token != "" {
299- result .Token = b .Token
300- }
301- if b .Auth != "" {
302- result .Auth = b .Auth
303- }
304- if b .CAFile != "" {
305- result .CAFile = b .CAFile
306- }
307- if b .CertFile != "" {
308- result .CertFile = b .CertFile
309- }
310- if b .KeyFile != "" {
311- result .KeyFile = b .KeyFile
312- }
313- if b .EnableSSL != nil {
314- result .EnableSSL = b .EnableSSL
315- }
316- if b .VerifySSL != nil {
317- result .VerifySSL = b .VerifySSL
318- }
319-
320- return & result
321- }
322-
323157// Telemetry holds the user specified configuration for metrics collection.
324158type Telemetry struct {
325159
@@ -557,8 +391,7 @@ func Default() (*Agent, error) {
557391 BindAddress : defaultHTTPBindAddress ,
558392 BindPort : defaultHTTPBindPort ,
559393 },
560- Consul : nil ,
561- Nomad : & Nomad {},
394+ Nomad : & Nomad {},
562395 Telemetry : & Telemetry {
563396 CollectionInterval : defaultTelemetryCollectionInterval ,
564397 },
@@ -623,10 +456,6 @@ func (a *Agent) Merge(b *Agent) *Agent {
623456 result .Nomad = result .Nomad .merge (b .Nomad )
624457 }
625458
626- if b .Consul != nil {
627- result .Consul = result .Consul .merge (b .Consul )
628- }
629-
630459 if b .Telemetry != nil {
631460 result .Telemetry = result .Telemetry .merge (b .Telemetry )
632461 }
0 commit comments