Refactoring

- 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 untrusted user: PeterSurda
GPG Key ID: 3E47497CF67ABB95

View File

@ -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'