Add friendly_name keyword in the comment
psyhomb opened this issue ยท 4 comments
psyhomb commented
It would be really nice to implement some kind of keyword that will be used to mark friendly name comment line, that way it would be possible to have multiple comments but only one with a specific keyword will be used to generate friendly_name
label and all others will be silently ignored.
Example:
[Peer]
# friendly_name=frcognowin10
# Additional comment
PublicKey = lqYcojJMsIZXMUw1heAFbQHBoKjCEaeo7M1WXDh/KWc=
AllowedIPs = 10.70.0.40/32
# Additional comment
[Peer]
# friendly_name=OnePlus 5T
PublicKey = 928vO9Lf4+Mo84cWu4k1oRyzf0AR7FTGoPKHGoTMSHk=
AllowedIPs = 10.70.0.80/32
# Additional comment
I'm providing an example snippet code written in Python:
import re
peers = '''
[Peer]
# friendly_name=frcognowin10
# Additional comment
PublicKey = lqYcojJMsIZXMUw1heAFbQHBoKjCEaeo7M1WXDh/KWc=
AllowedIPs = 10.70.0.40/32
# Additional comment
[Peer]
# friendly_name=OnePlus 5T
PublicKey = 928vO9Lf4+Mo84cWu4k1oRyzf0AR7FTGoPKHGoTMSHk=
AllowedIPs = 10.70.0.80/32
# Additional comment
'''
l = []
for peer in peers.split('\n\n'):
fn = re.search(r'friendly_name=(.*)', peer)
pk = re.search(r'PublicKey = (.*)', peer)
if fn:
l.append({
'friendly_name': fn.group(1),
'public_key': pk.group(1)
})
print(l)
Output:
[{'friendly_name': 'frcognowin10', 'public_key': 'lqYcojJMsIZXMUw1heAFbQHBoKjCEaeo7M1WXDh/KWc='}, {'friendly_name': 'OnePlus 5T', 'public_key': '928vO9Lf4+Mo84cWu4k1oRyzf0AR7FTGoPKHGoTMSHk='}]
Thanks ๐
MindFlavor commented
That is a great idea. I'll work on it ASAP.
psyhomb commented
FYI these are changes I've made (fork) and I'm currently testing it in my WireGuard environment.
psyhomb@6439f0a
MindFlavor commented
D'oh I missed your comment and replicated the same thing... ๐คฆโโ๏ธ Sorry!
psyhomb commented
Not a problem at all ๐ and thank you for making these changes.