YAML extended configuration support for 'include' keyword (#284)

pull/287/head
Chris Caron 2020-08-28 18:09:32 -04:00 committed by GitHub
parent 66d285a57e
commit cba8599764
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 4 deletions

View File

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

View File

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