Define tasks via config file
This commit is contained in:
parent
437afbb720
commit
1a06b1b52e
3 changed files with 29 additions and 5 deletions
|
|
@ -41,7 +41,10 @@ Special task method is created for achieving this which is called
|
|||
After task finishes, one can find the tarball on relevant task web page (URL
|
||||
will be printed to stdout until ``--quiet`` is used.
|
||||
|
||||
Currently plugin allow to save trees only for ``buildArch`` tasks and anybody
|
||||
Plugin allow to save trees only for tasks defined in config
|
||||
``/etc/koji-hub/plugins/save_failed_tree.conf``. Option
|
||||
``allowed_methods`` contains list of comma-delimited names of tasks. Default
|
||||
configuration contains line: ``allowed_methods = buildArch``. Anybody
|
||||
is allowed to create this type of task (and download tarball).
|
||||
|
||||
.. warning::
|
||||
|
|
|
|||
7
plugins/hub/save_failed_tree.conf
Normal file
7
plugins/hub/save_failed_tree.conf
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# config file for the Koji save-failed-trees plugin
|
||||
|
||||
[permissions]
|
||||
# task methods for whose can be triggered buildroot export
|
||||
# * can be used to allow everything. In such case it must be only component
|
||||
# on line. Otherwise multiple values are delimited by comma.
|
||||
allowed_methods = buildArch
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import sys
|
||||
import ConfigParser
|
||||
import koji
|
||||
from koji.plugin import export
|
||||
|
||||
|
|
@ -7,23 +8,36 @@ import kojihub
|
|||
|
||||
__all__ = ('saveFailedTree',)
|
||||
|
||||
CONFIG_FILE = '/etc/koji-hub/plugins/save_failed_tree.conf'
|
||||
config = None
|
||||
allowed_methods = None
|
||||
|
||||
|
||||
@export
|
||||
def saveFailedTree(taskID, full=False, **opts):
|
||||
'''xmlrpc method for creating saveFailedTree task. If arguments are
|
||||
invalid, error message is returned. Otherwise task id of newly created
|
||||
task is returned.'''
|
||||
global config, allowed_methods
|
||||
|
||||
# let it raise errors
|
||||
taskID = int(taskID)
|
||||
full = bool(full)
|
||||
|
||||
# read configuration only once
|
||||
if config is None:
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
config.read(CONFIG_FILE)
|
||||
allowed_methods = config.get('permissions', 'allowed_methods').split()
|
||||
if len(allowed_methods) == 1 and allowed_methods[0] == '*':
|
||||
allowed_methods = '*'
|
||||
|
||||
task_info = kojihub.Task(taskID).getInfo()
|
||||
if task_info['state'] != koji.TASK_STATES['FAILED']:
|
||||
return 'Task %s has not failed.' % taskID
|
||||
elif task_info['method'] != 'buildArch':
|
||||
# TODO: allowed tasks could be defined in plugin hub config
|
||||
return 'Only buildArch tasks can upload buildroot (Task %(id)s is %(method)s).' % task_info
|
||||
return 'Task %s has not failed. Only failed tasks can upload their buildroots.' % taskID
|
||||
elif allowed_methods != '*' and task_info['method'] not in allowed_methods:
|
||||
return 'Only %s tasks can upload their buildroots (Task %s is %s).' % \
|
||||
(', '.join(allowed_methods), task_info['id'], task_info['method'])
|
||||
# owner?
|
||||
# permissions?
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue