proxy

package module
v0.0.0-...-22dfcb7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: MIT Imports: 7 Imported by: 0

README

pg-rewrite-proxy

A reverse proxy for postgres which rewrites queries.

Arbitrary rewriting is supported by supplying an LUA script to the proxy application, with 'rewriteQuery' and 'rewriteParse' functions for rewriting the query. Note the latter is used for the extended query protocol. Rewriting query parameters supplied with Bind is not yet supported.

Failure to rewrite the query will raise a NOTICE but it will not cause an error.

All other messages than Query are passed to the upstream unmodified. SSL connections are not supported.

Binaries for linux amd64 and arm64 are available on the releases page. For other architectures please build from source.

Prerequisites:

  • Go 1.17 or greater

Build from source:

CGO_ENABLED=0 go build -o pg-rewrite-proxy cmd/main.go

Usage:

./pg-rewrite-proxy --help

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunProxy

func RunProxy(ln net.Listener, upstream string, rewriterFactory QueryRewriterFactory) error

Types

type LuaQueryRewriter

type LuaQueryRewriter struct {
	// contains filtered or unexported fields
}

LUA interpreter implementation

func (*LuaQueryRewriter) Close

func (r *LuaQueryRewriter) Close() error

func (*LuaQueryRewriter) RewriteParse

func (r *LuaQueryRewriter) RewriteParse(query string) (string, error)

func (*LuaQueryRewriter) RewriteQuery

func (r *LuaQueryRewriter) RewriteQuery(query string) (string, error)

type LuaQueryRewriterFactory

type LuaQueryRewriterFactory struct {
	// contains filtered or unexported fields
}

func (*LuaQueryRewriterFactory) Create

type PgRewriteProxy

type PgRewriteProxy struct {
	// contains filtered or unexported fields
}

func NewPgRewriteProxy

func NewPgRewriteProxy(clientConn, upstreamConn net.Conn, rewriterFactory QueryRewriterFactory) *PgRewriteProxy

func (*PgRewriteProxy) Close

func (p *PgRewriteProxy) Close() error

func (*PgRewriteProxy) Run

func (p *PgRewriteProxy) Run() error

type QueryRewriter

type QueryRewriter interface {
	RewriteQuery(string) (string, error)
	RewriteParse(string) (string, error)
}

Generic query rewriter interface

type QueryRewriterFactory

type QueryRewriterFactory interface {
	Create() (QueryRewriter, error)
}

/ Rewriters will be constructed per goroutine, as some of them may have state that isn't safe to share

func NewLuaQueryRewriterFactory

func NewLuaQueryRewriterFactory(luaFile string) QueryRewriterFactory

type StringRewriter

type StringRewriter struct {
	// contains filtered or unexported fields
}

Dumb String replacement implementation

func (*StringRewriter) RewriteParse

func (r *StringRewriter) RewriteParse(query string) (string, error)

func (*StringRewriter) RewriteQuery

func (r *StringRewriter) RewriteQuery(query string) (string, error)

type StringRewriterFactory

type StringRewriterFactory struct {
	// contains filtered or unexported fields
}

func NewStringRewriterFactory

func NewStringRewriterFactory(replacments map[string]string) *StringRewriterFactory

func (*StringRewriterFactory) Create

func (r *StringRewriterFactory) Create() (QueryRewriter, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL