Skip to content

Commit

Permalink
Refactor: Move existing class to tlscommon (#7055)
Browse files Browse the repository at this point in the history
  • Loading branch information
ph authored and kvch committed May 25, 2018
1 parent 8fa913c commit e8e61a9
Show file tree
Hide file tree
Showing 20 changed files with 88 additions and 83 deletions.
4 changes: 2 additions & 2 deletions heartbeat/monitors/active/http/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"

"github.com/elastic/beats/libbeat/common/match"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"

"github.com/elastic/beats/heartbeat/monitors"
)
Expand All @@ -26,7 +26,7 @@ type Config struct {
Password string `config:"password"`

// configure tls (if not configured HTTPS will use system defaults)
TLS *outputs.TLSConfig `config:"ssl"`
TLS *tlscommon.Config `config:"ssl"`

// http(s) ping validation
Check checkConfig `config:"check"`
Expand Down
4 changes: 2 additions & 2 deletions heartbeat/monitors/active/tcp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/outputs/transport"

"github.com/elastic/beats/heartbeat/monitors"
Expand All @@ -22,7 +22,7 @@ type Config struct {
Socks5 transport.ProxyConfig `config:",inline"`

// configure tls
TLS *outputs.TLSConfig `config:"ssl"`
TLS *tlscommon.Config `config:"ssl"`

Timeout time.Duration `config:"timeout"`

Expand Down
4 changes: 2 additions & 2 deletions heartbeat/scripts/generator/{{monitor}}/config.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package {{monitor}}
import (
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/outputs/transport"

"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/heartbeat/monitors"
)

Expand All @@ -19,7 +19,7 @@ type config struct {
Mode monitors.IPSettings `config:",inline"`

// configure tls
TLS *outputs.TLSConfig `config:"ssl"`
TLS *tlscommon.Config `config:"ssl"`

// configure validation
Check checkConfig `config:"check"`
Expand Down
28 changes: 14 additions & 14 deletions libbeat/monitoring/report/elasticsearch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@ package elasticsearch
import (
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
)

// config is subset of libbeat/outputs/elasticsearch config tailored
// for reporting metrics only
type config struct {
Hosts []string
Protocol string
Params map[string]string `config:"parameters"`
Headers map[string]string `config:"headers"`
Username string `config:"username"`
Password string `config:"password"`
ProxyURL string `config:"proxy_url"`
CompressionLevel int `config:"compression_level" validate:"min=0, max=9"`
TLS *outputs.TLSConfig `config:"ssl"`
MaxRetries int `config:"max_retries"`
Timeout time.Duration `config:"timeout"`
Period time.Duration `config:"period"`
BulkMaxSize int `config:"bulk_max_size" validate:"min=0"`
BufferSize int `config:"buffer_size"`
Tags []string `config:"tags"`
Params map[string]string `config:"parameters"`
Headers map[string]string `config:"headers"`
Username string `config:"username"`
Password string `config:"password"`
ProxyURL string `config:"proxy_url"`
CompressionLevel int `config:"compression_level" validate:"min=0, max=9"`
TLS *tlscommon.Config `config:"ssl"`
MaxRetries int `config:"max_retries"`
Timeout time.Duration `config:"timeout"`
Period time.Duration `config:"period"`
BulkMaxSize int `config:"bulk_max_size" validate:"min=0"`
BufferSize int `config:"buffer_size"`
Tags []string `config:"tags"`
}

var defaultConfig = config{
Expand Down
3 changes: 2 additions & 1 deletion libbeat/monitoring/report/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/monitoring"
"github.com/elastic/beats/libbeat/monitoring/report"
Expand Down Expand Up @@ -72,7 +73,7 @@ func makeReporter(beat beat.Info, cfg *common.Config) (report.Reporter, error) {
if proxyURL != nil {
logp.Info("Using proxy URL: %s", proxyURL)
}
tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
tlsConfig, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, err
}
Expand Down
30 changes: 15 additions & 15 deletions libbeat/outputs/elasticsearch/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package elasticsearch
import (
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
)

type elasticsearchConfig struct {
Protocol string `config:"protocol"`
Path string `config:"path"`
Params map[string]string `config:"parameters"`
Headers map[string]string `config:"headers"`
Username string `config:"username"`
Password string `config:"password"`
ProxyURL string `config:"proxy_url"`
LoadBalance bool `config:"loadbalance"`
CompressionLevel int `config:"compression_level" validate:"min=0, max=9"`
TLS *outputs.TLSConfig `config:"ssl"`
BulkMaxSize int `config:"bulk_max_size"`
MaxRetries int `config:"max_retries"`
Timeout time.Duration `config:"timeout"`
Backoff Backoff `config:"backoff"`
Protocol string `config:"protocol"`
Path string `config:"path"`
Params map[string]string `config:"parameters"`
Headers map[string]string `config:"headers"`
Username string `config:"username"`
Password string `config:"password"`
ProxyURL string `config:"proxy_url"`
LoadBalance bool `config:"loadbalance"`
CompressionLevel int `config:"compression_level" validate:"min=0, max=9"`
TLS *tlscommon.Config `config:"ssl"`
BulkMaxSize int `config:"bulk_max_size"`
MaxRetries int `config:"max_retries"`
Timeout time.Duration `config:"timeout"`
Backoff Backoff `config:"backoff"`
}

type Backoff struct {
Expand Down
5 changes: 3 additions & 2 deletions libbeat/outputs/elasticsearch/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/outputs/outil"
Expand Down Expand Up @@ -81,7 +82,7 @@ func makeES(
return outputs.Fail(err)
}

tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
tlsConfig, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return outputs.Fail(err)
}
Expand Down Expand Up @@ -188,7 +189,7 @@ func NewElasticsearchClients(cfg *common.Config) ([]Client, error) {
return nil, err
}

tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
tlsConfig, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, err
}
Expand Down
3 changes: 2 additions & 1 deletion libbeat/outputs/kafka/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/fmtstr"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/monitoring"
"github.com/elastic/beats/libbeat/monitoring/adapter"
Expand All @@ -19,7 +20,7 @@ import (

type kafkaConfig struct {
Hosts []string `config:"hosts" validate:"required"`
TLS *outputs.TLSConfig `config:"ssl"`
TLS *tlscommon.Config `config:"ssl"`
Timeout time.Duration `config:"timeout" validate:"min=1"`
Metadata metaConfig `config:"metadata"`
Key *fmtstr.EventFormatString `config:"key"`
Expand Down
4 changes: 2 additions & 2 deletions libbeat/outputs/logstash/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package logstash
import (
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/outputs/transport"
)

Expand All @@ -18,7 +18,7 @@ type Config struct {
Pipelining int `config:"pipelining" validate:"min=0"`
CompressionLevel int `config:"compression_level" validate:"min=0, max=9"`
MaxRetries int `config:"max_retries" validate:"min=-1"`
TLS *outputs.TLSConfig `config:"ssl"`
TLS *tlscommon.Config `config:"ssl"`
Proxy transport.ProxyConfig `config:",inline"`
Backoff Backoff `config:"backoff"`
}
Expand Down
3 changes: 2 additions & 1 deletion libbeat/outputs/logstash/logstash.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logstash
import (
"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/outputs/transport"
Expand Down Expand Up @@ -38,7 +39,7 @@ func makeLogstash(
return outputs.Fail(err)
}

tls, err := outputs.LoadTLSConfig(config.TLS)
tls, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return outputs.Fail(err)
}
Expand Down
4 changes: 2 additions & 2 deletions libbeat/outputs/redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"time"

"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/outputs/codec"
"github.com/elastic/beats/libbeat/outputs/transport"
)
Expand All @@ -20,7 +20,7 @@ type redisConfig struct {
Timeout time.Duration `config:"timeout"`
BulkMaxSize int `config:"bulk_max_size"`
MaxRetries int `config:"max_retries"`
TLS *outputs.TLSConfig `config:"ssl"`
TLS *tlscommon.Config `config:"ssl"`
Proxy transport.ProxyConfig `config:",inline"`
Codec codec.Config `config:"codec"`
Db int `config:"db"`
Expand Down
3 changes: 2 additions & 1 deletion libbeat/outputs/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/elastic/beats/libbeat/beat"
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/outputs/codec"
Expand Down Expand Up @@ -80,7 +81,7 @@ func makeRedis(
return outputs.Fail(err)
}

tls, err := outputs.LoadTLSConfig(config.TLS)
tls, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return outputs.Fail(err)
}
Expand Down
8 changes: 4 additions & 4 deletions libbeat/outputs/transport/transptest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"testing"
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/outputs/transport"
)

Expand Down Expand Up @@ -108,8 +108,8 @@ func NewMockServerTLS(t *testing.T, to time.Duration, cert string, proxy *transp
t.Fatalf("failed to generate TCP listener")
}

tlsConfig, err := outputs.LoadTLSConfig(&outputs.TLSConfig{
Certificate: outputs.CertificateConfig{
tlsConfig, err := tlscommon.LoadTLSConfig(&tlscommon.Config{
Certificate: tlscommon.CertificateConfig{
Certificate: cert + ".pem",
Key: cert + ".key",
},
Expand Down Expand Up @@ -158,7 +158,7 @@ func connectTCP(timeout time.Duration) TransportFactory {

func connectTLS(timeout time.Duration, certName string) TransportFactory {
return func(addr string, proxy *transport.ProxyConfig) (*transport.Client, error) {
tlsConfig, err := outputs.LoadTLSConfig(&outputs.TLSConfig{
tlsConfig, err := tlscommon.LoadTLSConfig(&tlscommon.Config{
CAs: []string{certName + ".pem"},
})
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions libbeat/setup/kibana/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"github.com/pkg/errors"

"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/logp"
"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/outputs/transport"
)

Expand Down Expand Up @@ -91,7 +91,7 @@ func NewKibanaClient(cfg *common.Config) (*Client, error) {

var dialer, tlsDialer transport.Dialer

tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
tlsConfig, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, fmt.Errorf("fail to load the TLS config: %v", err)
}
Expand Down
16 changes: 8 additions & 8 deletions libbeat/setup/kibana/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ package kibana
import (
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
)

type kibanaConfig struct {
Protocol string `config:"protocol"`
Host string `config:"host"`
Path string `config:"path"`
Username string `config:"username"`
Password string `config:"password"`
TLS *outputs.TLSConfig `config:"ssl"`
Timeout time.Duration `config:"timeout"`
Protocol string `config:"protocol"`
Host string `config:"host"`
Path string `config:"path"`
Username string `config:"username"`
Password string `config:"password"`
TLS *tlscommon.Config `config:"ssl"`
Timeout time.Duration `config:"timeout"`
}

var (
Expand Down
10 changes: 5 additions & 5 deletions metricbeat/helper/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/libbeat/outputs/transport"
"github.com/elastic/beats/metricbeat/mb"
)
Expand All @@ -27,9 +27,9 @@ type HTTP struct {
// NewHTTP creates new http helper
func NewHTTP(base mb.BaseMetricSet) (*HTTP, error) {
config := struct {
TLS *outputs.TLSConfig `config:"ssl"`
Timeout time.Duration `config:"timeout"`
Headers map[string]string `config:"headers"`
TLS *tlscommon.Config `config:"ssl"`
Timeout time.Duration `config:"timeout"`
Headers map[string]string `config:"headers"`
}{}
if err := base.Module().UnpackConfig(&config); err != nil {
return nil, err
Expand All @@ -39,7 +39,7 @@ func NewHTTP(base mb.BaseMetricSet) (*HTTP, error) {
config.Headers = map[string]string{}
}

tlsConfig, err := outputs.LoadTLSConfig(config.TLS)
tlsConfig, err := tlscommon.LoadTLSConfig(config.TLS)
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions metricbeat/module/kafka/consumergroup/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import (
"fmt"
"time"

"github.com/elastic/beats/libbeat/outputs"
"github.com/elastic/beats/libbeat/common/transport/tlscommon"
)

type metricsetConfig struct {
Retries int `config:"retries" validate:"min=0"`
Backoff time.Duration `config:"backoff" validate:"min=0"`
TLS *outputs.TLSConfig `config:"ssl"`
Username string `config:"username"`
Password string `config:"password"`
ClientID string `config:"client_id"`
Retries int `config:"retries" validate:"min=0"`
Backoff time.Duration `config:"backoff" validate:"min=0"`
TLS *tlscommon.Config `config:"ssl"`
Username string `config:"username"`
Password string `config:"password"`
ClientID string `config:"client_id"`

Groups []string `config:"groups"`
Topics []string `config:"topics"`
Expand Down
Loading

0 comments on commit e8e61a9

Please sign in to comment.