handlers.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #
  2. # Copyright 2018-2022 Elyra Authors
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. import os
  17. from jupyter_server.base.handlers import APIHandler
  18. from tornado import web
  19. class BaseSpecHandler(web.StaticFileHandler, APIHandler):
  20. @staticmethod
  21. def get_resource_metadata():
  22. """Returns the (resource, mime-type) for the handlers spec."""
  23. pass
  24. def initialize(self):
  25. web.StaticFileHandler.initialize(self, path=os.path.dirname(__file__))
  26. @web.authenticated
  27. def get(self):
  28. return web.StaticFileHandler.get(self, self.get_resource_metadata()[0])
  29. def get_content_type(self):
  30. return self.get_resource_metadata()[1]
  31. class YamlSpecHandler(BaseSpecHandler):
  32. """Exposes the ability to return specifications from static files"""
  33. @staticmethod
  34. def get_resource_metadata():
  35. """Returns the (resource, mime-type) for the handlers spec."""
  36. return "elyra.yaml", "text/x-yaml"