Move the auth context methods into their own file so that we don't have auth trying to import itself

This commit is contained in:
Joseph Schorr 2014-02-25 15:07:24 -05:00
parent a120f6c64a
commit 61ca29de04
5 changed files with 12 additions and 14 deletions

View file

@ -1,7 +1,7 @@
import logging
from functools import wraps
from flask import request, _request_ctx_stack, abort as flask_abort, session
from flask import request, _request_ctx_stack, session
from flask.ext.principal import identity_changed, Identity
from base64 import b64decode
@ -15,15 +15,6 @@ from util.http import abort
logger = logging.getLogger(__name__)
def get_authenticated_user():
return getattr(_request_ctx_stack.top, 'authenticated_user', None)
def get_validated_token():
return getattr(_request_ctx_stack.top, 'validated_token', None)
def process_basic_auth(auth):
normalized = [part.strip() for part in auth.split(' ') if part]
if normalized[0].lower() != 'basic' or len(normalized) != 2:

7
auth/auth_context.py Normal file
View file

@ -0,0 +1,7 @@
from flask import _request_ctx_stack
def get_authenticated_user():
return getattr(_request_ctx_stack.top, 'authenticated_user', None)
def get_validated_token():
return getattr(_request_ctx_stack.top, 'validated_token', None)

View file

@ -9,8 +9,8 @@ from collections import OrderedDict
from data import model, userevent
from data.queue import webhook_queue
from app import mixpanel, app
from auth.auth import (process_auth, get_authenticated_user,
get_validated_token)
from auth.auth import process_auth
from auth.auth_context import get_authenticated_user, get_validated_token
from util.names import parse_repository_name
from util.email import send_confirmation_email
from auth.permissions import (ModifyRepositoryPermission, UserPermission,

View file

@ -2,7 +2,7 @@ import logging
import json
from flask import (make_response, request, session, Response, redirect,
Blueprint, abort as flask_abort)
Blueprint)
from functools import wraps
from datetime import datetime
from time import time

View file

@ -2,6 +2,7 @@ import logging
from app import mixpanel
from flask import request, abort as flask_abort, jsonify
from auth.auth_context import get_authenticated_user, get_validated_token
logger = logging.getLogger(__name__)
@ -15,7 +16,6 @@ DEFAULT_MESSAGE[409] = 'Conflict'
DEFAULT_MESSAGE[501] = 'Not Implemented'
def abort(status_code, message=None, issue=None, **kwargs):
from auth.auth import get_authenticated_user, get_validated_token
message = (str(message) % kwargs if message else
DEFAULT_MESSAGE.get(status_code, ''))