mirror of https://github.com/caronc/apprise
YAML extended configuration support for 'include' keyword (#284)
parent
66d285a57e
commit
cba8599764
|
@ -38,6 +38,7 @@ from ..common import ConfigIncludeMode
|
||||||
from ..utils import GET_SCHEMA_RE
|
from ..utils import GET_SCHEMA_RE
|
||||||
from ..utils import parse_list
|
from ..utils import parse_list
|
||||||
from ..utils import parse_bool
|
from ..utils import parse_bool
|
||||||
|
from ..utils import parse_urls
|
||||||
from . import SCHEMA_MAP
|
from . import SCHEMA_MAP
|
||||||
|
|
||||||
|
|
||||||
|
@ -704,8 +705,9 @@ class ConfigBase(URLBase):
|
||||||
#
|
#
|
||||||
includes = result.get('include', None)
|
includes = result.get('include', None)
|
||||||
if isinstance(includes, six.string_types):
|
if isinstance(includes, six.string_types):
|
||||||
# Support a single inline string
|
# Support a single inline string or multiple ones separated by a
|
||||||
includes = list([includes])
|
# comma and/or space
|
||||||
|
includes = parse_urls(includes)
|
||||||
|
|
||||||
elif not isinstance(includes, (list, tuple)):
|
elif not isinstance(includes, (list, tuple)):
|
||||||
# Not a problem; we simply have no includes
|
# Not a problem; we simply have no includes
|
||||||
|
@ -715,8 +717,9 @@ class ConfigBase(URLBase):
|
||||||
for no, url in enumerate(includes):
|
for no, url in enumerate(includes):
|
||||||
|
|
||||||
if isinstance(url, six.string_types):
|
if isinstance(url, six.string_types):
|
||||||
# We're just a simple URL string...
|
# Support a single inline string or multiple ones separated by
|
||||||
configs.append(url)
|
# a comma and/or space
|
||||||
|
configs.extend(parse_urls(url))
|
||||||
|
|
||||||
elif isinstance(url, dict):
|
elif isinstance(url, dict):
|
||||||
# Store the url and ignore arguments associated
|
# Store the url and ignore arguments associated
|
||||||
|
|
|
@ -843,3 +843,66 @@ urls:
|
||||||
|
|
||||||
# There were no include entries defined
|
# There were no include entries defined
|
||||||
assert len(config) == 0
|
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
|
||||||
|
|
Loading…
Reference in New Issue