plugin/hub: use jsonschema to validate input

Use jsonschema to validate the input to the XMLRPC call to catch
mistakes early, i.e. before creating the task.
This commit is contained in:
Christian Kellner 2020-09-10 00:33:54 +02:00 committed by Tom Gundersen
parent 3dc463c8dd
commit af4e66d2b2
2 changed files with 62 additions and 0 deletions

View file

@ -1,5 +1,8 @@
"""Koji osbuild integration for Koji Hub"""
import sys
import jsonschema
import logging
import koji
from koji.context import context
@ -8,6 +11,62 @@ sys.path.insert(0, "/usr/share/koji-hub/")
import kojihub
OSBUILD_IMAGE_SCHMEA = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "osbuildImage arguments",
"type": "array",
"minItems": 7,
"items": [
{
"type": "string",
"description": "Name"
},
{
"type": "string",
"description": "Version"
},
{
"type": "string",
"description": "Distribution"
},
{
"type": "array",
"description": "Image Types",
"minItems": 1
},
{
"type": "string",
"description": "Target"
},
{
"type": "array",
"description": "Architectures",
"minItems": 1
},
{
"type": "object",
"$ref": "#/definitions/options"
}],
"definitions": {
"options":{
"title": "Optional arguments",
"type": "object",
"additionalProperties": False,
"properties": {
"repo": {
"type": "string",
"description": "Repositories"
},
"release": {
"type": "string",
"description": "Release override"
}
}
}
}
}
@koji.plugin.export
def osbuildImage(name, version, distro, image_types, target, arches, opts=None, priority=None):
"""Create an image via osbuild"""
@ -15,6 +74,8 @@ def osbuildImage(name, version, distro, image_types, target, arches, opts=None,
args = [name, version, distro, image_types, target, arches, opts]
task = {"channel": "image"}
jsonschema.validate(args, OSBUILD_IMAGE_SCHMEA)
if priority and priority < 0 and not context.session.hasPerm('admin'):
raise koji.ActionNotAllowed('only admins may create high-priority tasks')