From fe8f9be56781c4b224d8c2b8bd7dcff05c1dad2a Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 22 Apr 2024 15:07:48 +0800 Subject: [PATCH] Unix socket workaround --- collection/plugins/modules/device.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/collection/plugins/modules/device.py b/collection/plugins/modules/device.py index 9a7ba04..b92925e 100644 --- a/collection/plugins/modules/device.py +++ b/collection/plugins/modules/device.py @@ -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