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