enterprise

package
v0.1.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAnySection

func IsAnySection(section Section) bool

IsAnySection returns true if the section type is any valid HAProxy section.

func IsAnySectionString

func IsAnySectionString(section string) bool

IsAnySectionString returns true if the section string is any valid HAProxy section.

func IsCESection

func IsCESection(section Section) bool

IsCESection returns true if the section type is a Community Edition section.

func IsCESectionString

func IsCESectionString(section string) bool

IsCESectionString returns true if the section string is a Community Edition section.

func IsEESection

func IsEESection(section Section) bool

IsEESection returns true if the section type is an Enterprise Edition section.

func IsEESectionString

func IsEESectionString(section string) bool

IsEESectionString returns true if the section string is an Enterprise Edition section.

func IsNamedSection

func IsNamedSection(section Section) bool

IsNamedSection returns true if the section requires a name.

func IsNamedSectionString

func IsNamedSectionString(section string) bool

IsNamedSectionString returns true if the section string requires a name.

func IsSingletonSection

func IsSingletonSection(section Section) bool

IsSingletonSection returns true if the section can only appear once.

func IsSingletonSectionString

func IsSingletonSectionString(section string) bool

IsSingletonSectionString returns true if the section string 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

	// Program holds per-program parser collections.
	// Key is program name.
	Program 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) GetAllNames

func (c *ConfiguredParsers) GetAllNames(section Section) []string

GetAllNames returns all section names for a given section type.

func (*ConfiguredParsers) GetSectionParsers

func (c *ConfiguredParsers) GetSectionParsers(section Section, name string, factory ParserFactory) *parser.Parsers

GetSectionParsers returns the parser collection for a section. For named sections, creates a new collection if it doesn't exist.

func (*ConfiguredParsers) SetState

func (c *ConfiguredParsers) SetState(section Section, name string, parsers *parser.Parsers)

SetState sets the current parsing state and active parser collection.

type DefaultFactory

type DefaultFactory struct{}

DefaultFactory implements ParserFactory using client-native parsers. It creates parser collections for both CE and EE sections.

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) CreateProgramParsers

func (f *DefaultFactory) CreateProgramParsers() *parser.Parsers

CreateProgramParsers creates parsers for program 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

func NewParser() (*Parser, error)

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 an 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 ParserFactory

type ParserFactory interface {
	// CE singleton sections
	CreateGlobalParsers() *parser.Parsers
	CreateDefaultsParsers() *parser.Parsers
	CreateCommentsParsers() *parser.Parsers

	// CE named sections
	CreateFrontendParsers() *parser.Parsers
	CreateBackendParsers() *parser.Parsers
	CreateListenParsers() *parser.Parsers
	CreateResolversParsers() *parser.Parsers
	CreatePeersParsers() *parser.Parsers
	CreateMailersParsers() *parser.Parsers
	CreateCacheParsers() *parser.Parsers
	CreateProgramParsers() *parser.Parsers
	CreateHTTPErrorsParsers() *parser.Parsers
	CreateRingParsers() *parser.Parsers
	CreateLogForwardParsers() *parser.Parsers
	CreateFCGIAppParsers() *parser.Parsers
	CreateCrtStoreParsers() *parser.Parsers
	CreateTracesParsers() *parser.Parsers
	CreateLogProfileParsers() *parser.Parsers
	CreateACMEParsers() *parser.Parsers
	CreateUserlistParsers() *parser.Parsers

	// EE singleton sections
	CreateWAFGlobalParsers() *parser.Parsers

	// EE named sections
	CreateWAFProfileParsers() *parser.Parsers
	CreateBotMgmtProfileParsers() *parser.Parsers
	CreateCaptchaParsers() *parser.Parsers
	CreateUDPLBParsers() *parser.Parsers
	CreateDynamicUpdateParsers() *parser.Parsers
}

ParserFactory is an interface for creating parser collections. This allows dependency injection of the actual parser creation logic.

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 ParserFactory) *Reader

NewReader creates a new configuration reader.

