@@ -38,6 +38,10 @@ const (
3838 // Default value whether to skip checking insecure certs on TLS connections.
3939 defaultTlsInsecureSkipVerify = false
4040 defaultReadTimeout = time .Duration (0 ) // Read() will not time out
41+
42+ // Default values for cert and key pair
43+ defaultTlsCertFile = ""
44+ defaultTlsKeyFile = ""
4145)
4246
4347// randomGenerator is used by getUniqueId to generate ack hashes. Its value is replaced
@@ -82,6 +86,10 @@ type Config struct {
8286
8387 // ReadTimeout specifies the timeout on reads. Currently only acks are read.
8488 ReadTimeout time.Duration `json:"read_timeout"`
89+
90+ // Cert file and key file
91+ TlsCertFile string `json: "tls_cert_file"`
92+ TlsKeyFile string `json: "tls_key_file"`
8593}
8694
8795type ErrUnknownNetwork struct {
@@ -171,6 +179,12 @@ func newWithDialer(config Config, d dialer) (f *Fluent, err error) {
171179 if ! config .TlsInsecureSkipVerify {
172180 config .TlsInsecureSkipVerify = defaultTlsInsecureSkipVerify
173181 }
182+ if config .TlsCertFile == "" {
183+ config .TlsCertFile = defaultTlsCertFile
184+ }
185+ if config .TlsKeyFile == "" {
186+ config .TlsKeyFile = defaultTlsKeyFile
187+ }
174188 if config .AsyncConnect {
175189 fmt .Fprintf (os .Stderr , "fluent#New: AsyncConnect is now deprecated, please use Async instead" )
176190 config .Async = config .Async || config .AsyncConnect
@@ -465,6 +479,13 @@ func (f *Fluent) connect(ctx context.Context) (err error) {
465479 f .Config .FluentHost + ":" + strconv .Itoa (f .Config .FluentPort ))
466480 case "tls" :
467481 tlsConfig := & tls.Config {InsecureSkipVerify : f .Config .TlsInsecureSkipVerify }
482+ if (f .Config .TlsCertFile != "" ) && (f .Config .TlsKeyFile != "" ) {
483+ cert , err := tls .LoadX509KeyPair (f .Config .TlsCertFile , f .Config .TlsKeyFile )
484+ if err != nil {
485+ return err
486+ }
487+ tlsConfig = & tls.Config {Certificates : []tls.Certificate {cert }, InsecureSkipVerify : f .Config .TlsInsecureSkipVerify }
488+ }
468489 f .conn , err = tls .DialWithDialer (
469490 & net.Dialer {Timeout : f .Config .Timeout },
470491 "tcp" ,
0 commit comments