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