// HandleConnection accepts connection from a Postgres client, authenticates
// it and proxies it to an appropriate database service.
HandleConnection accepts connection from a Postgres client, authenticates
it and proxies it to an appropriate database service.
// HandleConnection accepts connection from a Postgres client authenticates // it and proxies it to an appropriate database service .
func (p *Proxy) HandleConnection(ctx context.Context, clientConn net.Conn) (err error) {
	startupMessage, tlsConn, backend, err := p.handleStartup(ctx, clientConn)
	if err != nil {
		return trace.Wrap(err)
	}
	defer func() {
		if err != nil {
			if err := backend.Send(toErrorResponse(err)); err != nil {
				p.Log.WithError(err).Warn("Failed to send error to backend.")
			}
		}
	}()
	ctx, err = p.Middleware.WrapContextWithUser(ctx, tlsConn)
	if err != nil {
		return trace.Wrap(err)
	}
	siteConn, err := p.ConnectToSite(ctx)
	if err != nil {
		return trace.Wrap(err)
	}
	defer siteConn.Close()
	err = p.proxyToSite(ctx, tlsConn, siteConn, startupMessage)
	if err != nil {
		return trace.Wrap(err)
	}
	return nil
}
func ( p * Proxy ) HandleConnection ( ctx context . Context , clientConn net . Conn ) ( err error ) { startupMessage , tlsConn , backend , err := p . handleStartup ( ctx , clientConn ) if err != nil { return trace . Wrap ( err ) } defer func ( ) { if err != nil { if err := backend . Send ( toErrorResponse ( err ) ) ; err != nil { p . Log . WithError ( err ) . Warn ( " " ) } } } ( ) ctx , err = p . Middleware . WrapContextWithUser ( ctx , tlsConn ) if err != nil { return trace . Wrap ( err ) } siteConn , err := p . ConnectToSite ( ctx ) if err != nil { return trace . Wrap ( err ) } defer siteConn . Close ( ) err = p . proxyToSite ( ctx , tlsConn , siteConn , startupMessage ) if err != nil { return trace . Wrap ( err ) } return nil }
HandleConnection accepts connection from a Postgres client, authenticates
it and proxies it to an appropriate database service.
HandleConnection accepts connection from a Postgres client authenticates it and proxies it to an appropriate database service .