Browse Source

module: hide_keys for show()

tags/v0.9
Maximilian Eschenbacher 6 years ago
parent
commit
f562c4553f
1 changed files with 7 additions and 6 deletions
  1. +7
    -6
      _modules/wireguard.py

+ 7
- 6
_modules/wireguard.py View File

return __salt__['cmd.run']('ip link del %s' % (name,)) return __salt__['cmd.run']('ip link del %s' % (name,))




def show(name=None, peer=None):
def show(name=None, peer=None, hide_keys=True):
if peer and not name: if peer and not name:
return 'If peer is given, name must also be given' return 'If peer is given, name must also be given'
if not name: if not name:
return _wg_ifaces()
return _wg_ifaces(hide_keys=hide_keys)
elif peer: elif peer:
return _wg_ifaces().get(name).get('peers').get(peer)
return _wg_ifaces(hide_keys=hide_keys).get(name).get('peers').get(peer)
else: else:
return _wg_ifaces().get(name)
return _wg_ifaces(hide_keys=hide_keys).get(name)


def showconf(name): def showconf(name):
return __salt__['cmd.run']('wg showconf %s' % (name,)) return __salt__['cmd.run']('wg showconf %s' % (name,))
def addconf(name, path): def addconf(name, path):
return __salt__['cmd.run']('wg addconf %s %s' % (name, path)) return __salt__['cmd.run']('wg addconf %s %s' % (name, path))


def _wg_ifaces():
def _wg_ifaces(hide_keys=True):
""" """
Parse output from 'wg show' Parse output from 'wg show'
""" """
tmp = dict() tmp = dict()
tmpiface = dict() tmpiface = dict()
ifaces = dict() ifaces = dict()
out = __salt__['cmd.run']('wg', env={'WG_HIDE_KEYS': 'never'})
out = __salt__['cmd.run']('wg',
env={'WG_HIDE_KEYS': 'always' if hide_keys else 'never'})
for line in out.splitlines(): for line in out.splitlines():
if line.startswith('interface: '): if line.startswith('interface: '):
k, v = _wg_splitline(line) k, v = _wg_splitline(line)

Loading…
Cancel
Save