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']()
|
|
|
|
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
|
2021-10-30 18:39:27 +02:00
|
|
|
ret['result'] = __salt__['syncthing.set_config'](url, verify, apikey, res_cfg)
|
2020-07-10 00:58:55 +02:00
|
|
|
ret['changes'] = salt.utils.dictdiffer.deep_diff(st_cfg, res_cfg)
|
|
|
|
|
2020-09-30 00:44:06 +02:00
|
|
|
return ret
|