mirror of https://github.com/kianby/stacosys
Configuration moved to JSON and validated by JSON Schema
parent
2c5b63fcf5
commit
754c37a373
@ -0,0 +1,147 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Created with https://app.quicktype.io
|
||||
# name: stacosys
|
||||
|
||||
json_schema = """
|
||||
{
|
||||
"$ref": "#/definitions/Stacosys",
|
||||
"definitions": {
|
||||
"Stacosys": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"general": {
|
||||
"$ref": "#/definitions/General"
|
||||
},
|
||||
"http": {
|
||||
"$ref": "#/definitions/HTTP"
|
||||
},
|
||||
"security": {
|
||||
"$ref": "#/definitions/Security"
|
||||
},
|
||||
"rss": {
|
||||
"$ref": "#/definitions/RSS"
|
||||
},
|
||||
"zmq": {
|
||||
"$ref": "#/definitions/Zmq"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"general",
|
||||
"http",
|
||||
"rss",
|
||||
"security",
|
||||
"zmq"
|
||||
],
|
||||
"title": "stacosys"
|
||||
},
|
||||
"General": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"debug": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"lang": {
|
||||
"type": "string"
|
||||
},
|
||||
"db_url": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"db_url",
|
||||
"debug",
|
||||
"lang"
|
||||
],
|
||||
"title": "general"
|
||||
},
|
||||
"HTTP": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"root_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"host": {
|
||||
"type": "string"
|
||||
},
|
||||
"port": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"host",
|
||||
"port",
|
||||
"root_url"
|
||||
],
|
||||
"title": "http"
|
||||
},
|
||||
"RSS": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"proto": {
|
||||
"type": "string"
|
||||
},
|
||||
"file": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"file",
|
||||
"proto"
|
||||
],
|
||||
"title": "rss"
|
||||
},
|
||||
"Security": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"salt": {
|
||||
"type": "string"
|
||||
},
|
||||
"secret": {
|
||||
"type": "string"
|
||||
},
|
||||
"private": {
|
||||
"type": "boolean"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"private",
|
||||
"salt",
|
||||
"secret"
|
||||
],
|
||||
"title": "security"
|
||||
},
|
||||
"Zmq": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"active": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"host": {
|
||||
"type": "string"
|
||||
},
|
||||
"pub_port": {
|
||||
"type": "integer"
|
||||
},
|
||||
"sub_port": {
|
||||
"type": "integer"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
"active",
|
||||
"host",
|
||||
"pub_port",
|
||||
"sub_port"
|
||||
],
|
||||
"title": "zmq"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: UTF-8 -*-
|
||||
|
||||
import logging
|
||||
import json
|
||||
from clize import clize, run
|
||||
from jsonschema import validate
|
||||
from conf import config, schema
|
||||
|
||||
def load_json(filename):
|
||||
jsondoc = None
|
||||
with open(filename, 'rt') as json_file:
|
||||
jsondoc = json.loads(json_file.read())
|
||||
return jsondoc
|
||||
|
||||
|
||||
@clize
|
||||
def stacosys_server(config_pathname):
|
||||
|
||||
# load and validate startup config
|
||||
conf = load_json(config_pathname)
|
||||
json_schema = json.loads(schema.json_schema)
|
||||
v = validate(conf, json_schema)
|
||||
print('validation: {}'.format(v))
|
||||
|
||||
# set configuration
|
||||
config.general = conf['general']
|
||||
config.http = conf['http']
|
||||
config.security = conf['security']
|
||||
config.rss = conf['rss']
|
||||
config.zmq = conf['zmq']
|
||||
|
||||
# start application
|
||||
from core import app
|
||||
|
||||
if __name__ == '__main__':
|
||||
run(stacosys_server)
|
@ -0,0 +1,27 @@
|
||||
{
|
||||
"general" : {
|
||||
"debug": true,
|
||||
"lang": "fr",
|
||||
"db_url": "sqlite:///db.sqlite"
|
||||
},
|
||||
"http": {
|
||||
"root_url": "http://localhost:8100",
|
||||
"host": "127.0.0.1",
|
||||
"port": 8100
|
||||
},
|
||||
"security": {
|
||||
"salt": "BRRJRqXgGpXWrgTidBPcixIThHpDuKc0",
|
||||
"secret": "Uqca5Kc8xuU6THz9",
|
||||
"private": true
|
||||
},
|
||||
"rss": {
|
||||
"proto": "http",
|
||||
"file": "comments.xml"
|
||||
},
|
||||
"zmq": {
|
||||
"active": true,
|
||||
"host": "127.0.0.1",
|
||||
"pub_port": 7701,
|
||||
"sub_port": 7702
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
# Configuration file
|
||||
|
||||
DEBUG = True
|
||||
|
||||
LANG = "fr"
|
||||
|
||||
# DB_URL = "mysql://stacosys_user:stacosys_password@localhost:3306/stacosys"
|
||||
DB_URL = "sqlite:///db.sqlite"
|
||||
|
||||
MAIL_URL = "http://localhost:8025/mbox"
|
||||
|
||||
HTTP_ADDRESS = "127.0.0.1"
|
||||
HTTP_PORT = 8100
|
||||
HTTP_WORKERS = 1
|
||||
|
||||
SALT = "BRRJRqXgGpXWrgTidBPcixIThHpDuKc0"
|
||||
|
||||
SECRET = "Uqca5Kc8xuU6THz9"
|
||||
|
||||
ROOT_URL = 'http://localhost:8100'
|
||||
|
||||
RSS_URL_PROTO = 'http'
|
||||
RSS_FILE = 'comments.xml'
|
||||
|
||||
PRIVATE = True
|
@ -1,11 +1,19 @@
|
||||
attrs==17.4.0
|
||||
chardet==3.0.4
|
||||
click==6.7
|
||||
clize==4.0.3
|
||||
docutils==0.14
|
||||
Flask==0.12.2
|
||||
Flask-Cors==3.0.3
|
||||
itsdangerous==0.24
|
||||
Jinja2==2.10
|
||||
jsonschema==2.6.0
|
||||
Markdown==2.6.11
|
||||
MarkupSafe==1.0
|
||||
od==1.0
|
||||
peewee==2.10.2
|
||||
PyRSS2Gen==1.1
|
||||
pyzmq==16.0.3
|
||||
sigtools==2.0.1
|
||||
six==1.11.0
|
||||
Werkzeug==0.14.1
|
||||
|
Loading…
Reference in New Issue