1 from sfa.trust.certificate import Keypair, convert_public_key
2 from sfa.trust.gid import *
4 from sfa.util.faults import *
5 from sfa.util.xrn import get_authority
6 from sfa.util.method import Method
7 from sfa.util.parameter import Parameter, Mixed
8 from sfa.util.record import SfaRecord
9 from sfa.util.table import SfaTable
10 from sfa.trust.auth import Auth
11 from sfa.trust.gid import create_uuid
12 from sfa.trust.credential import Credential
14 class RegisterPeerObject(Method):
16 Register a peer object with the registry. In addition to being stored in the
17 SFA database, the appropriate records will also be created in the
20 @param cred credential string
21 @param record_dict dictionary containing record fields
22 @return gid string representation
25 interfaces = ['registry']
28 Parameter(str, "Credential string"),
29 Parameter(dict, "Record dictionary containing record fields"),
30 Mixed(Parameter(str, "Human readable name of the original caller"),
31 Parameter(None, "Origin hrn not specified"))
34 returns = Parameter(int, "1 if successful")
36 def call(self, cred, record_dict, origin_hrn=None):
37 user_cred = Credential(string=cred)
41 origin_hrn = user_cred.get_gid_caller().get_hrn()
42 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, None, self.name))
45 self.api.auth.check(cred, "register")
47 # make sure this is a peer record
48 if 'peer_authority' not in record_dict or \
49 not record_dict['peer_authority']:
50 raise SfaInvalidArgument, "peer_authority must be specified"
52 record = SfaRecord(dict = record_dict)
53 type, hrn, peer_authority = record['type'], record['hrn'], record['peer_authority']
54 record['authority'] = get_authority(record['hrn'])
56 self.api.auth.verify_cred_is_me(cred)
58 # check if record already exists
60 existing_records = table.find({'type': type, 'hrn': hrn, 'peer_authority': peer_authority})
62 for existing_record in existing_records:
63 if existing_record['pointer'] != record['pointer']:
64 record['record_id'] = existing_record['record_id']
67 record_id = table.insert(record)