proxy_http

package
v0.0.0-...-0c02112 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2023 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Overview

Package proxy_http provides common HTTP handlers to use in application.

Index

Constants

This section is empty.

Variables

View Source
var Version = "development"

Functions

func AsyncSearchProxy

func AsyncSearchProxy(c *HandlerContext) bool

func BulkProxy

func BulkProxy(c *HandlerContext) bool

func CountProxy

func CountProxy(c *HandlerContext) (handled bool)

func Forward

func Forward(t *Config, w http.ResponseWriter, r *http.Request) bool

Forward forwards query to ElasticSearch if it's configured and returns true. Otherwise does nothing and returns false.

func MappingProxy

func MappingProxy(c *HandlerContext) bool

MappingProxy handles GET endpoint for Mapping API

See: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html

func Ping

func Ping(t *Config, w http.ResponseWriter, r *http.Request) bool

func ReverseProxyForConfig

func ReverseProxyForConfig(cfg *Config) (http.HandlerFunc, error)

func SearchProxy

func SearchProxy(c *HandlerContext) bool

func VersionHandler

func VersionHandler(w http.ResponseWriter, r *http.Request)

Types

type Config

type Config struct {
	Elastic struct {
		EndPoint   string `json:"endpoint,omitempty"`
		User       string `json:"user,omitempty"`
		Password   string `json:"password,omitempty"`
		ESPassword string `json:"esPassword,omitempty"`
		IgnoreCert bool   `json:"ignoreCert,omitempty"`
	} `json:"elastic,omitempty"`
	Sneller            configSneller            `json:"sneller,omitempty"`
	Mapping            map[string]*mappingEntry `json:"mapping"`
	CompareWithElastic bool                     `json:"compareWithElastic,omitempty"`
}

type DummyCache

type DummyCache struct{}

DummyCache is a MappingCache that does not support storing and always fetches nothing.

func (DummyCache) Fetch

func (d DummyCache) Fetch(idxName string) (*ElasticMapping, error)

func (DummyCache) Store

func (d DummyCache) Store(idxName string, mapping *ElasticMapping) error

type ElasticMapping

type ElasticMapping = elastic_proxy.ElasticMapping

type HandlerContext

type HandlerContext struct {
	Request *http.Request
	Writer  http.ResponseWriter
	Config  *Config
	Logging *Logging
	Client  *http.Client
	Mapping *mappingEntry // currently selected mapping for an index
	Cache   MappingCache

	// function performing verbose logging
	VerboseLog func(string, ...any)

	// Flag indicating we're using verbose logging;
	// provided in case some logging activities might
	// cost more than a single VerboseLog call.
	Verbose bool

	Memcache struct {
		// Optional memcache client
		Client *memcache.Client
		// The ID used to distinguish ElasticProxy instances
		TenantID string
		// A string used to create a crypto key
		Secret string
		// Item expiration timeout
		ExpirationTime int
	}
}

HandlerContext is all data required to process an HTTP request.

func NewHandlerContext

func NewHandlerContext(config *Config, client *http.Client, w http.ResponseWriter, r *http.Request, verbose bool, verboseLog func(format string, v ...any)) *HandlerContext

NewHandlerContext creates a new context based on the ElasticSearch configuration and the handled request.

func (*HandlerContext) AddHeader

func (c *HandlerContext) AddHeader(k, v string)

func (*HandlerContext) Authenticate

func (c *HandlerContext) Authenticate(username, password string) bool

func (*HandlerContext) BadRequest

func (c *HandlerContext) BadRequest(s string, args ...any)

func (*HandlerContext) Error

func (c *HandlerContext) Error(status int, s string, args ...any)

func (*HandlerContext) HasSnellerEndpoint

func (c *HandlerContext) HasSnellerEndpoint() bool

func (*HandlerContext) InternalServerError

func (c *HandlerContext) InternalServerError(s string, args ...any)

func (*HandlerContext) NeedsAuthentication

func (c *HandlerContext) NeedsAuthentication() bool

func (*HandlerContext) NotFound

func (c *HandlerContext) NotFound(s string, args ...any)

func (*HandlerContext) SelectIndex

func (c *HandlerContext) SelectIndex(index string) bool

type LogDetail

type LogDetail struct {
	LogRequest       bool
	LogQueryParams   bool
	LogSQL           bool
	LogSnellerResult bool
	LogPreprocessed  bool
	LogResult        bool
}

type Logging

type Logging struct {
	Revision       string                       `json:"revision"`
	SourceIP       string                       `json:"sourceIp"`
	TenantID       string                       `json:"tenantId,omitempty"`
	QueryID        string                       `json:"queryId"`
	Start          time.Time                    `json:"start"`
	Index          string                       `json:"index"`
	Duration       time.Duration                `json:"duration"`
	HttpStatusCode int                          `json:"httpStatusCode"`
	Sneller        *SnellerLogging              `json:"sneller,omitempty"`
	Request        map[string]any               `json:"request,omitempty"`
	QueryParams    url.Values                   `json:"queryParameters,omitempty"`
	SQL            string                       `json:"sql,omitempty"`
	SnellerResult  map[string]any               `json:"snellerResult,omitempty"`
	Preprocessed   map[string]any               `json:"preprocessed,omitempty"`
	Result         *elastic_proxy.ElasticResult `json:"result,omitempty"`
	ElasticResult  map[string]any               `json:"elasticResult,omitempty"`
	ElasticDiff    string                       `json:"diff,omitempty"`
}

type MappingCache

type MappingCache interface {
	// Store saves ElasticMapping entry for given database and table.
	Store(idxName string, mapping *ElasticMapping) error

	// Fetch loads ElasticMapping entry for given database and table.
	// It returns nil, false if no mapping was found.
	Fetch(idxName string) (*ElasticMapping, error)
}

MappingCache is an interaface to cache ElasticMapping data

Key is constructed from database and table names.

type MemcacheMappingCache

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

MemcacheMappingCache is a MappingCache backed by memcached

func NewMemcacheMappingCache

func NewMemcacheMappingCache(client *memcache.Client, tenantID string, secret string, defaultExpiration int) *MemcacheMappingCache

NewMemcacheMappingCache creates new MemcacheMappingCache instance.

func (*MemcacheMappingCache) Fetch

func (m *MemcacheMappingCache) Fetch(idxName string) (*ElasticMapping, error)

func (*MemcacheMappingCache) Store

func (m *MemcacheMappingCache) Store(idxName string, mapping *ElasticMapping) error

type SnellerLogging

type SnellerLogging struct {
	EndPoint     string               `json:"endpoint"`
	Sources      []mappingEntrySource `json:"sources"`
	TokenLast4   string               `json:"tokenLast4"`
	CacheHits    int                  `json:"cacheHits,omitempty"`
	CacheMisses  int                  `json:"cacheMisses,omitempty"`
	BytesScanned int                  `json:"bytesScanned,omitempty"`
}

Jump to

Keyboard shortcuts

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