コード例 #1
0
ファイル: worker.py プロジェクト: catlee/signingworker
    def process_message(self, body, message):
        task_id = None
        run_id = None
        work_dir = tempfile.mkdtemp()
        try:
            task_id = body["status"]["taskId"]
            run_id = body["status"]["runs"][-1]["runId"]
            log.debug("Claiming task %s, run %s", task_id, run_id)
            self.tc_queue.claimTask(
                task_id, run_id,
                {"workerGroup": self.worker_type, "workerId": self.worker_id}
            )
            task = self.tc_queue.task(task_id)
            task_graph_id = task["taskGroupId"]
            validate_task(task)
            validate_signature(task_id,
                               task["extra"]["signing"]["signature"],
                               self.pub_key)
            self.sign(task_id, run_id, task, work_dir)
            log.debug("Completing: %s, r: %s", task_id, run_id)
            self.tc_queue.reportCompleted(task_id, run_id)
            log.debug("Complete: %s, r: %s, tg: %s", task_id, run_id,
                      task_graph_id)
        except taskcluster.exceptions.TaskclusterRestFailure as e:
            log.exception("TC REST failure, %s", e.status_code)
            if e.status_code == 409:
                log.debug("Task already claimed, acking...")
            else:
                raise
        except (TaskVerificationError, ValidationError, JOSEError):
            log.exception("Cannot verify task, %s", body)
            self.tc_queue.reportException(
                task_id, run_id, {"reason": "malformed-payload"})
        except Exception:
            log.exception("Error processing %s", body)

        message.ack()
        shutil.rmtree(work_dir)
コード例 #2
0
    def process_message(self, body, message):
        task_id = None
        run_id = None
        work_dir = tempfile.mkdtemp()
        try:
            task_id = body["status"]["taskId"]
            run_id = body["status"]["runs"][-1]["runId"]
            log.debug("Claiming task %s, run %s", task_id, run_id)
            self.tc_queue.claimTask(
                task_id, run_id,
                {"workerGroup": self.worker_type, "workerId": self.worker_id}
            )
            task = self.tc_queue.task(task_id)
            task_graph_id = task["taskGroupId"]
            validate_task(task)
            validate_signature(task_id,
                               task["extra"]["signing"]["signature"],
                               self.pub_key)
            self.sign(task_id, run_id, task, work_dir)
            log.debug("Completing: %s, r: %s", task_id, run_id)
            self.tc_queue.reportCompleted(task_id, run_id)
            log.debug("Complete: %s, r: %s, tg: %s", task_id, run_id,
                      task_graph_id)
        except taskcluster.exceptions.TaskclusterRestFailure as e:
            log.exception("TC REST failure, %s", e.status_code)
            if e.status_code == 409:
                log.debug("Task already claimed, acking...")
            else:
                raise
        except (TaskVerificationError, ValidationError, JOSEError):
            log.exception("Cannot verify task, %s", body)
            self.tc_queue.reportException(
                task_id, run_id, {"reason": "malformed-payload"})
        except Exception:
            log.exception("Error processing %s", body)

        message.ack()
        shutil.rmtree(work_dir)
コード例 #3
0
 def test_valid_signature(self):
     validate_signature("blah", valid_signature, PUB_KEY)