stages & assemblers: don't allow additional props

Change all the schemata to not allow additional properties. This
should help with misspelled properties as well as missing schema
information in the stage itself.

Done via a small python3 script:

   --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< --- 8< ---

import os
import sys

def list_stages(base):
    return [(base, f) for f in os.listdir(base) if f.startswith("org.osbuild")]

stages = list_stages("stages")
stages += list_stages("assemblers")

def find_line(lines, start):
    for i, l in enumerate(lines):
        if l.startswith(start):
            return i
    return None

NOADD = '"additionalProperties": false'

for stage in stages:
    with open(f"{stage[0]}/{stage[1]}", "r") as f:
        print(f"{stage[0]}/{stage[1]}", file=sys.stderr)
        data = f.readlines()
        i = find_line(data, 'STAGE_OPTS = """')
        if i:
            data.insert(i+1, NOADD + ",\n")
        else:
            i = find_line(data, 'STAGE_OPTS = ""')
            if i:
                data[i] = f'STAGE_OPTS = """\n'
                data.insert(i+1, NOADD + "\n")
                data.insert(i+2, '"""\n')

    with open(f"{stage[0]}/{stage[1]}", "w") as f:
        f.writelines(data)
This commit is contained in:
Christian Kellner 2020-04-25 14:17:57 +02:00
parent 554d8dc868
commit 01ce01b1c7
28 changed files with 32 additions and 2 deletions

View file

@ -8,7 +8,9 @@ STAGE_INFO = """
No-op assembler. Produces no output, just prints a JSON dump of its options
and then exits.
"""
STAGE_OPTS = ""
STAGE_OPTS = """
"additionalProperties": false
"""
def main(_tree, _output_dir, options):
print("Not doing anything with these options:", json.dumps(options))

View file

@ -22,6 +22,7 @@ the commit id and the compose information respectively.
[1] https://ostree.readthedocs.io/en/stable/manual/adapting-existing/
"""
STAGE_OPTS = """
"additionalProperties": false,
"required": ["ref"],
"properties": {
"ref": {

View file

@ -30,6 +30,7 @@ Buildhost commands used: `truncate`, `mount`, `umount`, `sfdisk`,
`grub2-mkimage`, `mkfs.ext4` or `mkfs.xfs`, `qemu-img`.
"""
STAGE_OPTS = """
"additionalProperties": false,
"required": ["format", "filename", "ptuuid", "size"],
"oneOf": [{
"required": ["root_fs_uuid"]

View file

@ -26,6 +26,7 @@ generate with uuid.uuid4() in Python, `uuidgen(1)` in a shell script, or
read from `/proc/sys/kernel/random/uuid` if your kernel provides it.
"""
STAGE_OPTS = """
"additionalProperties": false,
"required": ["filename", "root_fs_uuid", "size"],
"properties": {
"filename": {

View file

@ -22,6 +22,7 @@ caller is responsible for making sure that `compression` and `filename` match.
Buildhost commands used: `tar` and any named `compression` program.
"""
STAGE_OPTS = """
"additionalProperties": false,
"required": ["filename"],
"properties": {
"filename": {