Skip to content

Commit

Permalink
add a target option that allows setting a whole TLS config instead of…
Browse files Browse the repository at this point in the history
… paths to cert files
  • Loading branch information
karimra committed Apr 25, 2024
1 parent a3dbbd3 commit 0363b84
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/api/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package api

import (
"crypto/tls"
"errors"
"strings"
"time"
Expand Down Expand Up @@ -165,6 +166,14 @@ func TLSVersion(v string) TargetOption {
}
}

// TLSConfig
func TLSConfig(tlsconfig *tls.Config) TargetOption {
return func(t *target.Target) error {
t.Config.SetTLSConfig(tlsconfig)
return nil
}
}

// LogTLSSecret, if set to true,
// enables logging of the TLS master key.
func LogTLSSecret(b bool) TargetOption {
Expand Down
9 changes: 9 additions & 0 deletions pkg/api/types/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ type TargetConfig struct {
CipherSuites []string `mapstructure:"cipher-suites,omitempty" yaml:"cipher-suites,omitempty" json:"cipher-suites,omitempty"`
TCPKeepalive time.Duration `mapstructure:"tcp-keepalive,omitempty" yaml:"tcp-keepalive,omitempty" json:"tcp-keepalive,omitempty"`
GRPCKeepalive *clientKeepalive `mapstructure:"grpc-keepalive,omitempty" yaml:"grpc-keepalive,omitempty" json:"grpc-keepalive,omitempty"`

tlsConfig *tls.Config
}

type clientKeepalive struct {
Expand All @@ -174,8 +176,15 @@ func (tc TargetConfig) String() string {
return string(b)
}

func (tc *TargetConfig) SetTLSConfig(tlsConfig *tls.Config) {
tc.tlsConfig = tlsConfig
}

// NewTLSConfig //
func (tc *TargetConfig) NewTLSConfig() (*tls.Config, error) {
if tc.tlsConfig != nil {
return tc.tlsConfig, nil
}
var ca, cert, key string
if tc.TLSCA != nil {
ca = *tc.TLSCA
Expand Down

0 comments on commit 0363b84

Please sign in to comment.