Documentation
¶
Overview ¶
Package enterprise provides HAProxy Enterprise Edition configuration parsing.
This file contains extraction helpers for EE section field values. Directives are parsed from the UnProcessed parser and mapped to struct fields.
Package enterprise provides HAProxy Enterprise Edition configuration parsing.
This package implements a hybrid parser for HAProxy EE configurations that: 1. Uses client-native's parser for complete CE section extraction (global, defaults, frontends, backends, etc.) 2. Uses a custom line-by-line reader for EE-specific sections (waf-global, waf-profile, captcha, etc.) 3. Uses wrapper parsers to intercept EE directives in CE sections (filter waf, http-request waf-evaluate)
This hybrid approach maximizes code reuse from client-native while adding EE support.
Usage:
// Choose parser based on HAProxy version
if isEnterpriseEdition(haproxyVersion) {
parser := enterprise.NewParser()
config, err := parser.ParseFromString(configString)
} else {
parser, _ := parser.New()
config, err := parser.ParseFromString(configString)
}
Package enterprise provides HAProxy Enterprise Edition configuration parsing.
HAProxy EE extends CE in three dimensions: 1. New sections (udp-lb, waf-global, waf-profile, botmgmt-profile, captcha, dynamic-update) 2. New directives in existing sections (maxmind-load in global, filter waf in frontend) 3. New actions in existing directives (http-request waf-evaluate, botmgmt-evaluate)
This package provides a custom parser that handles EE-specific sections and wraps client-native parsers to intercept EE directives that client-native doesn't support.
Index ¶
- func IsAnySectionString(section string) bool
- func IsSingletonSection(section Section) bool
- type ConfiguredParsers
- type DefaultFactory
- func (f *DefaultFactory) CreateACMEParsers() *parser.Parsers
- func (f *DefaultFactory) CreateBackendParsers() *parser.Parsers
- func (f *DefaultFactory) CreateBotMgmtProfileParsers() *parser.Parsers
- func (f *DefaultFactory) CreateCacheParsers() *parser.Parsers
- func (f *DefaultFactory) CreateCaptchaParsers() *parser.Parsers
- func (f *DefaultFactory) CreateCommentsParsers() *parser.Parsers
- func (f *DefaultFactory) CreateCrtStoreParsers() *parser.Parsers
- func (f *DefaultFactory) CreateDefaultsParsers() *parser.Parsers
- func (f *DefaultFactory) CreateDynamicUpdateParsers() *parser.Parsers
- func (f *DefaultFactory) CreateFCGIAppParsers() *parser.Parsers
- func (f *DefaultFactory) CreateFrontendParsers() *parser.Parsers
- func (f *DefaultFactory) CreateGlobalParsers() *parser.Parsers
- func (f *DefaultFactory) CreateHTTPErrorsParsers() *parser.Parsers
- func (f *DefaultFactory) CreateListenParsers() *parser.Parsers
- func (f *DefaultFactory) CreateLogForwardParsers() *parser.Parsers
- func (f *DefaultFactory) CreateLogProfileParsers() *parser.Parsers
- func (f *DefaultFactory) CreateMailersParsers() *parser.Parsers
- func (f *DefaultFactory) CreatePeersParsers() *parser.Parsers
- func (f *DefaultFactory) CreateResolversParsers() *parser.Parsers
- func (f *DefaultFactory) CreateRingParsers() *parser.Parsers
- func (f *DefaultFactory) CreateTracesParsers() *parser.Parsers
- func (f *DefaultFactory) CreateUDPLBParsers() *parser.Parsers
- func (f *DefaultFactory) CreateUserlistParsers() *parser.Parsers
- func (f *DefaultFactory) CreateWAFGlobalParsers() *parser.Parsers
- func (f *DefaultFactory) CreateWAFProfileParsers() *parser.Parsers
- type EEBackendData
- type EEFrontendData
- type Parser
- type Reader
- type Section
- type StructuredConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAnySectionString ¶
IsAnySectionString returns true if the section string is any valid HAProxy section.
func IsSingletonSection ¶
IsSingletonSection returns true if the section can only appear once.
Types ¶
type ConfiguredParsers ¶
type ConfiguredParsers struct {
// State is the current section being parsed.
State Section
// Active is the parser collection for the current section.
Active *parser.Parsers
// SectionName is the name of the current named section.
SectionName string
// Comments holds comment line parsers.
Comments *parser.Parsers
// Global holds parsers for the global section.
// Extended with EE global parsers (maxmind-load, etc.) via wrapper.
Global *parser.Parsers
// Defaults holds parsers for the defaults section.
Defaults *parser.Parsers
// Frontend holds per-frontend parser collections.
// Key is frontend name. Extended with EE parsers (filter waf, http-request waf-evaluate).
Frontend map[string]*parser.Parsers
// Backend holds per-backend parser collections.
// Key is backend name.
Backend map[string]*parser.Parsers
// Listen holds per-listen parser collections.
// Key is listen name.
Listen map[string]*parser.Parsers
// Resolvers holds per-resolvers parser collections.
// Key is resolvers name.
Resolvers map[string]*parser.Parsers
// Peers holds per-peers parser collections.
// Key is peers name.
Peers map[string]*parser.Parsers
// Mailers holds per-mailers parser collections.
// Key is mailers name.
Mailers map[string]*parser.Parsers
// Cache holds per-cache parser collections.
// Key is cache name.
Cache map[string]*parser.Parsers
// HTTPErrors holds per-http-errors parser collections.
// Key is http-errors name.
HTTPErrors map[string]*parser.Parsers
// Ring holds per-ring parser collections.
// Key is ring name.
Ring map[string]*parser.Parsers
// LogForward holds per-log-forward parser collections.
// Key is log-forward name.
LogForward map[string]*parser.Parsers
// FCGIApp holds per-fcgi-app parser collections.
// Key is fcgi-app name.
FCGIApp map[string]*parser.Parsers
// CrtStore holds per-crt-store parser collections.
// Key is crt-store name.
CrtStore map[string]*parser.Parsers
// Traces holds per-traces parser collections.
// Key is traces name.
Traces map[string]*parser.Parsers
// LogProfile holds per-log-profile parser collections.
// Key is log-profile name.
LogProfile map[string]*parser.Parsers
// ACME holds per-acme parser collections.
// Key is acme name.
ACME map[string]*parser.Parsers
// Userlist holds per-userlist parser collections.
// Key is userlist name.
Userlist map[string]*parser.Parsers
// WAFGlobal holds parsers for the waf-global section (singleton).
WAFGlobal *parser.Parsers
// WAFProfile holds per-waf-profile parser collections.
// Key is profile name.
WAFProfile map[string]*parser.Parsers
// BotMgmtProfile holds per-botmgmt-profile parser collections.
// Key is profile name.
BotMgmtProfile map[string]*parser.Parsers
// Captcha holds per-captcha parser collections.
// Key is captcha name.
Captcha map[string]*parser.Parsers
// UDPLB holds per-udp-lb parser collections.
// Key is udp-lb name.
UDPLB map[string]*parser.Parsers
// DynamicUpdate holds per-dynamic-update parser collections.
// Key is dynamic-update name.
DynamicUpdate map[string]*parser.Parsers
}
ConfiguredParsers holds parser collections for all HAProxy sections. This extends the concept from client-native to include EE sections.
The struct mirrors client-native's internal ConfiguredParsers but adds fields for Enterprise Edition sections that client-native doesn't support.
func NewConfiguredParsers ¶
func NewConfiguredParsers() *ConfiguredParsers
NewConfiguredParsers creates a new ConfiguredParsers with initialized maps.
func (*ConfiguredParsers) GetSectionParsers ¶
func (c *ConfiguredParsers) GetSectionParsers(section Section, name string, factory *DefaultFactory) *parser.Parsers
GetSectionParsers returns the parser collection for a section. For named sections, creates a new collection if it doesn't exist.
type DefaultFactory ¶
type DefaultFactory struct{}
DefaultFactory creates parser collections for both CE and EE sections using client-native parsers.
func NewDefaultFactory ¶
func NewDefaultFactory() *DefaultFactory
NewDefaultFactory creates a new DefaultFactory.
func (*DefaultFactory) CreateACMEParsers ¶
func (f *DefaultFactory) CreateACMEParsers() *parser.Parsers
CreateACMEParsers creates parsers for acme sections.
func (*DefaultFactory) CreateBackendParsers ¶
func (f *DefaultFactory) CreateBackendParsers() *parser.Parsers
CreateBackendParsers creates parsers for backend sections. Uses wrapper parsers for http-request and filter to capture EE directives.
func (*DefaultFactory) CreateBotMgmtProfileParsers ¶
func (f *DefaultFactory) CreateBotMgmtProfileParsers() *parser.Parsers
CreateBotMgmtProfileParsers creates parsers for botmgmt-profile sections.
func (*DefaultFactory) CreateCacheParsers ¶
func (f *DefaultFactory) CreateCacheParsers() *parser.Parsers
CreateCacheParsers creates parsers for cache sections.
func (*DefaultFactory) CreateCaptchaParsers ¶
func (f *DefaultFactory) CreateCaptchaParsers() *parser.Parsers
CreateCaptchaParsers creates parsers for captcha sections.
func (*DefaultFactory) CreateCommentsParsers ¶
func (f *DefaultFactory) CreateCommentsParsers() *parser.Parsers
CreateCommentsParsers creates parsers for comment lines.
func (*DefaultFactory) CreateCrtStoreParsers ¶
func (f *DefaultFactory) CreateCrtStoreParsers() *parser.Parsers
CreateCrtStoreParsers creates parsers for crt-store sections.
func (*DefaultFactory) CreateDefaultsParsers ¶
func (f *DefaultFactory) CreateDefaultsParsers() *parser.Parsers
CreateDefaultsParsers creates parsers for the defaults section.
func (*DefaultFactory) CreateDynamicUpdateParsers ¶
func (f *DefaultFactory) CreateDynamicUpdateParsers() *parser.Parsers
CreateDynamicUpdateParsers creates parsers for dynamic-update sections.
func (*DefaultFactory) CreateFCGIAppParsers ¶
func (f *DefaultFactory) CreateFCGIAppParsers() *parser.Parsers
CreateFCGIAppParsers creates parsers for fcgi-app sections.
func (*DefaultFactory) CreateFrontendParsers ¶
func (f *DefaultFactory) CreateFrontendParsers() *parser.Parsers
CreateFrontendParsers creates parsers for frontend sections. Uses wrapper parsers for http-request and filter to capture EE directives.
func (*DefaultFactory) CreateGlobalParsers ¶
func (f *DefaultFactory) CreateGlobalParsers() *parser.Parsers
CreateGlobalParsers creates parsers for the global section. Includes EE parser for maxmind-load, waf-load, etc.
func (*DefaultFactory) CreateHTTPErrorsParsers ¶
func (f *DefaultFactory) CreateHTTPErrorsParsers() *parser.Parsers
CreateHTTPErrorsParsers creates parsers for http-errors sections.
func (*DefaultFactory) CreateListenParsers ¶
func (f *DefaultFactory) CreateListenParsers() *parser.Parsers
CreateListenParsers creates parsers for listen sections. Uses wrapper parsers for http-request and filter to capture EE directives.
func (*DefaultFactory) CreateLogForwardParsers ¶
func (f *DefaultFactory) CreateLogForwardParsers() *parser.Parsers
CreateLogForwardParsers creates parsers for log-forward sections.
func (*DefaultFactory) CreateLogProfileParsers ¶
func (f *DefaultFactory) CreateLogProfileParsers() *parser.Parsers
CreateLogProfileParsers creates parsers for log-profile sections.
func (*DefaultFactory) CreateMailersParsers ¶
func (f *DefaultFactory) CreateMailersParsers() *parser.Parsers
CreateMailersParsers creates parsers for mailers sections.
func (*DefaultFactory) CreatePeersParsers ¶
func (f *DefaultFactory) CreatePeersParsers() *parser.Parsers
CreatePeersParsers creates parsers for peers sections.
func (*DefaultFactory) CreateResolversParsers ¶
func (f *DefaultFactory) CreateResolversParsers() *parser.Parsers
CreateResolversParsers creates parsers for resolvers sections.
func (*DefaultFactory) CreateRingParsers ¶
func (f *DefaultFactory) CreateRingParsers() *parser.Parsers
CreateRingParsers creates parsers for ring sections.
func (*DefaultFactory) CreateTracesParsers ¶
func (f *DefaultFactory) CreateTracesParsers() *parser.Parsers
CreateTracesParsers creates parsers for traces sections.
func (*DefaultFactory) CreateUDPLBParsers ¶
func (f *DefaultFactory) CreateUDPLBParsers() *parser.Parsers
CreateUDPLBParsers creates parsers for udp-lb sections.
func (*DefaultFactory) CreateUserlistParsers ¶
func (f *DefaultFactory) CreateUserlistParsers() *parser.Parsers
CreateUserlistParsers creates parsers for userlist sections.
func (*DefaultFactory) CreateWAFGlobalParsers ¶
func (f *DefaultFactory) CreateWAFGlobalParsers() *parser.Parsers
CreateWAFGlobalParsers creates parsers for waf-global sections.
func (*DefaultFactory) CreateWAFProfileParsers ¶
func (f *DefaultFactory) CreateWAFProfileParsers() *parser.Parsers
CreateWAFProfileParsers creates parsers for waf-profile sections.
type EEBackendData ¶
type EEBackendData = parserconfig.EEBackendData
EEBackendData is a type alias for parserconfig.EEBackendData.
type EEFrontendData ¶
type EEFrontendData = parserconfig.EEFrontendData
EEFrontendData is a type alias for parserconfig.EEFrontendData.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is the HAProxy Enterprise Edition configuration parser. It uses a hybrid approach: 1. client-native parser for complete CE section extraction (global, defaults, frontends, backends, etc.) 2. Custom EE reader for EE-specific sections (waf-global, waf-profile, captcha, etc.) 3. Custom EE reader for EE directives within CE sections (filter waf, http-request waf-evaluate, etc.)
func NewParser ¶
NewParser creates a new Enterprise Edition parser. Returns an error if the underlying client-native parser cannot be initialized.
func (*Parser) ParseFromString ¶
func (p *Parser) ParseFromString(config string) (*StructuredConfig, error)
ParseFromString parses a HAProxy EE configuration string into a structured representation.
This uses a hybrid approach: 1. client-native parser processes CE sections (complete field extraction) 2. EE reader processes EE-specific sections (waf-global, waf-profile, etc.) 3. EE reader captures EE directives within CE sections (filter waf, http-request waf-evaluate).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader parses HAProxy configuration files line by line. It handles both Community Edition (CE) and Enterprise Edition (EE) sections.
The reader implements a state machine that tracks the current section and routes directives to the appropriate parser collection.
func NewReader ¶
func NewReader(factory *DefaultFactory) *Reader
NewReader creates a new configuration reader.
func (*Reader) GetParsers ¶
func (r *Reader) GetParsers() *ConfiguredParsers
GetParsers returns the configured parsers after processing.
func (*Reader) Process ¶
Process reads and parses a HAProxy configuration from an io.Reader. It processes the configuration line by line, routing each line to the appropriate section parsers.
func (*Reader) ProcessString ¶
ProcessString reads and parses a HAProxy configuration from a string.
type Section ¶
type Section string
Section represents a HAProxy configuration section type. Follows the same pattern as github.com/haproxytech/client-native/v6/config-parser.Section.
const ( // SectionUDPLB is UDP load balancing section (named), syntax: udp-lb <name>. SectionUDPLB Section = "udp-lb" // SectionWAFGlobal is WAF global configuration section (singleton), syntax: waf-global. SectionWAFGlobal Section = "waf-global" // SectionWAFProfile is WAF profile definition section (named), syntax: waf-profile <name>. SectionWAFProfile Section = "waf-profile" // SectionBotMgmtProfile is bot management profile section (named), syntax: botmgmt-profile <name>. SectionBotMgmtProfile Section = "botmgmt-profile" // SectionCaptcha is CAPTCHA provider configuration section (named), syntax: captcha <name>. SectionCaptcha Section = "captcha" // SectionDynamicUpdate is dynamic update configuration section (named), syntax: dynamic-update <name>. SectionDynamicUpdate Section = "dynamic-update" )
Enterprise Edition section types. These sections are not supported by client-native's parser.
const ( // SectionGlobal is the global configuration section (singleton). SectionGlobal Section = "global" // SectionDefaults is the defaults section (singleton or named). SectionDefaults Section = "defaults" // SectionFrontend is a frontend section (named). SectionFrontend Section = "frontend" // SectionBackend is a backend section (named). SectionBackend Section = "backend" // SectionListen is a listen section (combined frontend+backend, named). SectionListen Section = "listen" // SectionResolvers is a DNS resolvers section (named). SectionResolvers Section = "resolvers" // SectionPeers is a peers section for stick-table replication (named). SectionPeers Section = "peers" // SectionMailers is a mailers section for email alerts (named). SectionMailers Section = "mailers" // SectionCache is a cache section (named). SectionCache Section = "cache" // SectionHTTPErrors is an http-errors section (named). SectionHTTPErrors Section = "http-errors" // SectionRing is a ring buffer section (named). SectionRing Section = "ring" // SectionLogForward is a log forwarding section (named). SectionLogForward Section = "log-forward" // SectionFCGIApp is a FastCGI application section (named). SectionFCGIApp Section = "fcgi-app" // SectionCrtStore is a certificate store section (named). SectionCrtStore Section = "crt-store" // SectionTraces is a traces section for OpenTelemetry (named). SectionTraces Section = "traces" // SectionLogProfile is a log profile section (named). SectionLogProfile Section = "log-profile" // SectionACME is an ACME section for Let's Encrypt (named). SectionACME Section = "acme" // SectionUserlist is a userlist section for authentication (named). SectionUserlist Section = "userlist" // SectionComments represents comment lines. SectionComments Section = "#" )
Standard Community Edition section types. These are handled by client-native but listed here for completeness.
type StructuredConfig ¶
type StructuredConfig = parserconfig.StructuredConfig
StructuredConfig is the canonical configuration type. This is a type alias to parserconfig.StructuredConfig for convenience.