Need help parsing OpenVPN file
This is not a bug report. I just need a little help. Please look into it in your free time.
I'm looking for an api which can parse a openvpn (.ovpn) file and return the key/value pairs. I need to do it in Python.
So far I've found this method: https://networkmanager.dev/docs/libnm/latest/NMVpnServicePlugin.html#nm-vpn-service-plugin-read-vpn-details
Using it in Python doesn't seem to work:
#!/usr/bin/env python
import gi
gi.require_version('NM', '1.0')
from gi.repository import GLib, NM
import sys
if len(sys.argv) != 2:
print("Expects one argument: the filename")
sys.exit(1)
filename = sys.argv[1]
fileObject = open('./test.ovpn', 'r')
fd = fileObject.fileno()
ret = NM.VpnServicePlugin.read_vpn_details(fd)
print(ret)
Executing above script I always get (False, out_data=None, out_secrets=None)
Sorry, both my python and C knowledge are limited, so it might be that I'm missing something obvious here.
Alternatively, if there's a dbus api which does something similar, that'd help too, so far I couldn't find any.
For context, I'm attempting to populate a form using the key/value pairs before importing.
I didn't open the issue in https://gitlab.gnome.org/GNOME/NetworkManager-openvpn because I think it's a NM api that I'm looking for. Feel free to move it if necessary.
Thanks!