-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f1b60ec
Showing
42 changed files
with
3,870 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
.bash_history | ||
.bash_logout | ||
.bash_profile | ||
.bashrc | ||
.cache | ||
.emacs | ||
.sass-cache | ||
.ssh/ | ||
__pycache__ | ||
settings/local.py | ||
assets | ||
celerybeat-schedule.bak | ||
celerybeat-schedule.dat | ||
celerybeat-schedule.dir | ||
celerybeat.pid | ||
tests/data/assets | ||
*.pyc | ||
/bin | ||
/lib | ||
/lib64 | ||
/logs | ||
/man | ||
/share | ||
pip-selfcheck.json | ||
pyvenv.cfg | ||
nohup.out | ||
npm-debug.log | ||
celerybeat-schedule | ||
*~ | ||
s3.cfg | ||
tests/data/s3.cfg | ||
backend_configs |
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,3 @@ | ||
# Hangar51 | ||
|
||
Hangar51 is an asset (image and file) storage and retrieval application. |
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,69 @@ | ||
from flask import Blueprint, g, jsonify, request | ||
from functools import wraps | ||
from mongoframes import * | ||
|
||
from models.accounts import Account | ||
|
||
api = Blueprint('api', __name__) | ||
|
||
__all__ = [ | ||
# Blueprint | ||
'api', | ||
|
||
# Decorators | ||
'authenticated', | ||
|
||
# Responses | ||
'fail', | ||
'success' | ||
] | ||
|
||
|
||
# Decorators | ||
|
||
def authenticated(func): | ||
""" | ||
Wrap this decorator around any view that requires a valid account key. | ||
""" | ||
|
||
# Wrap the function with the decorator | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
|
||
api_key = request.values.get('api_key') | ||
if not api_key: | ||
return fail('`api_key` not specified.') | ||
|
||
# Find the account | ||
account = Account.one(Q.api_key == api_key.strip()) | ||
if not account: | ||
return fail('Not a valid `api_key`.') | ||
|
||
# Set the account against the global context | ||
g.account = account | ||
|
||
return func(*args, **kwargs) | ||
|
||
return wrapper | ||
|
||
|
||
# Responses | ||
|
||
def fail(reason, issues=None): | ||
"""Return a fail response""" | ||
response = {'status': 'fail', 'payload': {'reason': reason}} | ||
if issues: | ||
response['payload']['issues'] = issues | ||
return jsonify(response) | ||
|
||
def success(payload=None): | ||
"""Return a success response""" | ||
response = {'status': 'success'} | ||
if payload: | ||
response['payload'] = payload | ||
return jsonify(response) | ||
|
||
|
||
# Place imports here to prevent cross import clashes | ||
|
||
from api import assets |
Oops, something went wrong.