#!/usr/bin/python3 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']() current_cfg = __salt__['syncthing.get_config'](url=url, verify=verify, apikey=apikey) cfg['gui']['apiKey'] = apikey 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) ## Return to managed to set result 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) return ret