<s> import logging <EOL> import time <EOL> from jumpgate . common import exceptions <EOL> from jumpgate . common import utils <EOL> from jumpgate . identity . drivers import core as identity <EOL> from oslo . config import cfg <EOL> import SoftLayer <EOL> USER_MASK = '<STR_LIT>' <EOL> LOG = logging . getLogger ( __name__ ) <EOL> def get_token_details ( token , tenant_id = None ) : <EOL> try : <EOL> token_id_driver = identity . token_id_driver ( ) <EOL> token_details = token_id_driver . token_from_id ( token ) <EOL> except ( TypeError , ValueError ) : <EOL> raise exceptions . Unauthorized ( '<STR_LIT>' ) <EOL> if time . time ( ) > token_details [ '<STR_LIT>' ] : <EOL> raise exceptions . Unauthorized ( '<STR_LIT>' ) <EOL> if tenant_id and str ( token_details [ '<STR_LIT>' ] ) != tenant_id : <EOL> raise exceptions . Unauthorized ( '<STR_LIT>' ) <EOL> return token_details <EOL> def get_new_token_v3 ( credentials ) : <EOL> token_driver = identity . token_driver ( ) <EOL> token_id = utils . lookup ( credentials , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:id>' ) <EOL> if token_id : <EOL> token = identity . token_id_driver ( ) . token_from_id ( token_id ) <EOL> LOG . debug ( "<STR_LIT>" , str ( token ) ) <EOL> token_driver . validate_token ( token ) <EOL> username = token_driver . username ( token ) <EOL> credential = token_driver . credential ( token ) <EOL> userinfo = { '<STR_LIT:username>' : username , <EOL> '<STR_LIT>' : str ( token [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : str ( token [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : token [ '<STR_LIT>' ] } <EOL> if token [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> userinfo [ '<STR_LIT>' ] = credential <EOL> if token [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> userinfo [ '<STR_LIT>' ] = credential <EOL> user = { '<STR_LIT:id>' : token [ '<STR_LIT>' ] , <EOL> '<STR_LIT:username>' : username , <EOL> '<STR_LIT>' : token [ '<STR_LIT>' ] } <EOL> return userinfo , user <EOL> username = utils . lookup ( credentials , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:password>' , <EOL> '<STR_LIT:user>' , <EOL> '<STR_LIT:name>' ) <EOL> credential = utils . lookup ( credentials , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:password>' , <EOL> '<STR_LIT:user>' , <EOL> '<STR_LIT:password>' ) <EOL> if len ( credential ) == <NUM_LIT:64> : <EOL> endpoint = cfg . CONF [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> client = SoftLayer . Client ( username = username , <EOL> api_key = credential , <EOL> endpoint_url = endpoint , <EOL> proxy = cfg . CONF [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> user = client [ '<STR_LIT>' ] . getCurrentUser ( mask = USER_MASK ) <EOL> username = token_driver . username ( user ) <EOL> return { '<STR_LIT:username>' : username , <EOL> '<STR_LIT>' : credential , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( user [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : time . time ( ) + ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) } , user <EOL> else : <EOL> endpoint = cfg . CONF [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> client = SoftLayer . Client ( endpoint_url = endpoint , <EOL> proxy = cfg . CONF [ '<STR_LIT>' ] [ '<STR_LIT>' ] ) <EOL> client . auth = None <EOL> try : <EOL> userId , tokenHash = client . authenticate_with_password ( username , <EOL> credential ) <EOL> user = client [ '<STR_LIT>' ] . getCurrentUser ( mask = USER_MASK ) <EOL> username = token_driver . username ( user ) <EOL> return { '<STR_LIT>' : userId , <EOL> '<STR_LIT:username>' : username , <EOL> '<STR_LIT>' : tokenHash , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : str ( user [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : time . time ( ) + ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> ) } , user <EOL> except SoftLayer . SoftLayerAPIError as e : <EOL> if e . faultCode == '<STR_LIT>' : <EOL> raise exceptions . Unauthorized ( e . faultString ) <EOL> raise <EOL> def get_auth ( token_details ) : <EOL> if token_details [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> return SoftLayer . BasicAuthentication ( token_details [ '<STR_LIT:username>' ] , <EOL> token_details [ '<STR_LIT>' ] ) <EOL> elif token_details [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> return SoftLayer . TokenAuthentication ( token_details [ '<STR_LIT>' ] , <EOL> token_details [ '<STR_LIT>' ] ) <EOL> return None </s>
