<s> import base64 <EOL> from twisted . conch . checkers import SSHPublicKeyDatabase <EOL> from twisted . internet import reactor , defer <EOL> from twisted . python import log <EOL> from twisted . web . client import Agent <EOL> from twisted . web . http_headers import Headers <EOL> from twisted . conch . ssh . keys import Key <EOL> from . extractors import UserExtractor <EOL> class OpenRukoCredentialChecker ( SSHPublicKeyDatabase ) : <EOL> agent = Agent ( reactor ) <EOL> def __init__ ( self , settings ) : <EOL> self . settings = settings <EOL> def checkKey ( self , credentials ) : <EOL> if not credentials . signature : <EOL> return True <EOL> cmp_key = Key . fromString ( <EOL> credentials . blob ) . fingerprint ( ) . replace ( '<STR_LIT::>' , '<STR_LIT>' ) <EOL> apiserver_base_url = '<STR_LIT>' % ( <EOL> self . settings [ '<STR_LIT>' ] , <EOL> self . settings [ '<STR_LIT>' ] , <EOL> self . settings [ '<STR_LIT>' ] <EOL> ) <EOL> lookup_url = '<STR_LIT>' % ( <EOL> apiserver_base_url , cmp_key ) <EOL> log . msg ( "<STR_LIT>" + lookup_url ) <EOL> d = defer . Deferred ( ) <EOL> def cbResponse ( resp ) : <EOL> if resp . code == <NUM_LIT:200> : <EOL> resp . deliverBody ( UserExtractor ( d , cmp_key , credentials ) ) <EOL> else : <EOL> log . err ( '<STR_LIT>' + cmp_key ) <EOL> d . errback ( False ) <EOL> def cbErrResponse ( failure ) : <EOL> log . err ( '<STR_LIT>' ) <EOL> d . errback ( False ) <EOL> auth_key = base64 . b64encode ( '<STR_LIT>' % self . settings [ '<STR_LIT>' ] ) <EOL> headers = Headers ( { '<STR_LIT>' : [ '<STR_LIT>' % auth_key ] } ) <EOL> req = self . agent . request ( '<STR_LIT:GET>' , lookup_url , headers = headers ) <EOL> req . addCallback ( cbResponse ) <EOL> req . addErrback ( cbErrResponse ) <EOL> return d </s>
