def handle(self, cid, extra): """ Dispatch a request from /containers/x/... to its proper destination. For example: /containers/x/files --> x is a project ID --> /projects/x/files """ results = container_search({'_id': cid}, projection={'_id': 1}) if not results: raise APINotFoundException('No container {} found'.format(cid)) # Create new request instance using destination URI (eg. replace containers with cont_name) cont_name, _ = results[0] destination_environ = self.request.environ for key in 'PATH_INFO', 'REQUEST_URI': if key in destination_environ: destination_environ[key] = destination_environ[key].replace('containers', cont_name, 1) destination_environ['fw_container_type'] = singularize(cont_name) destination_request = Request(destination_environ) # Apply SciTranRequest attrs destination_request.id = self.request.id destination_request.logger = self.request.logger # Dispatch the destination request self.app.router.dispatch(destination_request, self.response)
def lookup(self): """Locate a node by path, and re-route to the endpoint for that node""" result = self._resolve_and_check_permissions(True) # If we resolved a file, we can just return that file node path = result.get('path', []) if not path: raise APINotFoundException('No node matched that path') # In the event that we resolved a file, just return the file node dest = path[-1] if dest.get('container_type') == 'file': return dest # Reroute to the actual path that will log access, resolve analyses, etc path = self._get_node_path(dest) # Create new request instance using destination URI (eg. replace containers with cont_name) destination_environ = self.request.environ for key in 'PATH_INFO', 'REQUEST_URI': if key in destination_environ: destination_environ[key] = destination_environ[key].replace('lookup', path, 1) # We also must update the method, and indicate that we want the container_type included # The client will depend on container_type being set so that it can map to the correct type destination_environ['REQUEST_METHOD'] = 'GET' destination_environ['fw_container_type'] = dest['container_type'] destination_request = Request(destination_environ) # Apply SciTranRequest attrs destination_request.id = self.request.id destination_request.logger = self.request.logger # Dispatch the destination request self.app.router.dispatch(destination_request, self.response)