Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyjb committed May 8, 2018
0 parents commit f1b60ec
Show file tree
Hide file tree
Showing 42 changed files with 3,870 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .gitignore
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
3 changes: 3 additions & 0 deletions README.md
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.
69 changes: 69 additions & 0 deletions api/__init__.py
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
Loading

0 comments on commit f1b60ec

Please sign in to comment.