From 0428f356b099b57877d9903ea1b06e2f710023e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Lesimple?= Date: Sat, 21 Dec 2024 12:05:18 +0000 Subject: [PATCH] wip --- json-schema/include/ip-or-netblock.jsonschema | 21 +++++ json-schema/include/result.jsonschema | 81 +++++++++++++++++++ json-schema/plugins/alive.jsonschema | 12 +++ json-schema/plugins/ping.jsonschema | 51 ++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 json-schema/include/ip-or-netblock.jsonschema create mode 100644 json-schema/include/result.jsonschema create mode 100644 json-schema/plugins/alive.jsonschema create mode 100644 json-schema/plugins/ping.jsonschema diff --git a/json-schema/include/ip-or-netblock.jsonschema b/json-schema/include/ip-or-netblock.jsonschema new file mode 100644 index 0000000..1c68e6e --- /dev/null +++ b/json-schema/include/ip-or-netblock.jsonschema @@ -0,0 +1,21 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://ovh.github.io/the-bastion/schemas/plugins-include/ip-or-netblock", + "type": "string", + "anyOf": [ + { + "format": "ipv4" + }, + { + "format": "ipv6" + }, + { + "$comment": "IPv4 netblock", + "pattern": "^((25[0-5]|(2[0-4]|1\\d|[1-9]|)\\d)\\.?\\b){4}/(\\d|[12]\\d|3[012])$" + }, + { + "$comment": "IPv6 validation through regexes is extremely cumbersome, so just validate that it does roughly look like an IPv6 netblock", + "pattern": "^[a-fA-F0-9:]+/(12[0-8]|1[01]\\d|\\d\\d?)$" + } + ] +} diff --git a/json-schema/include/result.jsonschema b/json-schema/include/result.jsonschema new file mode 100644 index 0000000..6278be6 --- /dev/null +++ b/json-schema/include/result.jsonschema @@ -0,0 +1,81 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://ovh.github.io/the-bastion/schemas/plugins-include/result", + "$defs": { + "command": { + "description": "Command name", + "type": "string", + "pattern": "^[a-z][a-zA-Z]+$", + "minLength": 2 + }, + "error_message": { + "type": "string", + "minLength": 2 + }, + "session_id": { + "type": "string", + "pattern": "^[a-f0-9]{12}$" + } + }, + "type": "object", + "additionalProperties": true, + "minProperties": 5, + "maxProperties": 5, + "oneOf": [ + { + "additionalProperties": false, + "properties": { + "command": { + "oneOf": [ + { + "type": "null" + }, + { + "$ref": "#/$defs/command" + } + ] + }, + "error_message": { + "$ref": "#/$defs/error_message" + }, + "error_code": { + "type": "string", + "pattern": "^(ERR|KO)(_[A-Z_]+)?$" + }, + "value": { + "type": ["array","object","null"] + }, + "session_id": { + "$ref": "#/$defs/session_id" + } + } + }, + { + "additionalProperties": false, + "properties": { + "command": { + "$ref": "#/$defs/command" + }, + "error_message": { + "$ref": "#/$defs/error_message" + }, + "error_code": { + "type": "string", + "pattern": "^OK(_[A-Z_]+)?$" + }, + "value": { + "type": ["array","object","null"] + }, + "session_id": { + "$ref": "#/$defs/session_id" + } + } + } + ], + "required": [ + "command", + "error_code", + "error_message", + "value" + ] +} diff --git a/json-schema/plugins/alive.jsonschema b/json-schema/plugins/alive.jsonschema new file mode 100644 index 0000000..d58a27b --- /dev/null +++ b/json-schema/plugins/alive.jsonschema @@ -0,0 +1,12 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://ovh.github.io/the-bastion/schemas/plugins/alive", + "type": "object", + "allowAdditionalProperties": false, + "properties": { + "waited_for": { + "type": "integer", + "minimum": 0 + } + } +} diff --git a/json-schema/plugins/ping.jsonschema b/json-schema/plugins/ping.jsonschema new file mode 100644 index 0000000..f024ef2 --- /dev/null +++ b/json-schema/plugins/ping.jsonschema @@ -0,0 +1,51 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://ovh.github.io/the-bastion/schemas/plugins/ping", + "type": "object", + "allowAdditionalProperties": false, + "required":["sysret","host"], + "properties": { + "max": { + "type": "number", + "minimum": 0 + }, + "sysret": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "packets_received": { + "type": "integer", + "minimum": 0 + }, + "host": { + "type": "string", + "format": "hostname" + }, + "packets_loss_percentage": { + "type": "integer", + "minimum": 0, + "maximum": 100 + }, + "min": { + "type": "number", + "minimum": 0 + }, + "ping_duration": { + "type": "integer", + "minimum": 0 + }, + "mdev": { + "type": "number", + "minimum": 0 + }, + "packets_transmitted": { + "type": "integer", + "minimum": 0 + }, + "avg": { + "type": "number", + "minimum": 0 + } + } +}