from .. import Backend
from . import handlers
+from . import jobs
from . import queue
class Application(tornado.web.Application):
(r"/builders/jobs/(.*)/state/(.*)", handlers.BuildersJobsStateHandler),
# Jobs
+ (r"/jobs/([0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12})/builder",
+ jobs.BuilderHandler),
+
(r"/jobs/active", handlers.JobsGetActiveHandler),
(r"/jobs/latest", handlers.JobsGetLatestHandler),
(r"/jobs/queue", handlers.JobsGetQueueHandler),
--- /dev/null
+#!/usr/bin/python3
+###############################################################################
+# #
+# Pakfire - The IPFire package management system #
+# Copyright (C) 2011 Pakfire development team #
+# #
+# This program is free software: you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation, either version 3 of the License, or #
+# (at your option) any later version. #
+# #
+# This program is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
+# #
+###############################################################################
+
+import json
+import logging
+import tornado.websocket
+
+from .handlers import BackendMixin, HTTPBasicAuthMixin
+
+log = logging.getLogger("pakfire.hub.jobs")
+
+class BuilderHandler(BackendMixin, HTTPBasicAuthMixin, tornado.websocket.WebSocketHandler):
+ """
+ Builders connect to this handler when they are running a build.
+
+ We can pass information about this build around in real time.
+ """
+ def get_current_user(self):
+ name, password = self.get_basic_auth_credentials()
+ if name is None:
+ return
+
+ return self.backend.builders.auth(name, password)
+
+ @property
+ def builder(self):
+ return self.current_user
+
+ @tornado.web.authenticated
+ def open(self, job_id):
+ self.job = self.backend.jobs.get_by_uuid(job_id)
+ if not self.job:
+ raise tornado.web.HTTPError(404, "Could not find job %s" % job_id)
+
+ # Check if the builder matches
+ if not self.builder == self.job.builder:
+ raise tornado.web.HTTPError(403, "Job %s belongs to %s, not %s" % \
+ (self.job, self.job.builder, self.builder))
+
+ log.debug("Connection opened for %s by %s" % (self.job, self.builder))
+
+ async def on_message(self, message):
+ # Decode JSON message
+ try:
+ message = json.loads(message)
+ except json.DecodeError as e:
+ log.error("Could not decode JSON message", exc_info=True)
+ return
+
+ # Log message
+ log.debug("Received message:")
+ log.debug("%s" % json.dumps(message, indent=4))
+
+ # Get message type
+ t = message.get("message")
+
+ # Handle status messages
+ if t == "status":
+ pass
+
+ # Handle log messages
+ elif t == "log":
+ pass
+
+ # Unknown message
+ else:
+ log.warning("Received a message of an unknown type: %s" % t)