Git Product home page Git Product logo

haproxy-config's Introduction

HAProxy config

Parse HAProxy configs and easily query it

Crates.io Crates.io Docs.rs License

See also:

A parser for HAProxy config files. HAProxy's config format offers many options, too many to build a completely typed API. Such an API would also be quite fragile to changes in the config format. This crate therefore presents a loosely typed config.

It parses to sections consisting of lines from which a Config struct can be made. The struct follows the sections of a HAProxy config. Most options within the sections are presented in a HashMap as key value strings. The important settings have a fully typed API.

Example

List all the ports HAProxy will bind to from the config file.

use haproxy_config::parse_sections;
use haproxy_config::Config;

let file = include_str!("../tests/medium_haproxy.cfg");
let sections = parse_sections(file).unwrap();

let config = Config::try_from(&sections).unwrap();

let frontend_ports = config.frontends.values().map(|f| f.bind.addr.port);
let listen_ports = config.listen.values().map(|f| f.bind.addr.port);
let ports: Vec<_> = frontend_ports.chain(listen_ports).collect();

println!("ports bound to by haproxy: {ports:?}")

Features

  • Zero copy parsing to a config section based representation which preserves the order of the config lines and any comments.
  • A stricter owned representation that is easy to query.
  • Clear error reporting on parsing errors featuring a debug formatter that shows the problem with the config being parsed.
  • Panic free implementation, this crate will not crash your code.

Unsupported

Because the API is not fully typed the crate allows some invalid configs to parse. Specifically any invalid configuration inside a section will be interpreted as a configuration value. Sections end at the next section or the end of the file therefore any invalid configuration after the first section is undetected.

The crate will break on valid configs that feature conditional blocks.

Contributions

This crate is far from complete but covers all my own use cases. I do however welcome any contributions.

Thanks

haproxy-config's People

Stargazers

 avatar

Watchers

 avatar

haproxy-config's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

cargo
Cargo.toml
  • ariadne 0.4.0
  • itertools 0.12.1
  • peg 0.8.2
  • thiserror 1.0.56
  • color-eyre 0.6
github-actions
.github/workflows/testing.yml
  • actions/checkout v4@1d96c772d19495a3b5c517cd2bc0cb401ea0529f
  • actions-rs/toolchain v1
  • actions/cache v4

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.