1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/fc7de175ea2f/ Changeset: fc7de175ea2f User: dannon Date: 2014-05-08 17:33:55 Summary: Added the ability for /api/authenticate/baseauth to create an API key for a user if one is not set. Misc cleanup, using mappings instead of raw queries. Affected #: 1 file diff -r d6826c29e15a1f17553ae2fe2b149ef65ac4da9d -r fc7de175ea2f59b0389a74f30e1152ff4563ad0e lib/galaxy/webapps/galaxy/api/authenticate.py --- a/lib/galaxy/webapps/galaxy/api/authenticate.py +++ b/lib/galaxy/webapps/galaxy/api/authenticate.py @@ -2,18 +2,19 @@ API key retrieval through BaseAuth """ -from galaxy import util, web -from pprint import pprint -from galaxy.web.base.controller import BaseAPIController -from base64 import b64decode, b64encode -from urllib import quote, unquote +from base64 import b64decode +from paste.httpexceptions import HTTPBadRequest +from urllib import unquote + +from galaxy import web from galaxy.exceptions import ObjectNotFound -from paste.httpexceptions import HTTPBadRequest +from galaxy.web.base.controller import BaseAPIController, CreatesApiKeysMixin import logging log = logging.getLogger( __name__ ) -class AuthenticationController( BaseAPIController ): + +class AuthenticationController( BaseAPIController, CreatesApiKeysMixin ): @web.expose_api_anonymous def get_api_key( self, trans, **kwd ): @@ -37,15 +38,15 @@ else: user = user[0] is_valid_user = user.check_password( password ) - if ( is_valid_user ): - user_id = user.id - api_key_row = trans.sa_session.query( trans.app.model.APIKeys ).filter( trans.app.model.APIKeys.table.c.user_id == user_id ).first() + if user.api_keys: + key = user.api_keys[0].key + else: + key = self.create_api_key( trans, user ) + return dict( api_key=key ) else: trans.response.status = 500 - return "invalid password" - - return dict( api_key= api_key_row.key ) + return "invalid password" def _decode_baseauth( self, encoded_str ): """ Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.