-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from MatchmakerExchange/exchange_server
Authentication support and refactoring
- Loading branch information
Showing
22 changed files
with
849 additions
and
337 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,44 @@ | ||
# After changing this file, check it on: | ||
# http://lint.travis-ci.org/ | ||
language: python | ||
|
||
python: | ||
- "2.7" | ||
- "3.3" | ||
- "3.4" | ||
- "3.5" | ||
|
||
sudo: false | ||
|
||
cache: | ||
apt: true | ||
|
||
addons: | ||
apt: | ||
sources: | ||
- elasticsearch-2.x | ||
packages: | ||
- elasticsearch | ||
|
||
services: | ||
- elasticsearch | ||
|
||
install: | ||
- pip install -e . | ||
- mme-server quickstart | ||
|
||
script: | ||
# Test via module runner | ||
- python -m mme_server test | ||
# Test via setup.py (with environment variable to also test quickstart) | ||
- MME_TEST_QUICKSTART=1 coverage run --source=mme_server setup.py test | ||
services: | ||
- elasticsearch | ||
|
||
before_script: | ||
# Delay for elasticsearch to start | ||
- sleep 10 | ||
|
||
before_install: | ||
- pip install coveralls | ||
|
||
after_success: | ||
- coveralls | ||
- coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from .cli import main | ||
from .server import app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
""" | ||
Module hanlding the authentication of incoming and outgoing server requests. | ||
Stores: | ||
* Authenticated servers (`servers` index) | ||
""" | ||
from __future__ import with_statement, division, unicode_literals | ||
|
||
import logging | ||
import flask | ||
|
||
from functools import wraps | ||
|
||
from flask import request, jsonify | ||
|
||
from .backend import get_backend | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def auth_token_required(): | ||
def decorator(f): | ||
@wraps(f) | ||
def decorated_function(*args, **kwargs): | ||
logger.info("Authenticating request") | ||
token = request.headers.get('X-Auth-Token') | ||
backend = get_backend() | ||
servers = backend.get_manager('servers') | ||
server = servers.verify(token) | ||
if not server: | ||
error = jsonify(message='X-Auth-Token not authorized') | ||
error.status_code = 401 | ||
return error | ||
|
||
# Set authenticated server as flask global for request | ||
flask.g.server = server | ||
return f(*args, **kwargs) | ||
return decorated_function | ||
return decorator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
""" | ||
Module for accessing the backend connection | ||
""" | ||
|
||
from __future__ import with_statement, division, unicode_literals | ||
|
||
import logging | ||
import flask | ||
|
||
from elasticsearch import Elasticsearch | ||
|
||
from .managers import Managers | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
|
||
def get_backend(): | ||
backend = getattr(flask.g, '_mme_backend', None) | ||
if backend is None: | ||
backend = flask.g._mme_backend = Managers(Elasticsearch()) | ||
|
||
return backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.