Compare commits

..

No commits in common. 'develop' and 'master' have entirely different histories.

@ -1,3 +1,2 @@
include wsgi
recursive-include cookie_api/templates *
recursive-include cookie_api/static *

@ -1,4 +1,5 @@
from apistar import Route, App
from apistar import Route
from apistar.http import HTMLResponse
from apistar_jwt import JWT
from apistar_mail import MailComponent
import logbook
@ -6,9 +7,9 @@ from sqlalchemy import create_engine
from pathlib import Path
from cookie_api.auth import auth_routes
from cookie_api.logger import init_logging
from cookie_api.logger import global_init
from cookie_api.resources import cookie_routes
from cookie_api.util import SQLAlchemyHook, SQLAlchemySession
from cookie_api.util import SQLAlchemyHook, SQLAlchemySession, MetaApp as App
BASEDIR = Path(__file__).parent
TEMPLATE_DIR = BASEDIR.joinpath('templates')
@ -16,15 +17,18 @@ STATIC_DIR = BASEDIR.joinpath('static')
logger = logbook.Logger(__name__)
engine = create_engine('postgresql://apistar@localhost:5432/apistar')
app_settings = {
"LOGGING": {
"LEVEL": "INFO"
"LEVEL": "DEBUG"
}
}
def return_index_html(app: App):
return app.render_template('index.html')
def return_index_html():
with open(STATIC_DIR.joinpath('index.html'), mode='rb') as f:
return HTMLResponse(content=f.read())
index = Route('/', 'GET', return_index_html)
@ -34,7 +38,7 @@ _routes = cookie_routes + auth_routes + [index]
_hooks = [SQLAlchemyHook]
_components = [
SQLAlchemySession(engine=create_engine('postgresql://apistar@localhost:5432/apistar')),
SQLAlchemySession(engine=engine),
JWT({
'JWT_USER_ID': 'sub',
'JWT_SECRET': 'thisisasecret',
@ -56,8 +60,7 @@ def application_factory(routes=_routes, components=_components, hooks=_hooks, se
"""Returns an instance of Cookie API"""
_settings = {**app_settings, **settings}
init_logging(_settings)
global_init(_settings)
logger.debug("Template directory {}".format(template_dir))
logger.debug("Static directory {}".format(STATIC_DIR))

@ -2,7 +2,7 @@ import sys
import logbook
def init_logging(settings={}):
def global_init(settings={}):
_logging_setting = settings.get("LOGGING", {"LEVEL": logbook.TRACE})
_log_file = _logging_setting.get("LOG_FILE")

@ -10,10 +10,12 @@ from sqlalchemy.types import DateTime as DateTimeType
BCRYPT_LOG_ROUNDS = 11
# can be moved to models util?
class utcnow(expression.FunctionElement):
type = DateTimeType()
# Can be moved to the models util?
@compiles(utcnow, 'postgresql')
def pg_utcnow(element, compiler, **kw):
return "TIMEZONE('utc', CURRENT_TIMESTAMP)"

@ -1,7 +1,7 @@
import typing
import logbook
from apistar import Route, App
from apistar import http, Route, App
from apistar_jwt import authentication_required, JWTUser
from sqlalchemy.orm import Session

@ -11,7 +11,7 @@
<div id="app">
<ul>
<li v-for="cookie in cookies">
{% raw %}{{ cookie.name }} {% endraw%}
{{ cookie.name }}
</li>
</ul>
</div>

@ -1,4 +1,5 @@
from .app import MetaApp
from .http import MetaJSONResponse, ExtJSONResponse
from .component import SQLAlchemySession, DBSession
from .hook import SQLAlchemyHook
from .validators import Decimal
from .validators import Decimal

@ -0,0 +1,28 @@
import sys
from apistar import App, exceptions
from apistar.http import Response, HTMLResponse
from apistar.server.components import ReturnValue
from .http import MetaJSONResponse
class MetaApp(App):
"""
A WSGI App subclass with a MetaJSONResponse default response type
"""
def render_response(self, return_value: ReturnValue) -> Response:
if isinstance(return_value, Response):
return return_value
elif isinstance(return_value, str):
return HTMLResponse(return_value)
return MetaJSONResponse(return_value)
def exception_handler(self, exc: Exception) -> Response:
if isinstance(exc, exceptions.HTTPException):
return MetaJSONResponse(exc.detail, status_code=exc.status_code, headers=exc.get_headers())
raise
def error_handler(self) -> Response:
return MetaJSONResponse('Server error', status_code=500, exc_info=sys.exc_info())

@ -1,7 +1,6 @@
from apistar.http import Response
from .component import Session, DBSession
class SQLAlchemyHook:
def on_request(self, session: Session):
return
@ -13,4 +12,4 @@ class SQLAlchemyHook:
def on_error(self, session: Session, response: Response):
session.rollback()
DBSession.remove()
return response
return response

@ -4,10 +4,7 @@
#
# pip-compile --output-file dev_requirements.txt dev_requirements.in
#
--trusted-host pypi.python.org
--trusted-host git.aigalatic.com
alembic==0.9.10
alembic==0.9.9
atomicwrites==1.1.5 # via pytest
attrs==18.1.0 # via pytest
coverage==4.5.1 # via pytest-cov
@ -15,12 +12,12 @@ mako==1.0.7 # via alembic
markupsafe==1.0 # via mako
more-itertools==4.2.0 # via pytest
pluggy==0.6.0 # via pytest, tox
py==1.5.4 # via pytest, tox
py==1.5.3 # via pytest, tox
pytest-cov==2.5.1
pytest==3.6.3
pytest==3.6.1
python-dateutil==2.7.3 # via alembic
python-editor==1.0.3 # via alembic
six==1.11.0 # via more-itertools, pytest, python-dateutil, tox
sqlalchemy==1.2.9 # via alembic
sqlalchemy==1.2.8 # via alembic
tox==3.0.0
virtualenv==16.0.0 # via tox

@ -1,8 +0,0 @@
apistar
apistar-jwt
apistar-mail
bcrypt
psycopg2-binary
itsdangerous
logbook
sqlalchemy

@ -2,31 +2,28 @@
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile --output-file requirements.txt requirements.in
# pip-compile --output-file requirements.txt setup.py
#
--trusted-host pypi.python.org
--trusted-host git.aigalatic.com
apistar-jwt==0.5.0
apistar-jwt==0.4.2
apistar-mail==0.3.0
apistar==0.5.40
apistar==0.5.18
bcrypt==3.1.4
certifi==2018.4.16 # via requests
cffi==1.11.5 # via bcrypt
chardet==3.0.4 # via requests
click==6.7 # via apistar
idna==2.7 # via requests
idna==2.6 # via requests
itsdangerous==0.24
jinja2==2.10 # via apistar
logbook==1.4.0
logbook==1.3.3
markupsafe==1.0 # via jinja2
psycopg2-binary==2.7.5
psycopg2-binary==2.7.4
pycparser==2.18 # via cffi
pyjwt==1.6.4 # via apistar-jwt
pyyaml==3.12 # via apistar
requests==2.19.1 # via apistar
requests==2.18.4 # via apistar
six==1.11.0 # via bcrypt
sqlalchemy==1.2.9
urllib3==1.23 # via requests
sqlalchemy==1.2.8
urllib3==1.22 # via requests
werkzeug==0.14.1 # via apistar
whitenoise==3.3.1 # via apistar

@ -4,14 +4,14 @@ with open('README.md') as readme_file:
readme = readme_file.read()
requirements = [
'apistar-jwt==0.5.0',
'apistar-jwt==0.4.2',
'apistar-mail==0.3.0',
'apistar==0.5.40',
'apistar==0.5.18',
'bcrypt==3.1.4',
'itsdangerous==0.24',
'logbook==1.4.0',
'psycopg2-binary==2.7.5',
'sqlalchemy==1.2.9',
'logbook==1.3.3',
'psycopg2-binary==2.7.4',
'sqlalchemy==1.2.8',
]
test_requirements = [
@ -40,7 +40,7 @@ setup(
'Development Status :: 2 - Pre-Alpha',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'License :: OSI Approved :: BSD License',
'Natural Language :: English',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
@ -50,7 +50,7 @@ setup(
},
entry_points={
'console_scripts': [
'wsgi_serve=wsgi:main'
'wsgi_runner=wsgi:main'
]
}
)

@ -12,7 +12,7 @@ from sqlalchemy import create_engine
from cookie_api import application_factory
from cookie_api.util import SQLAlchemySession, SQLAlchemyHook
from config import db_config, jwt_config, mail_config, logging_config
from config import db_config, jwt_config, mail_config
components = [
SQLAlchemySession(create_engine(db_config)),
@ -24,7 +24,7 @@ hooks = [
SQLAlchemyHook()
]
app = application_factory(components=components, hooks=hooks, settings={**logging_config})
app = application_factory(components=components, hooks=hooks)
def main():
@ -32,4 +32,4 @@ def main():
if __name__ == '__main__':
main()
main()
Loading…
Cancel
Save