imjoey / pyhaproxy

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

[BUG] Wrong parsing on pegnode #25

Closed alisson276 closed 4 years ago

alisson276 commented 4 years ago

The pegnode parser treat all lines starting with server as a server_line.

My global section has the following:

global
        #log /dev/log    local0
        #log /dev/log    local1 notice
        log 127.0.0.1 local0 debug
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin
        stats timeout 30s
        server-state-base /etc/haproxy/serverstate
        server-state-file global
        user haproxy
        group haproxy
        daemon
        tune.ssl.default-dh-param 2048

The current parser understand the line server-state-file global as a server_line and render the config like this:

<config_line: config log 127.0.0.1 local0 debug>
<config_line: config chroot /var/lib/haproxy>
<config_line: config stats socket /run/haproxy/admin.sock mode 660 level admin>
<config_line: config stats timeout 30s>
<config_line: config server-state-base /etc/haproxy/serverstate>
<server_line: -state-file global: >
<config_line: config user haproxy>
<group_line: group haproxy >

That behavior occur because the parser disregards the space (mandatory for a server section).

My fix was just edit 2 lines of pegnode.py and change from 6 to 7 and add a space:

                chunk0 = self._input[self._offset:self._offset + 7]
            if chunk0 == 'server ':
imjoey commented 4 years ago

Hi @alisson276 , thanks for your contribution. Could you please submit a pull request to fix this issue? Much appreciated. 😄

alisson276 commented 4 years ago

Opened!

alisson276 commented 4 years ago

Can you release a new patch version with the fix provided?

imjoey commented 4 years ago

@alisson276 Happy to announce that the latest version v0.3.7 is available on PYPI. Feel free to update. Thanks again for your contribution.

alisson276 commented 4 years ago

Working. Thank you too!