postgres: socks proxy: use plugin-sdk (#82376)

This commit is contained in:
Gábor Farkas
2024-02-14 13:05:31 +01:00
committed by GitHub
parent 7c44dd713a
commit 4c221966e4
5 changed files with 32 additions and 40 deletions

View File

@ -5,21 +5,13 @@ import (
"net"
"time"
sdkproxy "github.com/grafana/grafana-plugin-sdk-go/backend/proxy"
"github.com/lib/pq"
"golang.org/x/net/proxy"
)
// newPostgresProxyDriver updates the dialer for a postgres connector with a dialer that proxies connections through the secure socks proxy
// and returns a new postgres driver to register
func newPostgresProxyDialer(opts *sdkproxy.Options) (pq.Dialer, error) {
dialer, err := sdkproxy.New(opts).NewSecureSocksProxyContextDialer()
if err != nil {
return nil, err
}
// update the postgres dialer with the proxy dialer
return &postgresProxyDialer{d: dialer}, nil
// we wrap the proxy.Dialer to become dialer that the postgres module accepts
func newPostgresProxyDialer(dialer proxy.Dialer) pq.Dialer {
return &postgresProxyDialer{d: dialer}
}
var _ pq.Dialer = (&postgresProxyDialer{})