- def call(self, cred, record_dict, caller_cred=None):
- self.api.auth.check(cred, "register")
- if caller_cred==None:
- caller_cred=cred
-
- #log the call
- self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, Credential(string=caller_cred).get_gid_caller().get_hrn(), None, self.name))
- record = GeniRecord(dict = record_dict)
- record['authority'] = get_authority(record['hrn'])
- type = record['type']
- hrn = record['hrn']
- self.api.auth.verify_object_permission(hrn)
- auth_info = self.api.auth.get_auth_info(record['authority'])
- pub_key = None
- # make sure record has a gid
- if 'gid' not in record:
- uuid = create_uuid()
- pkey = Keypair(create=True)
- if 'key' in record and record['key']:
- if isinstance(record['key'], list):
- pub_key = record['key'][0]
- else:
- pub_key = record['key']
- pkey = convert_public_key(pub_key)
-
- gid_object = self.api.auth.hierarchy.create_gid(hrn, uuid, pkey)
- gid = gid_object.save_to_string(save_parents=True)
- record['gid'] = gid
- record.set_gid(gid)
-
- # check if record already exists
- table = GeniTable()
- existing_records = table.find({'type': type, 'hrn': hrn})
- if existing_records:
- raise ExistingRecord(hrn)
- else:
- # We will update the pointer later
- record['pointer'] = -1
- record.set_pointer(-1)
- record_id = table.insert(record)
- record['record_id'] = record_id
-
- if type in ["authority"]:
- # update the tree
- if not self.api.auth.hierarchy.auth_exists(hrn):
- self.api.auth.hierarchy.create_auth(hrn)
-
- # authorities are special since they are managed by the registry
- # rather than by the caller. We create our own GID for the
- # authority rather than relying on the caller to supply one.
-
- # get the GID from the newly created authority
- gid = auth_info.get_gid_object()
- record.set_gid(gid.save_to_string(save_parents=True))
-
- pl_record = self.api.geni_fields_to_pl_fields(type, hrn, record)
- sites = self.api.plshell.GetSites(self.api.plauth, [pl_record['login_base']])
- if not sites:
- pointer = self.api.plshell.AddSite(self.api.plauth, pl_record)
- else:
- pointer = sites[0]['site_id']
-
- record.set_pointer(pointer)