refactor jwt context building

This commit is contained in:
Evan Cordell 2017-03-27 10:55:18 -04:00
parent 4c94d2c760
commit 1016641f8d

View file

@ -110,35 +110,35 @@ def build_context_and_subject(user=None, token=None, oauthtoken=None, tuf_root=N
if not tuf_root: if not tuf_root:
tuf_root = QUAY_TUF_ROOT tuf_root = QUAY_TUF_ROOT
context = {
CLAIM_TUF_ROOT: tuf_root
}
if oauthtoken: if oauthtoken:
context = { context.update({
'kind': 'oauth', 'kind': 'oauth',
'user': user.username, 'user': user.username,
'oauth': oauthtoken.uuid, 'oauth': oauthtoken.uuid,
CLAIM_TUF_ROOT: tuf_root, })
}
return (context, user.username) return (context, user.username)
if user: if user:
context = { context.update({
'kind': 'user', 'kind': 'user',
'user': user.username, 'user': user.username,
CLAIM_TUF_ROOT: tuf_root, })
}
return (context, user.username) return (context, user.username)
if token: if token:
context = { context.update({
'kind': 'token', 'kind': 'token',
'token': token.code, 'token': token.code,
CLAIM_TUF_ROOT: tuf_root, })
}
return (context, None) return (context, None)
context = { context.update({
'kind': 'anonymous', 'kind': 'anonymous',
CLAIM_TUF_ROOT: tuf_root, })
}
return (context, ANONYMOUS_SUB) return (context, ANONYMOUS_SUB)