From 6bbe221ede3524487b6d59debf0587a42adc91be Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 19 Sep 2017 17:20:19 -0400 Subject: [PATCH 01/17] Add limit and order_by in base view --- app/controllers/base.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/controllers/base.py b/app/controllers/base.py index 8d5ad7a..7d1e1b3 100644 --- a/app/controllers/base.py +++ b/app/controllers/base.py @@ -54,6 +54,13 @@ class RestController(object): for k, f in self.filters.items(): if k in filter_data: q = q.filter(f(filter_data)) + + if 'order_by' in filter_data: + q = q.order_by(getattr(self.Model, filter_data['order_by'])) + + if 'limit' in filter_data: + q = q.limit(int(filter_data['limit'])) + return q def get_form(self, filter_data): -- GitLab From 19d7991c2137d433535ccd8ffa7ef975574390f3 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Thu, 21 Sep 2017 14:46:59 -0400 Subject: [PATCH 02/17] Add sort param to filter --- app/controllers/base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/base.py b/app/controllers/base.py index 7d1e1b3..546e7de 100644 --- a/app/controllers/base.py +++ b/app/controllers/base.py @@ -56,7 +56,13 @@ class RestController(object): q = q.filter(f(filter_data)) if 'order_by' in filter_data: - q = q.order_by(getattr(self.Model, filter_data['order_by'])) + order_by = getattr(self.Model, filter_data['order_by']) + sort = '' + + if 'sort' in filter_data: + sort = filter_data['sort'] + + q = q.order_by('{} {}'.format(order_by, sort)) if 'limit' in filter_data: q = q.limit(int(filter_data['limit'])) -- GitLab From 0ec524151bd3636cbf61f71448cdcb79c92b5d23 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 25 Sep 2017 17:20:39 -0400 Subject: [PATCH 03/17] Add user to flask.g --- app/permissions/auth.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/permissions/auth.py b/app/permissions/auth.py index fb6bfbd..de95310 100644 --- a/app/permissions/auth.py +++ b/app/permissions/auth.py @@ -1,5 +1,5 @@ """Permissions to check authentication.""" -from flask import current_app +from flask import current_app, g from werkzeug.exceptions import Unauthorized from jose import jwt import json @@ -49,6 +49,7 @@ class AuthNeed(Permission): audience=API_AUDIENCE, issuer="https://"+AUTH0_DOMAIN+"/" ) + g.sub = payload['sub'] # For now we will print and return unauthorized. In the future # we will log these errors and the requester except jwt.ExpiredSignatureError: -- GitLab From fcc2f863920024a48b6c2751e2c826a9e029983f Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 12:51:56 -0400 Subject: [PATCH 04/17] Update base controller class to use bpvalve --- app/controllers/base.py | 146 +++------------------------------------- requirements.txt | 1 + 2 files changed, 10 insertions(+), 137 deletions(-) diff --git a/app/controllers/base.py b/app/controllers/base.py index 546e7de..2cdbaf1 100644 --- a/app/controllers/base.py +++ b/app/controllers/base.py @@ -1,140 +1,12 @@ -from sqlalchemy.exc import IntegrityError -from werkzeug.datastructures import MultiDict -from werkzeug.exceptions import NotFound, BadRequest -from flask import current_app +"""Flask RestController wrapper""" +from bpvalve.flask.controllers import RestController as BaseRestController +from app.lib.database import db +from app.lib.red import redis -from ..lib.database import db, commit - -class RestController(object): - """A RESTful class for manipulating database objects. - - Controllers should be request-agnostic. The can be initialized and used - outside of a request context. This provides a convenient place to dump - complicated filters or additional data manipulation that happens before - or after a database fetch. +class RestController(BaseRestController): """ - # The model associated with this REST resource. - Model = None - # A dictionary of available filters on the resource. - # - # For each key in this dictionary, if the key is present in the dictionary, - # the value associated with that key (a function taking one argument) is - # passed the filter_data dictionary and the return value is used as a - # database filter. For example, - # - # { - # 'id_': lambda d: Model.id_ == d['id_'] - # } - # - # There is no requirement that the filter function only manipulate its - # key, so these filters can be arbitrarily complex as needed. Multiline - # filters should be defined as separate functions and referenced here. - filters = {} - - # The primary key to use to retrieve the model in get/put/delete requests. - key = 'id' - - def query(self, filter_data): - """Construct a query for the model. - - Args: - filter_data - A dictionary representing the query string - parameters. This is unused at the moment. - """ - return db.session.query(self.Model) - - def filter(self, q, filter_data): - """Parse a dictionary representing the query parameters into database - filters. - - q - A SQLAlchemy query. - filter_data - A dictionary representing the query string parameters. - """ - for k, f in self.filters.items(): - if k in filter_data: - q = q.filter(f(filter_data)) - - if 'order_by' in filter_data: - order_by = getattr(self.Model, filter_data['order_by']) - sort = '' - - if 'sort' in filter_data: - sort = filter_data['sort'] - - q = q.order_by('{} {}'.format(order_by, sort)) - - if 'limit' in filter_data: - q = q.limit(int(filter_data['limit'])) - - return q - - def get_form(self, filter_data): - """Get the WTForms form for the model.""" - pass - - def index(self, filter_data): - """Get a query for all models matching filter_data.""" - q = self.query(filter_data) - q = self.filter(q, filter_data) - return q.all() - - def get(self, id_, filter_data): - """Get a single model matching an id.""" - model = db.session.query(self.Model)\ - .filter(getattr(self.Model, self.key)==id_).first() - if not model: - raise NotFound - return model - - def create(self, data, filter_data): - """Creates a model, but does not add it to the database.""" - model = self.Model() - form = self.get_form(filter_data)(formdata=MultiDict(data)) - - if not form.validate(): - raise BadRequest(form.errors) - - form.populate_obj(model) - return model - - def post(self, data, filter_data): - """Post a new model from a dictionary.""" - model = self.create(data, filter_data) - db.session.add(model) - try: - commit() - except IntegrityError as e: - raise ( - BadRequest(str(e)) if current_app.config['DEBUG'] else - BadRequest) - - return model - - def put(self, id_, data, filter_data): - """Change an existing model using an id and dictionary data.""" - model = self.get(id_, filter_data) - form = self.get_form(filter_data)(formdata=MultiDict(data)) - - if not str(form.id.data) == str(id_): - raise BadRequest(['The id in the model and the uri do not match.']) - if not form.validate(): - raise BadRequest(form.errors) - - form.populate_obj(model) - db.session.add(model) - try: - commit() - except IntegrityError as e: - raise ( - BadRequest(str(e)) if current_app.config['DEBUG'] else - BadRequest) - - return model - - def delete(self, id_, filter_data): - """Delete a model given its id.""" - model = self.get(id_, filter_data) - db.session.delete(model) - commit() - return {} + Wrapper for BaseRestController + """ + db = db + redis = redis diff --git a/requirements.txt b/requirements.txt index 0a28abd..34ee5f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ arrow==0.7.0 blessed==1.9.5 botocore==1.3.28 +https://github.com/Blocp/bpvalve@v1.1.0 cement==2.4.0 colorama==0.3.3 docker-py==1.1.0 -- GitLab From 13c6edcbd9e798bcc15bc5a0e2bbda167f8d66fe Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 12:58:00 -0400 Subject: [PATCH 05/17] Update dev requirements --- requirements-dev.txt | 3 +++ setup.cfg | 9 +++++++++ 2 files changed, 12 insertions(+) create mode 100644 setup.cfg diff --git a/requirements-dev.txt b/requirements-dev.txt index 5660f02..2748f38 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,6 +1,9 @@ -r requirements.txt Flask-Testing==0.4.2 nose==1.3.7 +pycodestyle>=2.3.1 +pydocstyle>=1.1.1 pytest==2.9.1 pylint>=1.6.5 pylint-flask>=0.5 +yapf>=0.16.1 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..64a0dfb --- /dev/null +++ b/setup.cfg @@ -0,0 +1,9 @@ +[pycodestyle] +max-line-length=100 + +[isort] +line_length=100 + +[yapf] +based_on_style=pep8 +spaces_before_comment=1 -- GitLab From 7a46dd4eeb327d1e842b91e8a5447cb79d433bd5 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 12:59:31 -0400 Subject: [PATCH 06/17] Use ssh for bpvalve --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 34ee5f4..e760f52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ arrow==0.7.0 blessed==1.9.5 botocore==1.3.28 -https://github.com/Blocp/bpvalve@v1.1.0 +git+ssh://git@github.com/Blocp/bpvalve.git@v1.1.0 cement==2.4.0 colorama==0.3.3 docker-py==1.1.0 -- GitLab From 11331ead79c97369c82e3f656e88ed4be086220b Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 14:03:17 -0400 Subject: [PATCH 07/17] Import UnprotectedRestView from bpvalve --- app/views/base.py | 69 +++-------------------------------------------- 1 file changed, 3 insertions(+), 66 deletions(-) diff --git a/app/views/base.py b/app/views/base.py index 1a175c5..4700da8 100644 --- a/app/views/base.py +++ b/app/views/base.py @@ -1,71 +1,8 @@ -import json -from werkzeug.exceptions import NotFound -from flask import jsonify, request, current_app -from flask.ext.classy import FlaskView -from app.lib.database import db -from app.lib.red import redis +from bpvalve.flask.views import UnprotectedRestView from app.permissions.auth import standard_login_need -class View(FlaskView): - """A base view to provide convenience methods to subclasses.""" - def request_json(self): - """Return json parsed from the request.""" - return json.loads(request.data.decode('utf-8')) - - def json(self, obj, status=200): - """A wrapper for Flask's jsonify().""" - response = jsonify(data=obj) - return response, status - - def parse(self, model): - """Parse the model into a dictionary.""" - return model.get_dictionary() - - -class UnprotectedRestView(View): - """A view wrapper for RESTful controllers that does not offer API - protection. - - Views should remain agnostic to the database (with the exception of - permissions). In general, the view is responsible for parsing the - request, checking permissions, calling the controller, and parsing that - return into a json output. - """ - def get_controller(self): - """Return a controller instance to use for database interactions.""" - pass - - def index(self): - """/ GET - Retrieve a list of resources.""" - return self.json([ - self.parse(m) for m in self.get_controller().index(request.args) - ]) - - def get(self, id_): - """/{id} GET - Retrieve a resource by id.""" - return self.json(self.parse( - self.get_controller().get(id_, request.args) - )) - - def post(self): - """/ POST - Post a new resource.""" - return self.json(self.parse( - self.get_controller().post(self.request_json(), request.args) - ), 201) - - def put(self, id_): - """/{id} PUT - Modify a resource by id.""" - return self.json(self.parse( - self.get_controller().put(id_, self.request_json(), request.args) - )) - - def delete(self, id_): - """/{id} DELETE - Delete a resource by id.""" - return self.json(self.get_controller().delete(id_, request.args), 204) - - class RestView(UnprotectedRestView): - """A view wrapper for RESTful controllers that _does_ offer API protection. - """ + """A view wrapper for RESTful controllers that _does_ offer API protection.""" + decorators = (standard_login_need,) -- GitLab From 3be40b7f4236da36d4326b0625f5ccd1dab528ed Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 18:49:44 -0400 Subject: [PATCH 08/17] Add auth0 and update init of lib and RestController imports --- app/controllers/base.py | 4 ++-- app/lib/__init__.py | 3 +++ app/lib/auth0.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 app/lib/auth0.py diff --git a/app/controllers/base.py b/app/controllers/base.py index 2cdbaf1..cf86692 100644 --- a/app/controllers/base.py +++ b/app/controllers/base.py @@ -1,7 +1,6 @@ """Flask RestController wrapper""" from bpvalve.flask.controllers import RestController as BaseRestController -from app.lib.database import db -from app.lib.red import redis +from app.lib import db, redis, auth0_ class RestController(BaseRestController): @@ -10,3 +9,4 @@ class RestController(BaseRestController): """ db = db redis = redis + auth0 = auth0_ diff --git a/app/lib/__init__.py b/app/lib/__init__.py index e69de29..3fac200 100644 --- a/app/lib/__init__.py +++ b/app/lib/__init__.py @@ -0,0 +1,3 @@ +from .database import db +from .red import redis +from .auth0 import auth0_ diff --git a/app/lib/auth0.py b/app/lib/auth0.py new file mode 100644 index 0000000..3014a0a --- /dev/null +++ b/app/lib/auth0.py @@ -0,0 +1,19 @@ +from bpvalve.auth0 import Auth0Wrapper + + +class FlaskAuth0: + """Initilalization class for Auth0Wrapper""" + + def init_app(self, app): + """Intialize Auth0Wrapper""" + self.auth = Auth0Wrapper(app.config.get('AUTH0_DOMAIN'), + app.config.get('AUTH0_CLIENT_ID'), + app.config.get('AUTH0_CLIENT_SECRET'), + 'https://{}/api/v2/'.format(app.config.get('AUTH0_DOMAIN'))) + +auth0_ = FlaskAuth0() + + +def register(app): + """Configure the Auth0Wrapper based on the app configuration.""" + auth0_.init_app(app) -- GitLab From 1c2cc4239442a6301f58b7a207fc8ab7a2e43642 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 18:50:26 -0400 Subject: [PATCH 09/17] Condense registeration of flask app --- app/__init__.py | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index da6671a..cbc3607 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -22,25 +22,15 @@ def create_app(config): app.logger.info('Setting up application...') - from .lib import database - database.register(app) - - from .lib import red - red.register(app) - from . import views views.register(app) - from .lib import exceptions - exceptions.register(app) - - from .lib import service - service.register(app) - - from .lib import session - session.register(app) + from app.lib import database, red, exceptions, service, session, auth0 + services = (database, red, exceptions, service, session, auth0) + for service in services: + service.register(app) - with app.app_context(): - database.db.create_all() + # with app.app_context(): + # database.db.create_all() return app -- GitLab From 6f2794035a842f14cc1912807cebffaf9a9867cd Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 18:53:18 -0400 Subject: [PATCH 10/17] Update package init with module docstring --- app/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index cbc3607..dc103fa 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -1,3 +1,4 @@ +"""BP flask microservices""" import logging from logging.handlers import RotatingFileHandler from flask import Flask @@ -6,6 +7,7 @@ MEGABYTE = 10**6 LOG_FORMAT = '[%(asctime)s] %(pathname)s:%(lineno)d %(levelname)s - %(message)s' LOG_PATH = '/var/log/flask.log' + def create_app(config): """Set up the application.""" app = Flask(__name__) -- GitLab From 3c0e43c73c97c984b29ef65abd5b587a569e3f04 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 9 Oct 2017 18:56:40 -0400 Subject: [PATCH 11/17] Import RedisWrapper from bpvalve --- app/lib/red.py | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/app/lib/red.py b/app/lib/red.py index 43c02fa..2a55615 100644 --- a/app/lib/red.py +++ b/app/lib/red.py @@ -1,32 +1,4 @@ -"""A library for interacting with redis.""" -from redis import StrictRedis -from parse import parse - - -class RedisWrapper(object): - """A wrapper for Redis.""" - def get_database(self, database): - """Gets an actual database.""" - return StrictRedis(host=self.host, port=self.port, db=database) - - def init_app(self, app): - """Stores information about the redis database from the URI.""" - uri = app.config.get('REDIS_URI') - self.host, self.port = parse('redis://{}:{}/', uri) - - # key/tokens for applications that this service serves. - self.server_apps = self.get_database(0) - # key/tokens for applications that this service consumes. - self.client_apps = self.get_database(1) - # key/tokens for users - self.users = self.get_database(2) - - def flushdb(self): - """Flushes each database.""" - self.server_apps.flushdb() - self.client_apps.flushdb() - self.users.flushdb() - +from bpvalve.flask.lib.red import RedisWrapper redis = RedisWrapper() -- GitLab From db156712a8d0ad8cb5827d3d98e4d4503a4a7c72 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Tue, 10 Oct 2017 16:04:18 -0400 Subject: [PATCH 12/17] Add user model and form --- app/forms/base.py | 5 +++++ app/models/base.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/app/forms/base.py b/app/forms/base.py index 8118e93..a886f9c 100644 --- a/app/forms/base.py +++ b/app/forms/base.py @@ -9,6 +9,11 @@ class Form(wtf.Form): id = wtf.IntegerField() +class UserForm: + user_created = wtf.StringField(validators=[wtf.validators.Length(max=64)]) + user_modified = wtf.StringField(validators=[wtf.validators.Length(max=64)]) + + class AddressForm(object): """A form for validating address information.""" street_address = wtf.StringField( diff --git a/app/models/base.py b/app/models/base.py index e304c90..c4470e2 100644 --- a/app/models/base.py +++ b/app/models/base.py @@ -59,6 +59,11 @@ class Model(BaseModel): id = db.Column(db.Integer, primary_key=True) +class User: + user_created = db.Column(db.String(64)) + user_modified = db.Column(db.String(64)) + + class Tracked(object): """A mixin to include tracking datetime fields.""" created = db.Column(columns.Arrow, default=func.now()) -- GitLab From adb192ddfac997ed8ba43f0229670098624efe03 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Thu, 19 Oct 2017 17:02:08 -0400 Subject: [PATCH 13/17] Update bpvalve to v1.1.1 --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e760f52..87be95d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ arrow==0.7.0 blessed==1.9.5 botocore==1.3.28 -git+ssh://git@github.com/Blocp/bpvalve.git@v1.1.0 +git+ssh://git@github.com/Blocp/bpvalve.git@v1.1.1 cement==2.4.0 colorama==0.3.3 docker-py==1.1.0 -- GitLab From 5b0310b9a318e4603422637dc88567cff1269e65 Mon Sep 17 00:00:00 2001 From: Alessandro DiMarco Date: Mon, 23 Oct 2017 12:02:41 -0400 Subject: [PATCH 14/17] Add auth0 client id and secret env vars --- app/config/development.default.py | 2 ++ app/config/local.default.py | 2 ++ app/config/production.default.py | 2 ++ app/config/staging.default.py | 2 ++ 4 files changed, 8 insertions(+) diff --git a/app/config/development.default.py b/app/config/development.default.py index 9333a24..18a4f9e 100644 --- a/app/config/development.default.py +++ b/app/config/development.default.py @@ -28,6 +28,8 @@ AUTH0_AUTH_HEADER = 'x-blocpower-auth0-token' AUTH0_DOMAIN = os.environ['AUTH0_DOMAIN'] AUTH0_AUDIENCE = os.environ['AUTH0_AUDIENCE'] AUTH0_CLAIMS_NAMESPACE = os.environ['AUTH0_CLAIMS_NAMESPACE'] +AUTH0_CLIENT_ID = os.environ['AUTH0_CLIENT_ID'] +AUTH0_CLIENT_SECRET = os.environ['AUTH0_CLIENT_SECRET'] # Blocpower auth information. HEADER_AUTH_KEY = 'x-blocpower-auth-key' diff --git a/app/config/local.default.py b/app/config/local.default.py index d3e4d2b..41819cb 100644 --- a/app/config/local.default.py +++ b/app/config/local.default.py @@ -25,6 +25,8 @@ AUTH0_AUTH_HEADER = 'x-blocpower-auth0-token' AUTH0_DOMAIN = '$AUTH0_DOMAIN' AUTH0_AUDIENCE = '$AUTH0_AUDIENCE' AUTH0_CLAIMS_NAMESPACE = '$AUTH0_CLAIMS_NAMESPACE' +AUTH0_CLIENT_ID = '$AUTH0_CLIENT_ID' +AUTH0_CLIENT_SECRET = '$AUTH0_CLIENT_SECRET' # Blocpower auth information. HEADER_AUTH_KEY = 'x-blocpower-auth-key' diff --git a/app/config/production.default.py b/app/config/production.default.py index b382b44..74fbbb2 100644 --- a/app/config/production.default.py +++ b/app/config/production.default.py @@ -28,6 +28,8 @@ AUTH0_AUTH_HEADER = 'x-blocpower-auth0-token' AUTH0_DOMAIN = os.environ['AUTH0_DOMAIN'] AUTH0_AUDIENCE = os.environ['AUTH0_AUDIENCE'] AUTH0_CLAIMS_NAMESPACE = os.environ['AUTH0_CLAIMS_NAMESPACE'] +AUTH0_CLIENT_ID = os.environ['AUTH0_CLIENT_ID'] +AUTH0_CLIENT_SECRET = os.environ['AUTH0_CLIENT_SECRET'] # Blocpower auth information. HEADER_AUTH_KEY = 'x-blocpower-auth-key' diff --git a/app/config/staging.default.py b/app/config/staging.default.py index c8a4b81..1e82cec 100644 --- a/app/config/staging.default.py +++ b/app/config/staging.default.py @@ -28,6 +28,8 @@ AUTH0_AUTH_HEADER = 'x-blocpower-auth0-token' AUTH0_DOMAIN = os.environ['AUTH0_DOMAIN'] AUTH0_AUDIENCE = os.environ['AUTH0_AUDIENCE'] AUTH0_CLAIMS_NAMESPACE = os.environ['AUTH0_CLAIMS_NAMESPACE'] +AUTH0_CLIENT_ID = os.environ['AUTH0_CLIENT_ID'] +AUTH0_CLIENT_SECRET = os.environ['AUTH0_CLIENT_SECRET'] # Blocpower auth information. HEADER_AUTH_KEY = 'x-blocpower-auth-key' -- GitLab From 6cc53a997a785b2d4300106afb2009c00a5bf0ec Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Mon, 23 Oct 2017 13:40:49 -0400 Subject: [PATCH 15/17] Remove unused imports and use app need in application views. --- app/__init__.py | 4 ++-- app/permissions/auth.py | 2 -- app/views/application.py | 11 +++++++---- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/__init__.py b/app/__init__.py index dc103fa..cb425bf 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -27,8 +27,8 @@ def create_app(config): from . import views views.register(app) - from app.lib import database, red, exceptions, service, session, auth0 - services = (database, red, exceptions, service, session, auth0) + from app.lib import database, red, exceptions, auth0 + services = (database, red, exceptions, auth0) for service in services: service.register(app) diff --git a/app/permissions/auth.py b/app/permissions/auth.py index de95310..107a77f 100644 --- a/app/permissions/auth.py +++ b/app/permissions/auth.py @@ -5,8 +5,6 @@ from jose import jwt import json import requests -from ..lib.red import redis -from ..lib.service import services from .base import Permission from .application import app_need diff --git a/app/views/application.py b/app/views/application.py index 6ac7b3c..54f1adf 100644 --- a/app/views/application.py +++ b/app/views/application.py @@ -2,14 +2,15 @@ from werkzeug.exceptions import MethodNotAllowed from flask import request -from app.views.base import RestView +from bpvalve.flask.views import UnprotectedRestView from app.controllers.application import AuthenticationController, RoleController -from app.permissions.application import AppNeed +from app.permissions.application import AppNeed, app_need -class AuthenticationView(RestView): +class AuthenticationView(UnprotectedRestView): """A view for app authentications.""" route_base = '/auth/' + decorators = [app_need,] def get_controller(self): """Return an instance of the authentication controller.""" @@ -43,8 +44,10 @@ class AuthenticationView(RestView): raise MethodNotAllowed -class RoleView(RestView): +class RoleView(UnprotectedRestView): """A view for auth roles.""" + decorators = [app_need,] + def get_controller(self): """Return an instance of the role controller.""" return RoleController() -- GitLab From ff16d37126ed62e4f6556545946b0797d1ce47b8 Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Mon, 23 Oct 2017 13:43:15 -0400 Subject: [PATCH 16/17] Remove extra lines. --- app/config/development.default.py | 1 - app/config/staging.default.py | 1 - 2 files changed, 2 deletions(-) diff --git a/app/config/development.default.py b/app/config/development.default.py index 0ab1bd4..9f3058e 100644 --- a/app/config/development.default.py +++ b/app/config/development.default.py @@ -16,4 +16,3 @@ AUTH0_AUDIENCE = os.environ['AUTH0_AUDIENCE'] AUTH0_CLAIMS_NAMESPACE = os.environ['AUTH0_CLAIMS_NAMESPACE'] AUTH0_CLIENT_ID = os.environ['AUTH0_CLIENT_ID'] AUTH0_CLIENT_SECRET = os.environ['AUTH0_CLIENT_SECRET'] - diff --git a/app/config/staging.default.py b/app/config/staging.default.py index 0ab1bd4..9f3058e 100644 --- a/app/config/staging.default.py +++ b/app/config/staging.default.py @@ -16,4 +16,3 @@ AUTH0_AUDIENCE = os.environ['AUTH0_AUDIENCE'] AUTH0_CLAIMS_NAMESPACE = os.environ['AUTH0_CLAIMS_NAMESPACE'] AUTH0_CLIENT_ID = os.environ['AUTH0_CLIENT_ID'] AUTH0_CLIENT_SECRET = os.environ['AUTH0_CLIENT_SECRET'] - -- GitLab From 8bc492770970a2a5d6c8af7c670e21365547b62d Mon Sep 17 00:00:00 2001 From: Jose Contreras Date: Mon, 23 Oct 2017 15:53:15 -0400 Subject: [PATCH 17/17] Add new line --- app/config/local.default.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app/config/local.default.py b/app/config/local.default.py index 1d9d0ab..3e7aea6 100644 --- a/app/config/local.default.py +++ b/app/config/local.default.py @@ -5,6 +5,7 @@ SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_DATABASE_URI = os.environ['SQLALCHEMY_DATABASE_URI'] DEBUG = True + # Auth0 Authentication AUTH0_AUTH_HEADER = 'x-blocpower-auth0-token' AUTH0_DOMAIN = '$AUTH0_DOMAIN' -- GitLab