From cba85997642853fc2ad0df4bb501cf7f3b96624d Mon Sep 17 00:00:00 2001 From: Chris Caron Date: Fri, 28 Aug 2020 18:09:32 -0400 Subject: [PATCH] YAML extended configuration support for 'include' keyword (#284) --- apprise/config/ConfigBase.py | 11 ++++--- test/test_config_base.py | 63 ++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/apprise/config/ConfigBase.py b/apprise/config/ConfigBase.py index 9474cd72..22efd8e2 100644 --- a/apprise/config/ConfigBase.py +++ b/apprise/config/ConfigBase.py @@ -38,6 +38,7 @@ from ..common import ConfigIncludeMode from ..utils import GET_SCHEMA_RE from ..utils import parse_list from ..utils import parse_bool +from ..utils import parse_urls from . import SCHEMA_MAP @@ -704,8 +705,9 @@ class ConfigBase(URLBase): # includes = result.get('include', None) if isinstance(includes, six.string_types): - # Support a single inline string - includes = list([includes]) + # Support a single inline string or multiple ones separated by a + # comma and/or space + includes = parse_urls(includes) elif not isinstance(includes, (list, tuple)): # Not a problem; we simply have no includes @@ -715,8 +717,9 @@ class ConfigBase(URLBase): for no, url in enumerate(includes): if isinstance(url, six.string_types): - # We're just a simple URL string... - configs.append(url) + # Support a single inline string or multiple ones separated by + # a comma and/or space + configs.extend(parse_urls(url)) elif isinstance(url, dict): # Store the url and ignore arguments associated diff --git a/test/test_config_base.py b/test/test_config_base.py index 72b7c6db..8ab6f301 100644 --- a/test/test_config_base.py +++ b/test/test_config_base.py @@ -843,3 +843,66 @@ urls: # There were no include entries defined assert len(config) == 0 + + # Valid Configuration (multi inline configuration entries) + result, config = ConfigBase.config_parse_yaml(""" +# A configuration file that contains 2 includes separated by a comma and/or +# space: +include: http://localhost:8080/notify/apprise, http://localhost/apprise/cfg + +""", asset=asset) + + # We will have loaded no results + assert isinstance(result, list) + assert len(result) == 0 + + # But our two configuration files will be present: + assert len(config) == 2 + assert 'http://localhost:8080/notify/apprise' in config + assert 'http://localhost/apprise/cfg' in config + + # Valid Configuration (another way of specifying more then one include) + result, config = ConfigBase.config_parse_yaml(""" +# A configuration file that contains 4 includes on their own +# lines beneath the keyword `include`: +include: + http://localhost:8080/notify/apprise + http://localhost/apprise/cfg01 + http://localhost/apprise/cfg02 + http://localhost/apprise/cfg03 + +""", asset=asset) + + # We will have loaded no results + assert isinstance(result, list) + assert len(result) == 0 + + # But our 4 configuration files will be present: + assert len(config) == 4 + assert 'http://localhost:8080/notify/apprise' in config + assert 'http://localhost/apprise/cfg01' in config + assert 'http://localhost/apprise/cfg02' in config + assert 'http://localhost/apprise/cfg03' in config + + # Valid Configuration (we allow comma separated entries for + # each defined bullet) + result, config = ConfigBase.config_parse_yaml(""" +# A configuration file that contains 4 includes on their own +# lines beneath the keyword `include`: +include: + - http://localhost:8080/notify/apprise, http://localhost/apprise/cfg01 + http://localhost/apprise/cfg02 + - http://localhost/apprise/cfg03 + +""", asset=asset) + + # We will have loaded no results + assert isinstance(result, list) + assert len(result) == 0 + + # But our 4 configuration files will be present: + assert len(config) == 4 + assert 'http://localhost:8080/notify/apprise' in config + assert 'http://localhost/apprise/cfg01' in config + assert 'http://localhost/apprise/cfg02' in config + assert 'http://localhost/apprise/cfg03' in config