-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathconfig.go
68 lines (56 loc) · 1.97 KB
/
config.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
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package remote
import (
"fmt"
"time"
"github.com/elastic/elastic-agent-libs/transport/httpcommon"
)
// Config is the configuration for the client.
type Config struct {
Protocol Protocol `config:"protocol" yaml:"protocol"`
SpaceID string `config:"space.id" yaml:"space.id,omitempty"`
Path string `config:"path" yaml:"path,omitempty"`
Host string `config:"host" yaml:"host,omitempty"`
Hosts []string `config:"hosts" yaml:"hosts,omitempty"`
Transport httpcommon.HTTPTransportSettings `config:",inline" yaml:",inline"`
}
// Protocol define the protocol to use to make the connection. (Either HTTPS or HTTP)
type Protocol string
const (
// ProtocolHTTP is HTTP protocol connection.
ProtocolHTTP Protocol = "http"
// ProtocolHTTPS is HTTPS protocol connection.
ProtocolHTTPS Protocol = "https"
)
// Unpack the protocol.
func (p *Protocol) Unpack(from string) error {
if Protocol(from) != ProtocolHTTPS && Protocol(from) != ProtocolHTTP {
return fmt.Errorf("invalid protocol %s, accepted values are 'http' and 'https'", from)
}
*p = Protocol(from)
return nil
}
// DefaultClientConfig creates default configuration for client.
func DefaultClientConfig() Config {
transport := httpcommon.DefaultHTTPTransportSettings()
// Default timeout 10 minutes, expecting Fleet Server to control the long poll with default timeout of 5 minutes
transport.Timeout = 10 * time.Minute
return Config{
Protocol: ProtocolHTTP,
Host: "localhost:5601",
Path: "",
SpaceID: "",
Transport: transport,
}
}
// GetHosts returns the hosts to connect.
//
// This looks first at `Hosts` and then at `Host` when `Hosts` is not defined.
func (c *Config) GetHosts() []string {
if len(c.Hosts) > 0 {
return c.Hosts
}
return []string{c.Host}
}