grafana/pkg/tsdb/mssql/proxy.go
Andreas Christou 28df41fd96
MSSQL: Add HostName method (#87309)
* Add HostName method

* Add test

* Fix lint
2024-05-03 15:45:34 +01:00

34 lines
819 B
Go

package mssql
import (
"context"
"errors"
"net"
mssql "github.com/microsoft/go-mssqldb"
"golang.org/x/net/proxy"
)
type HostTransportDialer struct {
Dialer proxy.ContextDialer
Host string
}
func (m HostTransportDialer) HostName() string {
return m.Host
}
func (m HostTransportDialer) DialContext(ctx context.Context, network string, addr string) (conn net.Conn, err error) {
return m.Dialer.DialContext(ctx, network, addr)
}
// // we wrap the proxy.Dialer to become dialer that the mssql module accepts
func newMSSQLProxyDialer(hostName string, dialer proxy.Dialer) (mssql.Dialer, error) {
contextDialer, ok := dialer.(proxy.ContextDialer)
if !ok {
return nil, errors.New("unable to cast socks proxy dialer to context proxy dialer")
}
return &HostTransportDialer{contextDialer, hostName}, nil
}