imjoey / pyhaproxy

Python library to parse haproxy configurations
MIT License
54 stars 21 forks source link

ACL is misplaced in rendered/dumped haproxy.cfg file #12

Closed badfd closed 7 years ago

badfd commented 7 years ago

After loading an existing and working configuration, which includes the following lines:

backend my_be_nodes
    balance roundrobin
    option httplog 
    option forwardfor 
    acl is_special hdr_sub(Special-Request) -i True
    stick-table type integer size 1k expire 10m
    stick match hdr(Request-ID) if is_special
    stick store-request hdr(Request-ID)

on saving the altered configuration [wherein I added a BE server], the new configuration fails sanity because the ACL that defines is_special appears after [and so is unknown to] the stick match line that references is_special:

backend my_be_nodes
    balance roundrobin
    stick-table type integer size 1k expire 10m
    stick match hdr(Request-ID) if is_special
    stick store-request hdr(Request-ID)
    acl is_special hdr_sub(Special-Request) -i True
    option httplog 
    option forwardfor 
    server foo1 127.0.0.1:6001 ssl ca-file /ssl/public/ca-chain.cert.pem check

Simplified, the Python code looks like:

CONFIG_FILE = os.path.join(os.path.dirname(__file__), "haproxy.cfg")
cfg_parser = Parser(CONFIG_FILE)
config = cfg_parser.build_configuration()
new_server = Server(name='foo1',
                         host='127.0.0.1',
                         port='6001',
                         attributes=[
                             'ssl',
                             'ca-file /ssl/public/ca-chain.cert.pem',
                             'check'
                        ])
backend.servers().append(new_server)
config_render = Render(config)
config_render.dumps_to(CONFIG_FILE)
imjoey commented 7 years ago

@badfd It is indeed an issue, because I use an unordered dict to store the configs, including the ACLs. So rendering the dict is disorder. I will fix it soon. Thanks.

imjoey commented 7 years ago

@badfd The issue had been fixed, but with some APIs backward incompatible. You could find them in readme.