grafana/pkg/tsdb/mssql/proxy.go
Andreas Christou ae84d16a6f
MSSQL: Simplify proxy logic (#86278)
* Simplify proxy dialer creation

- Set new dialer on connector
- Create MSSQL connector in a similar fashion to postgres

* Update test

* Fix lint

* More lint

* Use correct driver name
2024-04-19 22:03:26 +01:00

30 lines
752 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) 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
}