<s> from openflow . optin_manager . sfa . util . faults import RecordNotFound , ConnectionKeyGIDMismatch <EOL> from openflow . optin_manager . sfa . util . xrn import urn_to_hrn <EOL> from openflow . optin_manager . sfa . util . method import Method <EOL> from openflow . optin_manager . sfa . trust . certificate import Certificate <EOL> from openflow . optin_manager . sfa . util . parameter import Parameter , Mixed <EOL> class GetSelfCredential ( Method ) : <EOL> """<STR_LIT>""" <EOL> interfaces = [ '<STR_LIT>' ] <EOL> accepts = [ <EOL> Parameter ( str , "<STR_LIT>" ) , <EOL> Parameter ( str , "<STR_LIT>" ) , <EOL> Mixed ( Parameter ( str , "<STR_LIT>" ) , <EOL> Parameter ( None , "<STR_LIT>" ) ) , <EOL> ] <EOL> returns = Parameter ( str , "<STR_LIT>" ) <EOL> def call ( self , cert , xrn , type ) : <EOL> """<STR_LIT>""" <EOL> if type : <EOL> hrn = urn_to_hrn ( xrn ) [ <NUM_LIT:0> ] <EOL> else : <EOL> hrn , type = urn_to_hrn ( xrn ) <EOL> self . api . auth . verify_object_belongs_to_me ( hrn ) <EOL> origin_hrn = Certificate ( string = cert ) . get_subject ( ) <EOL> self . api . logger . info ( "<STR_LIT>" % ( self . api . interface , origin_hrn , hrn , self . name ) ) <EOL> from openflow . optin_manager . sfa . storage . model import RegRecord <EOL> records = self . api . manager . Resolve ( self . api , xrn , type , details = False ) <EOL> if not records : <EOL> raise RecordNotFound ( hrn ) <EOL> record_obj = RegRecord ( dict = records [ <NUM_LIT:0> ] ) <EOL> gid = record_obj . get_gid_object ( ) <EOL> gid_str = gid . save_to_string ( save_parents = True ) <EOL> self . api . auth . authenticateGid ( gid_str , [ cert , type , hrn ] ) <EOL> certificate = Certificate ( string = cert ) <EOL> if not certificate . is_pubkey ( gid . get_pubkey ( ) ) : <EOL> for ( obj , name ) in [ ( certificate , "<STR_LIT>" ) , ( gid , "<STR_LIT>" ) , ] : <EOL> self . api . logger . debug ( "<STR_LIT>" % ( name , obj . get_pubkey ( ) . get_pubkey_string ( ) ) ) <EOL> self . api . logger . debug ( "<STR_LIT>" % ( name , obj . dump_string ( ) ) ) <EOL> if hasattr ( obj , '<STR_LIT:filename>' ) : <EOL> self . api . logger . debug ( "<STR_LIT>" % ( name , obj . filename ) ) <EOL> raise ConnectionKeyGIDMismatch ( gid . get_subject ( ) ) <EOL> return self . api . manager . GetCredential ( self . api , xrn , type ) </s>
