miron0xff / vyatta-conf-parser

Config parser for Vyatta/VyOS
MIT License
20 stars 11 forks source link

Wireguard syntax not parseable #9

Closed network-shark closed 4 years ago

network-shark commented 4 years ago

Hello Hedin,

one of my routers is running wireguard , but it seems that it is not compatible to your parser.

Can you take a look ?

wireguard wg0 {
        address 10.200.200.1/24
        listen-port 60000
        mtu 1420
        peer XXXX= {
            allowed-ips 10.200.200.3/32
        }
        peer YYYY= {
            allowed-ips 10.200.200.2/32
        }
        private-key ****************
        route-allowed-ips true
    }

ERROR :

╰─ ./vyatta.py
Traceback (most recent call last):
  File "./vyatta.py", line 15, in <module>
    conf_dict = vyattaconfparser.parse_conf(data)
  File "/Users/sharky/.pyenv/versions/salt/lib/python3.7/site-packages/vyattaconfparser/parser.py", line 166, in parse_conf
    c, headers = parse_node(c, line, n, headers)
  File "/Users/sharky/.pyenv/versions/salt/lib/python3.7/site-packages/vyattaconfparser/parser.py", line 130, in parse_node
    update_tree(config, path, {key: value}, val_type='value')
  File "/Users/sharky/.pyenv/versions/salt/lib/python3.7/site-packages/vyattaconfparser/parser.py", line 58, in update_tree
    elif list(val.keys())[0] == list(path[-1].keys())[0]:
IndexError: list index out of range

I think it has to do with some regex , because if I change

peer XXXX=

to
peer XXXXX

than your parser works fine.

From the documentation https://github.com/Lochnair/vyatta-wireguard

It looks like every peer name ends with an "="

Are you willing to implement this ?

Thank you !

miron0xff commented 4 years ago

Thank you for the report. I've added = to regex pattern for named sections. New version is on PyPi =)

miron0xff commented 4 years ago

I've also added + sign to regex pattern since WG's named sections are Base64 encoded. Please use 0.5.5 version. It's on PyPi

network-shark commented 4 years ago

Thank you !