Get basic debug Flask application working

Now I can serve up an API endpoint that indicates the version. yay
This commit is contained in:
Eli Ribble 2016-05-02 09:30:27 -06:00
parent 681a62bbf5
commit 03e431a2ce
6 changed files with 93 additions and 0 deletions

9
bin/vanth Normal file → Executable file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env python3
import vanth.main
def run():
vanth.main.main()
if __name__ == '__main__':
run()

View File

@ -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 = {

18
vanth/api/about.py Normal file
View File

@ -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)

9
vanth/config.py Normal file
View File

@ -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),
}

34
vanth/main.py Normal file
View File

@ -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')

21
vanth/server.py Normal file
View File

@ -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