Unix socket workaround
All checks were successful
buildbot/multibuild_parent Build done.
buildbot/travis_bionic Build done.

This commit is contained in:
Peter Šurda 2024-04-22 15:07:48 +08:00
parent 6bd9731844
commit fe8f9be567
Signed by: PeterSurda
GPG Key ID: 3E47497CF67ABB95

View File

@ -82,11 +82,6 @@ from xml.etree.ElementTree import parse
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.urls import fetch_url, url_argument_spec from ansible.module_utils.urls import fetch_url, url_argument_spec
try:
import requests_unixsocket
except ImportError:
pass
SYNCTHING_API_URI = "/rest/config/devices" SYNCTHING_API_URI = "/rest/config/devices"
if platform.system() == 'Windows': if platform.system() == 'Windows':
DEFAULT_ST_CONFIG_LOCATION = '%localappdata%/Syncthing/config.xml' DEFAULT_ST_CONFIG_LOCATION = '%localappdata%/Syncthing/config.xml'
@ -121,8 +116,12 @@ def get_key_from_filesystem(module):
# Fetch Syncthing configuration # Fetch Syncthing configuration
def remote_config(module, method='GET', config=None, result=None, device=None): def remote_config(module, method='GET', config=None, result=None, device=None):
url, headers = make_headers(module.params['host'], module.params['api_key'], if 'unix_socket' in module.params:
device) url, headers = make_headers(module.params['unix_socket'], module.params['api_key'],
device)
else:
url, headers = make_headers(module.params['host'], module.params['api_key'],
device)
data = config data = config
if config: if config:
headers['Content-Type'] = 'application/json' headers['Content-Type'] = 'application/json'
@ -130,9 +129,14 @@ def remote_config(module, method='GET', config=None, result=None, device=None):
if not result: if not result:
result = {} result = {}
resp, info = fetch_url( if 'unix_socket' in module['params']:
module, url, data=data, headers=headers, resp, info = fetch_url(
method=method, timeout=module.params['timeout']) module, unix_socket=url, data=data, headers=headers,
method=method, timeout=module.params['timeout'])
else:
resp, info = fetch_url(
module, url, data=data, headers=headers,
method=method, timeout=module.params['timeout'])
if not info or info['status'] != 200: if not info or info['status'] != 200:
result['response'] = info result['response'] = info