diff --git a/.gitignore b/.gitignore index b5ce60e..cf6a489 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# virtualenv +env + # Pycharm .idea diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..1140274 --- /dev/null +++ b/config.ini @@ -0,0 +1,4 @@ +; config.ini + +[user] +BCRYPT_LOG_ROUNDS : 13 \ No newline at end of file diff --git a/cookie_api/app.py b/cookie_api/app.py index 0a432bd..c4f79bb 100644 --- a/cookie_api/app.py +++ b/cookie_api/app.py @@ -5,9 +5,9 @@ from apistar.frameworks.wsgi import WSGIApp as App from apistar.handlers import docs_urls, static_urls from apistar.interfaces import Router -from render import JSONRenderer -from commands import commands -from models.schema import Base, Cookie +from cookie_api.render import JSONRenderer +from cookie_api.commands import commands +from cookie_api.models.schema import Base, Cookie def get_cookies(session: Session): @@ -57,14 +57,13 @@ routes = [ settings = { 'DATABASE': { - 'URL': 'postgresql://:@localhost/apistar', + 'URL': 'postgresql://apistar:local@localhost/apistar', 'METADATA': Base.metadata }, 'RENDERERS': [JSONRenderer()], 'JWT': { 'SECRET': 'thisisasecret' - }, - 'BCRYPT_LOG_ROUNDS': 13 + } } commands = sqlalchemy_backend.commands + commands diff --git a/cookie_api/commands.py b/cookie_api/commands.py index 9c06112..b0c7d53 100644 --- a/cookie_api/commands.py +++ b/cookie_api/commands.py @@ -1,7 +1,7 @@ from apistar import Command from apistar.backends.sqlalchemy_backend import Session -from models.schema import User +from cookie_api.models.schema import User def create_user(session: Session, email, password): diff --git a/cookie_api/models/schema.py b/cookie_api/models/schema.py index 2d4a338..ec14f22 100644 --- a/cookie_api/models/schema.py +++ b/cookie_api/models/schema.py @@ -1,3 +1,5 @@ +from configparser import ConfigParser + import bcrypt from sqlalchemy.ext.declarative import declarative_base from sqlalchemy import Column, Integer, String, ForeignKey, DateTime, Boolean, Numeric @@ -6,6 +8,11 @@ from sqlalchemy.sql import expression from sqlalchemy.ext.compiler import compiles from sqlalchemy.types import DateTime as DateTimeType +cfg = ConfigParser() +cfg.read('config.ini') + +BCRYPT_LOG_ROUNDS = cfg.get('user', 'BCRYPT_LOG_ROUNDS') + # can be moved to models util? class utcnow(expression.FunctionElement): @@ -55,7 +62,7 @@ class User(DBMixin, Base): def __init__(self, email, password, admin=False): self.email = email - self.password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(13)).decode() + self.password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt(BCRYPT_LOG_ROUNDS)).decode() self.admin = admin diff --git a/cookie_api/render.py b/cookie_api/render.py index b751716..c1a884c 100644 --- a/cookie_api/render.py +++ b/cookie_api/render.py @@ -1,6 +1,6 @@ import json -from models.util import alchemyencoder +from cookie_api.models.util import alchemyencoder from apistar import http from apistar.renderers import Renderer @@ -11,4 +11,4 @@ class JSONRenderer(Renderer): charset = None def render(self, data: http.ResponseData) -> bytes: - return json.dumps(data, default=alchemyencoder).encode('utf-8') \ No newline at end of file + return json.dumps(data, default=alchemyencoder).encode('utf-8') diff --git a/requirements.txt b/requirements.txt index e41aac6..1a7951e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,18 +1,22 @@ -apistar==0.3.6 -apistar-jwt==0.1.2 +apistar==0.3.9 +apistar-jwt==0.2.0 +bcrypt==3.1.4 certifi==2017.7.27.1 +cffi==1.11.2 chardet==3.0.4 -coreapi==2.3.1 +colorama==0.3.9 +coreapi==2.3.3 coreschema==0.0.4 idna==2.6 itypes==1.1.0 Jinja2==2.9.6 MarkupSafe==1.0 -psycopg2==2.7.3.1 py==1.4.34 +pycparser==2.18 PyJWT==1.5.3 -pytest==3.2.2 +pytest==3.2.3 requests==2.18.4 +six==1.11.0 SQLAlchemy==1.1.14 uritemplate==3.0.0 urllib3==1.22 diff --git a/wsgi.py b/wsgi.py new file mode 100644 index 0000000..52693bf --- /dev/null +++ b/wsgi.py @@ -0,0 +1,3 @@ +if __name__ == "__main__": + from cookie_api.app import app + app.main()