Get basic debug Flask application working
Now I can serve up an API endpoint that indicates the version. yay
This commit is contained in:
parent
681a62bbf5
commit
03e431a2ce
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env python3
|
||||
import vanth.main
|
||||
|
||||
|
||||
def run():
|
||||
vanth.main.main()
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
2
setup.py
2
setup.py
|
@ -99,6 +99,8 @@ def main():
|
|||
},
|
||||
install_requires = [
|
||||
'chryso==1.3',
|
||||
'Flask==0.10.1',
|
||||
'flask-login==0.3.2',
|
||||
'sepiida==5.27',
|
||||
],
|
||||
extras_require = {
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
import json
|
||||
|
||||
import flask
|
||||
import sepiida.endpoints
|
||||
import sepiida.fields
|
||||
|
||||
from vanth.version import VERSION
|
||||
|
||||
|
||||
class About(sepiida.endpoints.APIEndpoint):
|
||||
ENDPOINT = "/about/"
|
||||
SIGNATURE = sepiida.fields.JSONObject(s={
|
||||
'version' : sepiida.fields.String()
|
||||
})
|
||||
PUBLIC_METHODS = ['list']
|
||||
@staticmethod
|
||||
def list():
|
||||
return flask.make_response(json.dumps({'version': VERSION}), 200)
|
|
@ -0,0 +1,9 @@
|
|||
import sepiida.config
|
||||
|
||||
SPECIFICATION = {
|
||||
'api_token' : sepiida.config.Option(str, 'api_token'),
|
||||
'secret_key' : sepiida.config.Option(str, 'some-secret-key'),
|
||||
'session_cookie_domain' : sepiida.config.Option(str, None),
|
||||
'db' : sepiida.config.Option(str, 'postgres://vanth_dev:letmein@localhost:5432/vanth_test'),
|
||||
'debug' : sepiida.config.Option(bool, True),
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
import logging
|
||||
import os
|
||||
|
||||
import chryso.connection
|
||||
import sepiida.config
|
||||
import sepiida.log
|
||||
|
||||
import vanth.config
|
||||
import vanth.server
|
||||
import vanth.tables
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
def create_application(config):
|
||||
sepiida.log.setup_logging()
|
||||
engine = chryso.connection.Engine(config.db, vanth.tables)
|
||||
chryso.connection.store(engine)
|
||||
|
||||
LOGGER.info("Starting up vanth version %s", vanth.version.VERSION)
|
||||
application = vanth.server.create_app(config)
|
||||
return application
|
||||
|
||||
def main():
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
logging.basicConfig()
|
||||
|
||||
config = sepiida.config.load('/etc/vanth.yaml', vanth.config.SPECIFICATION)
|
||||
application = create_application(config)
|
||||
try:
|
||||
host = os.getenv('HOST', 'localhost')
|
||||
port = int(os.getenv('PORT', 4545))
|
||||
application.run(host, port)
|
||||
except KeyboardInterrupt:
|
||||
LOGGER.info('Shutting down')
|
|
@ -0,0 +1,21 @@
|
|||
from flask import Flask
|
||||
from flask_uuid import FlaskUUID
|
||||
from sepiida import endpoints
|
||||
|
||||
import vanth.api.about
|
||||
|
||||
|
||||
def create_app(config):
|
||||
app = Flask('vanth')
|
||||
|
||||
FlaskUUID(app)
|
||||
app.config.update(
|
||||
API_TOKEN = config.api_token,
|
||||
DEBUG = config.debug,
|
||||
SECRET_KEY = config.secret_key,
|
||||
SESSION_COOKIE_DOMAIN = config.session_cookie_domain,
|
||||
)
|
||||
|
||||
endpoints.add_resource(app, vanth.api.about.About, endpoint='about')
|
||||
|
||||
return app
|
Loading…
Reference in New Issue