Unix socket workaround
buildbot/multibuild_parent Build done. Details
buildbot/travis_bionic Build done. Details

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
1 changed files with 14 additions and 10 deletions

View File

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