paulbsd-salt/states/_states/syncthing.py

27 lines
779 B
Python
Raw Normal View History

2020-07-10 00:58:55 +02:00
#!/usr/bin/python3
from __future__ import absolute_import, print_function, unicode_literals
import salt.utils.dictupdate
import salt.utils.dictdiffer
def config(name, verify, url, cfg):
ret = {'name': name,
'changes': {},
'result': True,
'comment': 'config is up to date'}
cfg = dict(cfg)
apikey = __salt__['syncthing.get_apikey']()
st_cfg = __salt__['syncthing.get_config'](url, verify, apikey)
cfg['gui']['apiKey'] = apikey
res_cfg = salt.utils.dictupdate.update(st_cfg, cfg, recursive_update=True, merge_lists=False)
## Return to managed to set result
__salt__['syncthing.set_config'](url, verify, apikey, res_cfg)
ret['changes'] = salt.utils.dictdiffer.deep_diff(st_cfg, res_cfg)
return ret