Ver código fonte

removing and adding of preshared_keys fixed

tags/v0.9
Maximilian Eschenbacher 6 anos atrás
pai
commit
b3affb2680
2 arquivos alterados com 6 adições e 5 exclusões
  1. +1
    -1
      _modules/wireguard.py
  2. +5
    -4
      _states/wireguard.py

+ 1
- 1
_modules/wireguard.py Ver arquivo

s = '%s private-key %s' % (s, filename) s = '%s private-key %s' % (s, filename)
if peer: if peer:
s = '%s peer %s' % (s, peer) s = '%s peer %s' % (s, peer)
if preshared_key:
if preshared_key != None:
if not peer: if not peer:
return 'If preshared_key is given, peer must also be given' return 'If preshared_key is given, peer must also be given'
fd2, filename2 = mkstemp(text=True) fd2, filename2 = mkstemp(text=True)

+ 5
- 4
_states/wireguard.py Ver arquivo

allowed_ips=None, preshared_key=None): allowed_ips=None, preshared_key=None):
ret = dict(name=name, changes=dict(), result=False, comment=None) ret = dict(name=name, changes=dict(), result=False, comment=None)


show = __salt__['wg.show'](interface)
show = __salt__['wg.show'](interface, hide_keys=False)
if not show: if not show:
ret['comment'] = 'Interface %s does not exist.' % (interface) ret['comment'] = 'Interface %s does not exist.' % (interface)
return ret return ret


show = __salt__['wg.show'](name=interface, peer=name)
show = __salt__['wg.show'](name=interface, peer=name, hide_keys=False)
if not show: if not show:
__salt__['wg.set'](interface, peer=name, endpoint=endpoint, __salt__['wg.set'](interface, peer=name, endpoint=endpoint,
persistent_keepalive=persistent_keepalive, persistent_keepalive=persistent_keepalive,
if sorted(show.get('allowed ips')) != sorted(allowed_ips): if sorted(show.get('allowed ips')) != sorted(allowed_ips):
__salt__['wg.set'](interface, peer=name, allowed_ips=','.join(allowed_ips)) __salt__['wg.set'](interface, peer=name, allowed_ips=','.join(allowed_ips))
ret['changes']['allowed ips'] = dict(new=allowed_ips, old=show.get('allowed ips')) ret['changes']['allowed ips'] = dict(new=allowed_ips, old=show.get('allowed ips'))
if show.get('preshared key') and preshared_key and show.get('preshared key') != preshared_key:
print(show.get('preshared key'), preshared_key)
if preshared_key and show.get('preshared key') != preshared_key:
__salt__['wg.set'](interface, peer=name, preshared_key=preshared_key) __salt__['wg.set'](interface, peer=name, preshared_key=preshared_key)
ret['changes']['preshared key'] = 'preshared key changed.' ret['changes']['preshared key'] = 'preshared key changed.'
if show.get('preshared key') and not preshared_key:
elif show.get('preshared key') and not preshared_key:
__salt__['wg.set'](interface, peer=name, preshared_key='') __salt__['wg.set'](interface, peer=name, preshared_key='')
ret['changes']['preshared key'] = 'preshared key deleted.' ret['changes']['preshared key'] = 'preshared key deleted.'



Carregando…
Cancelar
Salvar