Allow piecemeal overrides of tokenserver backend default config.

Before this change, you have either have to accept the default config
for the tokenserver backend, or specify all config options and hence
duplicate info from earlier in the file.  With this change you can
now just specify anything you want to change and we'll use the defaults
for the rest.
This commit is contained in:
Ryan Kelly 2017-04-10 11:49:33 +10:00
parent 8e693129e6
commit 7fe5c0fafc

View File

@ -22,6 +22,9 @@ from tokenserver.util import _JSONError
logger = logging.getLogger("syncserver") logger = logging.getLogger("syncserver")
DEFAULT_TOKENSERVER_BACKEND = "syncserver.staticnode.StaticNodeAssignment"
def includeme(config): def includeme(config):
"""Install SyncServer application into the given Pyramid configurator.""" """Install SyncServer application into the given Pyramid configurator."""
# Set the umask so that files are created with secure permissions. # Set the umask so that files are created with secure permissions.
@ -53,10 +56,15 @@ def includeme(config):
settings.pop("config", None) settings.pop("config", None)
if "tokenserver.backend" not in settings: if "tokenserver.backend" not in settings:
# Default to our simple static node-assignment backend # Default to our simple static node-assignment backend
settings["tokenserver.backend"] =\ settings["tokenserver.backend"] = DEFAULT_TOKENSERVER_BACKEND
"syncserver.staticnode.StaticNodeAssignment" if settings["tokenserver.backend"] == DEFAULT_TOKENSERVER_BACKEND:
# Provide some additional defaults for the default backend,
# unless overridden in the config.
if "tokenserver.sqluri" not in settings:
settings["tokenserver.sqluri"] = sqluri settings["tokenserver.sqluri"] = sqluri
if "tokenserver.node_url" not in settings:
settings["tokenserver.node_url"] = public_url settings["tokenserver.node_url"] = public_url
if "endpoints.sync-1.5" not in settings:
settings["endpoints.sync-1.5"] = "{node}/storage/1.5/{uid}" settings["endpoints.sync-1.5"] = "{node}/storage/1.5/{uid}"
if "tokenserver.monkey_patch_gevent" not in settings: if "tokenserver.monkey_patch_gevent" not in settings:
# Default to no gevent monkey-patching # Default to no gevent monkey-patching