Skip to content

Commit

Permalink
Merge pull request #41 from ethpandaops/feat/tls
Browse files Browse the repository at this point in the history
feat: tls
  • Loading branch information
Savid authored Jan 16, 2023
2 parents 224319e + df43c6c commit ddda3f8
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 3 deletions.
1 change: 1 addition & 0 deletions example_discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ metricsAddr: ":9090"

coordinator:
address: localhost:8080
tls: false
headers:
Authorization: Someb64Value
max_queue_size: 51200
Expand Down
13 changes: 12 additions & 1 deletion example_mimicry.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ coordinator:
# max_peers: 100

outputs:
- name: basic
- name: http-sink
type: http
config:
address: http://localhost:8080
Expand All @@ -41,3 +41,14 @@ outputs:
batch_timeout: 5s
export_timeout: 30s
max_export_batch_size: 512
- name: xatu-server
type: xatu
config:
address: localhost:8080
tls: false
headers:
Authorization: Someb64Value
max_queue_size: 51200
batch_timeout: 5s
export_timeout: 30s
max_export_batch_size: 512
1 change: 1 addition & 0 deletions pkg/discovery/coordinator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Config struct {
Address string `yaml:"address"`
Headers map[string]string `yaml:"headers"`
TLS bool `yaml:"tls" default:"false"`
MaxQueueSize int `yaml:"max_queue_size" default:"51200"`
BatchTimeout time.Duration `yaml:"batch_timeout" default:"5s"`
ExportTimeout time.Duration `yaml:"export_timeout" default:"30s"`
Expand Down
14 changes: 13 additions & 1 deletion pkg/discovery/coordinator/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package coordinator
import (
"context"
"fmt"
"net"

pb "github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/metadata"
Expand All @@ -22,7 +24,17 @@ type ItemExporter struct {

func NewItemExporter(config *Config, log logrus.FieldLogger) (ItemExporter, error) {
var opts []grpc.DialOption
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))

if config.TLS {
host, _, err := net.SplitHostPort(config.Address)
if err != nil {
return ItemExporter{}, fmt.Errorf("fail to get host from address: %v", err)
}

opts = append(opts, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, host)))
} else {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

conn, err := grpc.Dial(config.Address, opts...)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/output/xatu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
type Config struct {
Address string `yaml:"address"`
Headers map[string]string `yaml:"headers"`
TLS bool `yaml:"tls" default:"false"`
MaxQueueSize int `yaml:"max_queue_size" default:"51200"`
BatchTimeout time.Duration `yaml:"batch_timeout" default:"5s"`
ExportTimeout time.Duration `yaml:"export_timeout" default:"30s"`
Expand Down
14 changes: 13 additions & 1 deletion pkg/output/xatu/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package xatu
import (
"context"
"fmt"
"net"

pb "github.com/ethpandaops/xatu/pkg/proto/xatu"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org/grpc/metadata"
Expand All @@ -22,7 +24,17 @@ type ItemExporter struct {

func NewItemExporter(config *Config, log logrus.FieldLogger) (ItemExporter, error) {
var opts []grpc.DialOption
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))

if config.TLS {
host, _, err := net.SplitHostPort(config.Address)
if err != nil {
return ItemExporter{}, fmt.Errorf("fail to get host from address: %v", err)
}

opts = append(opts, grpc.WithTransportCredentials(credentials.NewClientTLSFromCert(nil, host)))
} else {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

conn, err := grpc.Dial(config.Address, opts...)
if err != nil {
Expand Down

0 comments on commit ddda3f8

Please sign in to comment.