Configuration¶
A global configuration is required to exists as a package
settings.default_settings. Per-installation/environment configuration is possible.
A file with suffix cfg and name set in environment variable ZSL_SETTINGS is needed.
Environment variables¶
ZSL_SETTINGSLocation of the per-installation configuration file (with *.cfg suffix).
Required fields¶
TASKSThe task router will search for task according to the task configuration. The object under this variable is an instance ofzsl.router.task.TaskConfiguration. The users register the packages holding task classes under their urls. See the example app and the following example for more.If we have a
FooApiTaskin modulemyapp.tasks.api.v1.foo_api_task, then we register it under url /api/v1 in so that we use:TASKS = TaskConfiguration()\ .create_namespace('api/v1')\ .add_packages(['myapp.tasks.api.v1'])\ .get_configuration()
Notice that all the tasks in the modules in the package
myapp.tasks.api.v1.foo_api_taskwill be routed under /api/v1 url. If one needs a more detailed routing, thenadd_routesmethod is much more convenient.RESOURCE_PACKAGESList of packages with resources. The resource router will search any resource in these packages with given order.DATABASE_URIDatabase URL for SQLAlchemy’s crate_engine.DATABASE_ENGINE_PROPSA dictionary of optional properties for the DB connection.SERVICE_INJECTIONList of services initialized and bind to the injecor after start.:SERVICE_INJECTION = ({ 'list': ['AccountService', 'BuildService'] 'package': 'app.services' })
REDISRedis configuration.
Optional fields¶
RELOADReload tasks on every call. Especially usable when debugging.DEBUGSet the debug mode -TrueorFalse.LOGGINGLogging settings are specified in LOGGING variable as a python dictionary. ZSL uses python logging as the logging infrastructure and the configuration is done accordingly.The concrete options are specified in Python Logging library in the part called dictionary configuration, just check the logging.config module documentation for more. An example is here.:
LOGGING = { 'version': 1, 'formatters': { 'default': { 'format': '%(levelname)s %(name)s %(asctime)-15s %(message)s' } }, 'handlers': { 'console': { 'class': 'logging.StreamHandler', 'formatter': 'default' }, }, 'loggers': { 'storage': { 'handlers': ['console'], 'level': 'DEBUG', 'propagate': True, } }, 'root': { 'handlers': ['console'], 'level': 'DEBUG', 'propagate': True, } }
Because of using Flask one has to provide import_name parameter to the
zsl.application.service_application.ServiceApplicationobject constructor. This import_name is also the name of the root logger used in the application. Thus it is convenient to choose as the root package name of the project.EXTERNAL_LIBRARIESAdd external libraries to path. This option will be deprecated use a correct virtualenv environment instead.:EXTERNAL_LIBRARIES = { 'vendor_path': './vendor' 'libs': ['my_lib_dir1', 'my_lib_dir2'] }
CORSThe configuration containing the default CORS/crossdomain settings. Checkzsl.application.modules.web.cors.CORSConfiguration. The available options are:origin,
allow_headers,
expose_headers,
max_age.
Check CORS explanation on Wikipedia.