Merge pull request #1153 from coreos-inc/fixtutorial

Fix tutorial by properly publishing user events for V2 API
This commit is contained in:
josephschorr 2016-01-22 12:51:47 -05:00
commit d00db518df

View file

@ -6,7 +6,7 @@ import jwt
from flask import request, jsonify, abort from flask import request, jsonify, abort
from cachetools import lru_cache from cachetools import lru_cache
from app import app from app import app, userevents
from data import model from data import model
from auth.auth import process_auth from auth.auth import process_auth
from auth.registry_jwt_auth import build_context_and_subject from auth.registry_jwt_auth import build_context_and_subject
@ -62,6 +62,9 @@ def generate_registry_jwt():
logger.debug('Authenticated OAuth token: %s', oauthtoken) logger.debug('Authenticated OAuth token: %s', oauthtoken)
access = [] access = []
user_event_data = {
'action': 'login',
}
if len(scope_param) > 0: if len(scope_param) > 0:
match = SCOPE_REGEX.match(scope_param) match = SCOPE_REGEX.match(scope_param)
@ -121,18 +124,36 @@ def generate_registry_jwt():
logger.debug('No permission to pull repository %v/%v', namespace, reponame) logger.debug('No permission to pull repository %v/%v', namespace, reponame)
abort(403) abort(403)
# Add the access for the JWT.
access.append({ access.append({
'type': 'repository', 'type': 'repository',
'name': namespace_and_repo, 'name': namespace_and_repo,
'actions': final_actions, 'actions': final_actions,
}) })
# Set the user event data for the auth.
if 'push' in final_actions:
user_action = 'push_start'
elif 'pull' in final_actions:
user_action = 'pull_start'
user_event_data = {
'action': user_action,
'repository': reponame,
'namespace': namespace,
}
elif user is None and token is None: elif user is None and token is None:
# In this case, we are doing an auth flow, and it's not an anonymous pull # In this case, we are doing an auth flow, and it's not an anonymous pull
logger.debug('No user and no token sent for empty scope list') logger.debug('No user and no token sent for empty scope list')
abort(401) abort(401)
# Send the user event.
if user is not None:
event = userevents.get_event(user.username)
event.publish_event_data('docker-cli', user_event_data)
# Build the signed JWT.
context, subject = build_context_and_subject(user, token, oauthtoken) context, subject = build_context_and_subject(user, token, oauthtoken)
token_data = { token_data = {
'iss': app.config['JWT_AUTH_TOKEN_ISSUER'], 'iss': app.config['JWT_AUTH_TOKEN_ISSUER'],