aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/apprise/AppriseConfig.py
diff options
context:
space:
mode:
authorLouis Vézina <[email protected]>2020-09-14 08:24:26 -0400
committerLouis Vézina <[email protected]>2020-09-14 08:24:26 -0400
commite6b8b1ad195d553bca2ecff7e52f67ba4f5871ec (patch)
treefd56bb19e90afbf87bf845a74d69ca17cda0deff /libs/apprise/AppriseConfig.py
parentae731bb78b1d91b3e7f6017830c4014fae4aa6ff (diff)
downloadbazarr-e6b8b1ad195d553bca2ecff7e52f67ba4f5871ec.tar.gz
bazarr-e6b8b1ad195d553bca2ecff7e52f67ba4f5871ec.zip
Updated Apprise to 0.8.8
Diffstat (limited to 'libs/apprise/AppriseConfig.py')
-rw-r--r--libs/apprise/AppriseConfig.py85
1 files changed, 80 insertions, 5 deletions
diff --git a/libs/apprise/AppriseConfig.py b/libs/apprise/AppriseConfig.py
index 902dfa6dd..fa5e6fba9 100644
--- a/libs/apprise/AppriseConfig.py
+++ b/libs/apprise/AppriseConfig.py
@@ -27,6 +27,7 @@ import six
from . import config
from . import ConfigBase
+from . import CONFIG_FORMATS
from . import URLBase
from .AppriseAsset import AppriseAsset
@@ -46,7 +47,8 @@ class AppriseConfig(object):
"""
- def __init__(self, paths=None, asset=None, cache=True, **kwargs):
+ def __init__(self, paths=None, asset=None, cache=True, recursion=0,
+ insecure_includes=False, **kwargs):
"""
Loads all of the paths specified (if any).
@@ -69,6 +71,29 @@ class AppriseConfig(object):
It's also worth nothing that the cache value is only set to elements
that are not already of subclass ConfigBase()
+
+ recursion defines how deep we recursively handle entries that use the
+ `import` keyword. This keyword requires us to fetch more configuration
+ from another source and add it to our existing compilation. If the
+ file we remotely retrieve also has an `import` reference, we will only
+ advance through it if recursion is set to 2 deep. If set to zero
+ it is off. There is no limit to how high you set this value. It would
+ be recommended to keep it low if you do intend to use it.
+
+ insecure includes by default are disabled. When set to True, all
+ Apprise Config files marked to be in STRICT mode are treated as being
+ in ALWAYS mode.
+
+ Take a file:// based configuration for example, only a file:// based
+ configuration can import another file:// based one. because it is set
+ to STRICT mode. If an http:// based configuration file attempted to
+ import a file:// one it woul fail. However this import would be
+ possible if insecure_includes is set to True.
+
+ There are cases where a self hosting apprise developer may wish to load
+ configuration from memory (in a string format) that contains import
+ entries (even file:// based ones). In these circumstances if you want
+ these includes to be honored, this value must be set to True.
"""
# Initialize a server list of URLs
@@ -81,13 +106,20 @@ class AppriseConfig(object):
# Set our cache flag
self.cache = cache
+ # Initialize our recursion value
+ self.recursion = recursion
+
+ # Initialize our insecure_includes flag
+ self.insecure_includes = insecure_includes
+
if paths is not None:
# Store our path(s)
self.add(paths)
return
- def add(self, configs, asset=None, tag=None, cache=True):
+ def add(self, configs, asset=None, tag=None, cache=True, recursion=None,
+ insecure_includes=None):
"""
Adds one or more config URLs into our list.
@@ -107,6 +139,12 @@ class AppriseConfig(object):
It's also worth nothing that the cache value is only set to elements
that are not already of subclass ConfigBase()
+
+ Optionally override the default recursion value.
+
+ Optionally override the insecure_includes flag.
+ if insecure_includes is set to True then all plugins that are
+ set to a STRICT mode will be a treated as ALWAYS.
"""
# Initialize our return status
@@ -115,6 +153,14 @@ class AppriseConfig(object):
# Initialize our default cache value
cache = cache if cache is not None else self.cache
+ # Initialize our default recursion value
+ recursion = recursion if recursion is not None else self.recursion
+
+ # Initialize our default insecure_includes value
+ insecure_includes = \
+ insecure_includes if insecure_includes is not None \
+ else self.insecure_includes
+
if asset is None:
# prepare default asset
asset = self.asset
@@ -154,7 +200,8 @@ class AppriseConfig(object):
# Instantiate ourselves an object, this function throws or
# returns None if it fails
instance = AppriseConfig.instantiate(
- _config, asset=asset, tag=tag, cache=cache)
+ _config, asset=asset, tag=tag, cache=cache,
+ recursion=recursion, insecure_includes=insecure_includes)
if not isinstance(instance, ConfigBase):
return_status = False
continue
@@ -165,7 +212,8 @@ class AppriseConfig(object):
# Return our status
return return_status
- def add_config(self, content, asset=None, tag=None, format=None):
+ def add_config(self, content, asset=None, tag=None, format=None,
+ recursion=None, insecure_includes=None):
"""
Adds one configuration file in it's raw format. Content gets loaded as
a memory based object and only exists for the life of this
@@ -174,8 +222,22 @@ class AppriseConfig(object):
If you know the format ('yaml' or 'text') you can specify
it for slightly less overhead during this call. Otherwise the
configuration is auto-detected.
+
+ Optionally override the default recursion value.
+
+ Optionally override the insecure_includes flag.
+ if insecure_includes is set to True then all plugins that are
+ set to a STRICT mode will be a treated as ALWAYS.
"""
+ # Initialize our default recursion value
+ recursion = recursion if recursion is not None else self.recursion
+
+ # Initialize our default insecure_includes value
+ insecure_includes = \
+ insecure_includes if insecure_includes is not None \
+ else self.insecure_includes
+
if asset is None:
# prepare default asset
asset = self.asset
@@ -190,7 +252,13 @@ class AppriseConfig(object):
# Create ourselves a ConfigMemory Object to store our configuration
instance = config.ConfigMemory(
- content=content, format=format, asset=asset, tag=tag)
+ content=content, format=format, asset=asset, tag=tag,
+ recursion=recursion, insecure_includes=insecure_includes)
+
+ if instance.config_format not in CONFIG_FORMATS:
+ logger.warning(
+ "The format of the configuration could not be deteced.")
+ return False
# Add our initialized plugin to our server listings
self.configs.append(instance)
@@ -235,6 +303,7 @@ class AppriseConfig(object):
@staticmethod
def instantiate(url, asset=None, tag=None, cache=None,
+ recursion=0, insecure_includes=False,
suppress_exceptions=True):
"""
Returns the instance of a instantiated configuration plugin based on
@@ -279,6 +348,12 @@ class AppriseConfig(object):
# Force an over-ride of the cache value to what we have specified
results['cache'] = cache
+ # Recursion can never be parsed from the URL
+ results['recursion'] = recursion
+
+ # Insecure includes flag can never be parsed from the URL
+ results['insecure_includes'] = insecure_includes
+
if suppress_exceptions:
try:
# Attempt to create an instance of our plugin using the parsed