Refactoring
All checks were successful
buildbot/multibuild_parent Build done.
buildbot/travis_bionic Build done.

- unix_socket wasn't used correctly
This commit is contained in:
Peter Šurda 2024-04-22 15:23:03 +08:00
parent 89a69e6e38
commit b6ec505285
Signed by: PeterSurda
GPG Key ID: 3E47497CF67ABB95

View File

@ -95,11 +95,12 @@ else:
DEFAULT_ST_CONFIG_LOCATION = '$HOME/.config/syncthing/config.xml' DEFAULT_ST_CONFIG_LOCATION = '$HOME/.config/syncthing/config.xml'
def make_headers(host, api_key, device=None): def make_headers(host, api_key, unix_socket=None, device=None):
if device: url = '{}{}{}{}'.format(
url = '{}{}/{}'.format(host, SYNCTHING_API_URI, device) host if not unix_socket else "",
else: SYNCTHING_API_URI,
url = '{}{}'.format(host, SYNCTHING_API_URI) '/' if device else '',
device if device else '')
headers = {'X-Api-Key': api_key } headers = {'X-Api-Key': api_key }
return url, headers return url, headers
@ -120,12 +121,13 @@ 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):
if 'unix_socket' in module.params: url, headers = make_headers(
url, headers = make_headers(module.params['unix_socket'], module.params['api_key'], host=module.params['host'],
device) unix_socket=module.params['unix_socket']
else: if 'unix_socket' in module.params
url, headers = make_headers(module.params['host'], module.params['api_key'], else None,
device) api_key= module.params['api_key'],
device=device)
data = config data = config
if config: if config:
headers['Content-Type'] = 'application/json' headers['Content-Type'] = 'application/json'