1# This Source Code Form is subject to the terms of the Mozilla Public 2# License, v. 2.0. If a copy of the MPL was not distributed with this 3# file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 5from __future__ import absolute_import, print_function, unicode_literals 6 7import logging 8import os 9 10from . import base 11from taskgraph.util.templates import Templates 12 13 14logger = logging.getLogger(__name__) 15GECKO = os.path.realpath(os.path.join(__file__, '..', '..', '..', '..')) 16ARTIFACT_URL = 'https://queue.taskcluster.net/v1/task/{}/artifacts/{}' 17INDEX_URL = 'https://index.taskcluster.net/v1/task/{}' 18 19 20class SigningTask(base.Task): 21 22 def __init__(self, kind, name, task, attributes): 23 self.unsigned_artifact_label = task['unsigned-task']['label'] 24 super(SigningTask, self).__init__(kind, name, task=task['task'], 25 attributes=attributes) 26 27 @classmethod 28 def load_tasks(cls, kind, path, config, params, loaded_tasks): 29 root = os.path.abspath(path) 30 31 tasks = [] 32 for filename in config.get('jobs-from', []): 33 templates = Templates(root) 34 jobs = templates.load(filename, {}) 35 36 for name, job in jobs.iteritems(): 37 for artifact in job['unsigned-task']['artifacts']: 38 url = ARTIFACT_URL.format('<{}>'.format('unsigned-artifact'), artifact) 39 job['task']['payload']['unsignedArtifacts'].append({ 40 'task-reference': url 41 }) 42 attributes = job.setdefault('attributes', {}) 43 attributes.update({'kind': 'signing'}) 44 tasks.append(cls(kind, name, job, attributes=attributes)) 45 46 return tasks 47 48 def get_dependencies(self, taskgraph): 49 return [(self.unsigned_artifact_label, 'unsigned-artifact')] 50 51 def optimize(self, params): 52 return False, None 53 54 @classmethod 55 def from_json(cls, task_dict): 56 unsigned_task_label = task_dict['dependencies']['unsigned-artifact'] 57 task_dict['unsigned-task'] = { 58 'label': unsigned_task_label 59 } 60 signing_task = cls(kind='build-signing', 61 name=task_dict['label'], 62 attributes=task_dict['attributes'], 63 task=task_dict) 64 return signing_task 65