paulbsd-salt/states/_states/syncthing.py

31 lines
901 B
Python
Raw Normal View History

2020-07-10 00:58:55 +02:00
#!/usr/bin/python3
import salt.utils.dictupdate
import salt.utils.dictdiffer
2021-01-17 17:43:56 +01:00
2020-07-10 00:58:55 +02:00
def config(name, verify, url, cfg):
ret = {'name': name,
2020-09-30 00:44:06 +02:00
'changes': {},
'result': True,
2021-07-11 17:37:42 +02:00
'comment': 'Config is up to date'}
2020-07-10 00:58:55 +02:00
cfg = dict(cfg)
apikey = __salt__['syncthing.get_apikey']()
2023-02-19 17:59:18 +01:00
current_cfg = __salt__['syncthing.get_config'](url=url, verify=verify, apikey=apikey)
2020-07-10 00:58:55 +02:00
cfg['gui']['apiKey'] = apikey
2023-02-19 17:59:18 +01:00
res_cfg = salt.utils.dictupdate.update(current_cfg, cfg, recursive_update=True, merge_lists=False)
ret['changes'] = salt.utils.dictdiffer.deep_diff(current_cfg, res_cfg)
2020-07-10 00:58:55 +02:00
## Return to managed to set result
2023-02-19 17:59:18 +01:00
res = []
res.append(__salt__['syncthing.set_config_options'](url, verify, apikey, res_cfg['options']))
res.append(__salt__['syncthing.set_config_gui'](url, verify, apikey, res_cfg['gui']))
ret['result'] = all(res)
2020-07-10 00:58:55 +02:00
2020-09-30 00:44:06 +02:00
return ret