#NEWLINE# def authenticate( self ) : #NEWLINE# #INDENT# "Authenticate with the Keystone service.\n\n        There are a few scenarios to consider here:\n\n        1. Which version of Keystone are we using? v1 which uses headers to\n           pass the credentials, or v2 which uses a JSON encoded request body?\n\n        2. Keystone may respond back with a redirection using a 305 status\n           code.\n\n        3. We may attempt a v1 auth when v2 is what's called for. In this\n           case, we rewrite the url to contain /v2.0/ and retry using the v2\n           protocol.\n        " #NEWLINE# def _authenticate( auth_url ) : #NEWLINE# #INDENT# if ( not auth_url . endswith ( '/' ) ) : #NEWLINE# #INDENT# auth_url += '/' #NEWLINE# #UNINDENT# token_url = urlparse . urljoin ( auth_url , 'tokens' ) #NEWLINE# is_v2 = auth_url . rstrip ( '/' ) . endswith ( 'v2.0' ) #NEWLINE# if is_v2 : #NEWLINE# #INDENT# self . _v2_auth ( token_url ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _v1_auth ( token_url ) #NEWLINE# #UNINDENT# #UNINDENT# self . check_auth_params ( ) #NEWLINE# auth_url = self . creds [ 'auth_url' ] #NEWLINE# for x in range ( self . MAX_REDIRECTS ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# _authenticate ( auth_url ) #NEWLINE# #UNINDENT# except exception . AuthorizationRedirect as e : #NEWLINE# #INDENT# auth_url = e . url #NEWLINE# #UNINDENT# except exception . AuthorizationFailure : #NEWLINE# #INDENT# if ( 'v2.0' not in auth_url ) : #NEWLINE# #INDENT# auth_url = urlparse . urljoin ( auth_url , 'v2.0/' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# self . creds [ 'auth_url' ] = x #NEWLINE# break #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# raise exception . MaxRedirectsExceeded ( redirects = self . MAX_REDIRECTS )