We can't count on auth tokens being sent anymore, so we set the namespace and repository for the session when the original put on the repo is made.

This commit is contained in:
root 2013-12-09 04:24:29 +00:00
parent 8917812efa
commit 61618c7eab
2 changed files with 8 additions and 6 deletions

View file

@ -1,7 +1,7 @@
import logging
from functools import wraps
from flask import request, make_response, _request_ctx_stack, abort, session
from flask import request, _request_ctx_stack, abort, session
from flask.ext.principal import identity_changed, Identity
from base64 import b64decode
@ -106,9 +106,6 @@ def process_token(auth):
token_vals['signature'])
abort(401)
session['repository'] = token_data.repository.name
session['namespace'] = token_data.repository.namespace
logger.debug('Successfully validated token: %s' % token_data.code)
ctx = _request_ctx_stack.top
ctx.validated_token = token_data
@ -136,7 +133,8 @@ def extract_namespace_repo_from_session(f):
@wraps(f)
def wrapper(*args, **kwargs):
if 'namespace' not in session or 'repository' not in session:
logger.debug('Unable to load namespace or repository from session.')
logger.error('Unable to load namespace or repository from session: %s' %
session)
abort(400)
return f(session['namespace'], session['repository'], *args, **kwargs)

View file

@ -2,7 +2,7 @@ import json
import logging
import urlparse
from flask import request, make_response, jsonify, abort
from flask import request, make_response, jsonify, abort, session
from functools import wraps
from data import model
@ -25,6 +25,10 @@ def generate_headers(role='read'):
def wrapper(namespace, repository, *args, **kwargs):
response = f(namespace, repository, *args, **kwargs)
# Setting session namespace and repository
session['namespace'] = namespace
session['repository'] = repository
# We run our index and registry on the same hosts for now
registry_server = urlparse.urlparse(request.url).netloc
response.headers['X-Docker-Endpoints'] = registry_server