parser

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: 8 Imported by: 0

README

pkg/dataplane/parser

HAProxy configuration parser.

Overview

Parses HAProxy configuration files into structured format for comparison and validation.

Quick Start

import "haptic/pkg/dataplane/parser"

parser, err := parser.New()
parsed, err := parser.Parse(haproxyConfig)

License

See main repository for license information.

Documentation

Overview

Package parser provides HAProxy configuration parsing using client-native library.

This package wraps the haproxytech/client-native parser to parse HAProxy configurations from strings (in-memory, no disk I/O) into structured representations suitable for comparison and API operations.

Semantic validation (checking resource availability, directive compatibility, etc.) is NOT performed here - that is handled by the external haproxy binary in later stages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeConfigMetadata

func NormalizeConfigMetadata(config *parserconfig.StructuredConfig)

NormalizeConfigMetadata normalizes all Metadata fields in a StructuredConfig from nested API format to flat client-native format.

This ensures consistent format for comparison regardless of where config was parsed from. When the Dataplane API stores configs with metadata, it converts flat format to nested JSON. When we parse that config back, the metadata comes back in nested format, but the desired config (from template) has flat format. This mismatch causes false positive updates during comparison.

This function walks all models in the config and normalizes their Metadata fields.

func NormalizeMetadata

func NormalizeMetadata(m map[string]interface{}) map[string]interface{}

NormalizeMetadata converts nested API metadata format to flat client-native format.

When the Dataplane API stores configurations, comments containing metadata are stored in JSON format like: # {"comment":{"value":"Pod: echo-server"}}

When client-native parses this JSON comment, it returns the nested structure directly. However, when templates render configs, they produce flat metadata: {"comment": "Pod: echo-server"}

This format mismatch causes false positive updates during comparison. This function normalizes nested metadata to flat format for consistent comparison.

Input (nested): {"comment": {"value": "Pod: echo-server"}, "custom": {"value": "foo"}} Output (flat): {"comment": "Pod: echo-server", "custom": "foo"}

If the input is already flat, nil, or empty, it returns unchanged (or nil for nil/empty).

Types

type Parser

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

Parser wraps client-native's config-parser for parsing HAProxy configurations.

func New

func New() (*Parser, error)

New creates a new Parser instance.

The parser uses client-native's config-parser which provides robust parsing of HAProxy configuration syntax without requiring file I/O.

func (*Parser) ParseFromString

func (p *Parser) ParseFromString(config string) (*StructuredConfig, error)

ParseFromString parses an HAProxy configuration string into a structured representation.

The configuration string should contain valid HAProxy configuration syntax. Returns a StructuredConfig containing all parsed sections (global, defaults, frontends, backends, etc.) suitable for comparison and synchronization.

Syntax validation is performed as part of parsing - any syntax errors will be returned. Semantic validation (resource availability, directive compatibility) is performed by HAProxy via the Dataplane API during configuration application.

Example:

config := `
global
    daemon
defaults
    mode http
backend web
    balance roundrobin
    server srv1 192.168.1.10:80
`
parser, _ := parser.New()
structured, err := parser.ParseFromString(config)

type StructuredConfig

type StructuredConfig = parserconfig.StructuredConfig

StructuredConfig is a type alias for types.StructuredConfig. This alias is provided for backward compatibility with existing code. New code should import from haptic/pkg/dataplane/parser/parserconfig.

Directories

Path Synopsis
Package enterprise provides HAProxy Enterprise Edition configuration parsing.
Package enterprise provides HAProxy Enterprise Edition configuration parsing.
directives
Package types provides parser implementations for HAProxy Enterprise Edition section-specific directives.
Package types provides parser implementations for HAProxy Enterprise Edition section-specific directives.
parsers
Package parsers provides wrapper parsers for HAProxy Enterprise Edition directives.
Package parsers provides wrapper parsers for HAProxy Enterprise Edition directives.
Package parserconfig provides canonical configuration types for HAProxy parsing.
Package parserconfig provides canonical configuration types for HAProxy parsing.

Jump to

Keyboard shortcuts

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