From b6ec505285327e81cadb5d5cdfd86d39a574766e Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Mon, 22 Apr 2024 15:23:03 +0800 Subject: [PATCH] Refactoring - unix_socket wasn't used correctly --- collection/plugins/modules/device.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/collection/plugins/modules/device.py b/collection/plugins/modules/device.py index 9572073..241f7bc 100644 --- a/collection/plugins/modules/device.py +++ b/collection/plugins/modules/device.py @@ -95,11 +95,12 @@ else: DEFAULT_ST_CONFIG_LOCATION = '$HOME/.config/syncthing/config.xml' -def make_headers(host, api_key, device=None): - if device: - url = '{}{}/{}'.format(host, SYNCTHING_API_URI, device) - else: - url = '{}{}'.format(host, SYNCTHING_API_URI) +def make_headers(host, api_key, unix_socket=None, device=None): + url = '{}{}{}{}'.format( + host if not unix_socket else "", + SYNCTHING_API_URI, + '/' if device else '', + device if device else '') headers = {'X-Api-Key': api_key } return url, headers @@ -120,12 +121,13 @@ def get_key_from_filesystem(module): # Fetch Syncthing configuration def remote_config(module, method='GET', config=None, result=None, device=None): - 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) + url, headers = make_headers( + host=module.params['host'], + unix_socket=module.params['unix_socket'] + if 'unix_socket' in module.params + else None, + api_key= module.params['api_key'], + device=device) data = config if config: headers['Content-Type'] = 'application/json'