From e336ebde130d63a15e56fbaa3ccd8aa1449b3af1 Mon Sep 17 00:00:00 2001 From: Borjan Tchakaloff Date: Fri, 1 Jan 2021 15:14:49 +0100 Subject: [PATCH] syncthing_folder: Accept path to the configuration file Specifying `config_file` overrides the default path relative to the current user. This is handy when the executing user is a different user. --- library/storage/syncthing/syncthing_folder.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/storage/syncthing/syncthing_folder.py b/library/storage/syncthing/syncthing_folder.py index ed493b4..0ae642c 100644 --- a/library/storage/syncthing/syncthing_folder.py +++ b/library/storage/syncthing/syncthing_folder.py @@ -62,6 +62,12 @@ options: - API key to use for authentication with host. If not provided, will try to auto-configure from filesystem. required: false + config_file: + description: + - Path to the Syncthing configuration file for automatic + discovery (`api_key`). Note that the running user needs read + access to the file. + required: false timeout: description: - The socket level timeout in seconds @@ -116,7 +122,10 @@ def make_headers(host, api_key): def get_key_from_filesystem(module): try: - stconfigfile = os.path.expandvars(DEFAULT_ST_CONFIG_LOCATION) + if module.params['config_file']: + stconfigfile = module.params['config_file'] + else: + stconfigfile = os.path.expandvars(DEFAULT_ST_CONFIG_LOCATION) stconfig = parse(stconfigfile) root = stconfig.getroot() gui = root.find('gui') @@ -228,6 +237,7 @@ def run_module(): choices=['sendreceive', 'sendonly', 'receiveonly']), host=dict(type='str', default='http://127.0.0.1:8384'), api_key=dict(type='str', required=False, no_log=True), + config_file=dict(type='path', required=False), timeout=dict(type='int', default=30), state=dict(type='str', default='present', choices=['absent', 'present', 'pause']),