async def get(self, kernel_name): ksm = self.kernel_spec_cache kernel_name = url_unescape(kernel_name) kernel_user_filter = self.request.query_arguments.get('user') kernel_user = None if kernel_user_filter: kernel_user = kernel_user_filter[0].decode("utf-8") try: spec = await maybe_future(ksm.get_kernel_spec(kernel_name)) except KeyError: raise web.HTTPError(404, u'Kernel spec %s not found' % kernel_name) if is_kernelspec_model(spec): model = spec else: model = kernelspec_model(self, kernel_name, spec.to_dict(), spec.resource_dir) d = apply_user_filter(model, self.settings['eg_authorized_users'], self.settings['eg_unauthorized_users'], kernel_user) if d is None: raise web.HTTPError( 403, u'User %s is not authorized to use kernel spec %s' % (kernel_user, kernel_name)) self.set_header("Content-Type", 'application/json') self.finish(json.dumps(model))
async def get(self): ksm = self.kernel_spec_cache km = self.kernel_manager model = {} model['default'] = km.default_kernel_name model['kernelspecs'] = specs = {} kernel_user_filter = self.request.query_arguments.get('user') kernel_user = None if kernel_user_filter: kernel_user = kernel_user_filter[0].decode("utf-8") if kernel_user: self.log.debug("Searching kernels for user '%s' " % kernel_user) kspecs = await maybe_future(ksm.get_all_specs()) list_kernels_found = [] for kernel_name, kernel_info in kspecs.items(): try: if is_kernelspec_model(kernel_info): d = kernel_info else: d = kernelspec_model(self, kernel_name, kernel_info['spec'], kernel_info['resource_dir']) d = apply_user_filter(d, self.settings['eg_authorized_users'], self.settings['eg_unauthorized_users'], kernel_user) if d is not None: specs[kernel_name] = d list_kernels_found.append(d['name']) else: self.log.debug( 'User %s is not authorized to use kernel spec %s' % (kernel_user, kernel_name)) except Exception: self.log.error("Failed to load kernel spec: '%s'", kernel_name) continue self.set_header("Content-Type", 'application/json') self.finish(json.dumps(model))