github.com/blend/go-sdk@v1.20220411.3/r2/opt_tls_client_cert_file_pair.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package r2
     9  
    10  import "crypto/tls"
    11  
    12  // OptTLSClientCertFilePair adds a client cert and key to the request.
    13  func OptTLSClientCertFilePair(certFile, keyFile string) Option {
    14  	return func(r *Request) error {
    15  		transport, err := EnsureHTTPTransport(r)
    16  		if err != nil {
    17  			return err
    18  		}
    19  
    20  		if transport.TLSClientConfig == nil {
    21  			transport.TLSClientConfig = &tls.Config{}
    22  		}
    23  		cert, err := tls.LoadX509KeyPair(certFile, keyFile)
    24  		if err != nil {
    25  			return err
    26  		}
    27  		transport.TLSClientConfig.Certificates = append(transport.TLSClientConfig.Certificates, cert)
    28  		return nil
    29  	}
    30  }