updated modules and states scripts

This commit is contained in:
Paul 2021-10-30 18:39:27 +02:00
parent 37f73a29f0
commit fec2ac76f8
2 changed files with 11 additions and 5 deletions

View File

@ -3,8 +3,9 @@
import ssl
import json
import xml.etree.ElementTree as ET
from urllib.request import urlopen
from urllib.request import Request
from urllib.request import urlopen, Request
from urllib.parse import urljoin
from urllib.error import HTTPError
def get_context(verify):
@ -48,7 +49,13 @@ def set_config(url, verify, apikey, config):
url=fullurl,
data=json.dumps(config).encode())
req.add_header("X-API-Key", apikey)
res = urlopen(req, context=get_context(verify))
try:
res = urlopen(req, context=get_context(verify))
except HTTPError as err:
if err.status != 307:
return None
req.full_url = urljoin(url, err.headers['Location'])
res = urlopen(req, context=get_context(verify))
if res.status == 200:
return True

View File

@ -20,8 +20,7 @@ def config(name, verify, url, cfg):
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['result'] = __salt__['syncthing.set_config'](url, verify, apikey, res_cfg)
ret['changes'] = salt.utils.dictdiffer.deep_diff(st_cfg, res_cfg)
return ret