func (*Reader) ExtractSection

func (r *Reader) ExtractSection(section Section, name string) map[string]interface{}

ExtractSection extracts all parsed data for a section. This is used to convert parsed results into the structured config.

func (*Reader) GetParsers

func (r *Reader) GetParsers() *ConfiguredParsers

GetParsers returns the configured parsers after processing.

func (*Reader) Process

func (r *Reader) Process(input io.Reader) error

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

func (r *Reader) ProcessString(config string) error

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"

	// SectionProgram is a program section for external programs (named).
	SectionProgram Section = "program"

	// 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.

func GetAllCESections

func GetAllCESections() []Section

GetAllCESections returns all Community Edition section types.

func GetAllEESections

func GetAllEESections() []Section

GetAllEESections returns all Enterprise Edition section types.

func GetAllSections

func GetAllSections() []Section

GetAllSections returns all HAProxy section types (CE + EE).

type SectionHeader

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

SectionHeader parses section headers (e.g., "frontend foo", "backend bar"). Used by the reader to detect section transitions.

func (*SectionHeader) Delete

func (p *SectionHeader) Delete(index int) error

Delete deletes data at index.

func (*SectionHeader) Get

func (p *SectionHeader) Get(createIfNotExist bool) (interface{}, error)

Get returns all parsed data.

func (*SectionHeader) GetOne

func (p *SectionHeader) GetOne(index int) (interface{}, error)

GetOne returns parsed data at index.

func (*SectionHeader) GetParserName

func (p *SectionHeader) GetParserName() string

GetParserName returns the parser name.

func (*SectionHeader) GetPreComments

func (p *SectionHeader) GetPreComments() ([]string, error)

GetPreComments returns pre-comments.

func (*SectionHeader) Init

func (p *SectionHeader) Init()

Init initializes the parser.

func (*SectionHeader) Insert

func (p *SectionHeader) Insert(data interface{}, index int) error

Insert inserts data at index.

func (*SectionHeader) Parse

func (p *SectionHeader) Parse(line string, parts []string, comment string) (string, error)

Parse parses a section header line.

func (*SectionHeader) PreParse

func (p *SectionHeader) PreParse(line string, parts, preComments []string, comment string) (string, error)

PreParse is called before Parse for preprocessor handling.

func (*SectionHeader) ResultAll

func (p *SectionHeader) ResultAll() (results []interface{}, preComments []string, err error)

ResultAll returns all results for serialization.

func (*SectionHeader) Set

func (p *SectionHeader) Set(data interface{}, index int) error

Set sets data at index.

func (*SectionHeader) SetPreComments

func (p *SectionHeader) SetPreComments(preComment []string)

SetPreComments sets pre-comments.

type SectionHeaderData

type SectionHeaderData struct {
	Type    Section
	Name    string
	Comment string
}

SectionHeaderData holds parsed section header information.

type SectionInfo

type SectionInfo struct {
	// Section is the section type.
	Section Section

	// IsEnterprise indicates if this is an EE-only section.
	IsEnterprise bool

	// IsSingleton indicates if only one instance can exist.
	IsSingleton bool

	// RequiresName indicates if the section requires a name argument.
	RequiresName bool

	// Description is a human-readable description.
	Description string
}

SectionInfo contains metadata about a section type.

func GetSectionInfo

func GetSectionInfo(section Section) SectionInfo

GetSectionInfo returns metadata about a section type.

type StructuredConfig

type StructuredConfig = parserconfig.StructuredConfig

StructuredConfig is the canonical configuration type. This is a type alias to parserconfig.StructuredConfig for convenience.

Directories

Path Synopsis
Package types provides parser implementations for HAProxy Enterprise Edition section-specific directives.
Package types provides parser implementations for HAProxy Enterprise Edition section-specific directives.
Package parsers provides wrapper parsers for HAProxy Enterprise Edition directives.
Package parsers provides wrapper parsers for HAProxy Enterprise Edition directives.

Jump to

Keyboard shortcuts

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