From 6dbac570ad27d42bf64dea95e9b051e3e6fd68c8 Mon Sep 17 00:00:00 2001 From: Neil Armstrong Date: Tue, 31 Oct 2023 13:16:19 +0100 Subject: [PATCH] Add yaml schema and validator Closes: #41 Signed-off-by: Neil Armstrong --- schema.yaml | 244 ++++++++++++++++++++++++++++++++++++++++++++++++++++ validate.py | 23 +++++ 2 files changed, 267 insertions(+) create mode 100644 schema.yaml create mode 100644 validate.py diff --git a/schema.yaml b/schema.yaml new file mode 100644 index 0000000..f1a278b --- /dev/null +++ b/schema.yaml @@ -0,0 +1,244 @@ +"$schema": https://json-schema.org/draft/2020-12/schema# +title: CDBA Configuration Schema +type: object +properties: + devices: + type: array + items: + type: object + properties: + board: + type: string + + name: + type: string + + description: + type: string + + console: + type: string + pattern: "^/dev/.*$" + + fastboot: + type: string + pattern: "^[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]$" + + fastboot_set_active: + type: boolean + + broken_fastboot_boot: + type: boolean + + usb_always_on: + type: boolean + + fastboot_key_timeout: + type: integer + minimum: 1 + + cdba: + type: string + pattern: "^/dev/.*$" + + conmux: + type: string + pattern: "^/dev/.*$" + + external: + type: string + + ppps_path: + type: string + + ppps3_path: + type: string + + qcomlt_debug_board: + type: string + pattern: "^/dev/.*$" + + voltage: + type: integer + + alpaca: + type: string + pattern: "^/dev/.*$" + + users: + type: array + uniqueItems: true + minItems: 1 + items: + type: string + + ftdi_gpio: + oneOf: + - type: string + pattern: "^s:0x[0-9A-f][0-9a-f][0-9a-f][0-9a-f]:0x[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:FT[0-9a-zA-Z]{6};[A-D](;(POWER|FASTBOOT_KEY|POWER_KEY|USB_DISCONNECT),[0-7],(ACTIVE_HIGH|ACTIVE_LOW)){1,4}$" + + - type: object + properties: + description: + type: string + pattern: "^s:0x[0-9A-f][0-9a-f][0-9a-f][0-9a-f]:0x[0-9a-f][0-9a-f][0-9a-f][0-9a-f]:FT[0-9a-zA-Z]{6}$" + interface: + enum: + - A + - B + - C + - D + gpios: + type: array + unevaluatedItems: false + minItems: 1 + prefixItems: + - type: object + properties: + power: + type: object + properties: + line: + type: integer + minimum: 0 + maximum: 7 + active_low: + type: boolean + required: + - line + - type: object + properties: + fastboot_key: + type: object + properties: + line: + type: integer + minimum: 0 + maximum: 7 + active_low: + type: boolean + required: + - line + - type: object + properties: + power_key: + type: object + properties: + line: + type: integer + minimum: 0 + maximum: 7 + active_low: + type: boolean + required: + - line + - type: object + properties: + usb_disconnect: + type: object + properties: + line: + type: integer + minimum: 0 + maximum: 7 + active_low: + type: boolean + required: + - line + - type: object + properties: + output_enable: + type: object + properties: + line: + type: integer + minimum: 0 + maximum: 7 + active_low: + type: boolean + required: + - line + required: + - description + - interface + - gpios + + local_gpio: + type: array + unevaluatedItems: false + minItems: 1 + prefixItems: + - type: object + properties: + power: + type: object + properties: + chip: + type: string + pattern: "^gpiochip[0-9]+$" + line: + type: integer + minimum: 0 + active_low: + type: boolean + required: + - chip + - line + - type: object + properties: + fastboot_key: + type: object + properties: + chip: + type: string + pattern: "^gpiochip[0-9]+$" + line: + type: integer + minimum: 0 + active_low: + type: boolean + required: + - chip + - line + - type: object + properties: + power_key: + type: object + properties: + chip: + type: string + pattern: "^gpiochip[0-9]+$" + line: + type: integer + minimum: 0 + active_low: + type: boolean + required: + - chip + - line + - type: object + properties: + usb_disconnect: + type: object + properties: + chip: + type: string + pattern: "^gpiochip[0-9]+$" + line: + type: integer + minimum: 0 + active_low: + type: boolean + required: + - chip + - line + required: + - board + - name + + additionalProperties: false + +required: + - devices + +additionalProperties: false diff --git a/validate.py b/validate.py new file mode 100644 index 0000000..e0dfc5b --- /dev/null +++ b/validate.py @@ -0,0 +1,23 @@ +import os +import sys +import argparse +import json +import jsonschema +import ruamel.yaml + +if __name__ == "__main__": + ap = argparse.ArgumentParser() + ap.add_argument("cfg", help="Filename YAML input file") + ap.add_argument('-s', '--schema', help="schema file") + args = ap.parse_args() + + yaml = ruamel.yaml.YAML(typ='safe') + yaml.allow_duplicate_keys = False + + with open(args.schema, 'r', encoding='utf-8') as f: + schema = yaml.load(f.read()) + + with open(args.cfg, 'r', encoding='utf-8') as f: + cfg = yaml.load(f.read()) + + jsonschema.validate(cfg, schema=schema)