{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "description": "The clusterd settings",
    "markdownDescription": "The clusterd settings",
    "additionalProperties": false,
    "required": [
        "version"
    ],
    "properties": {
        "version": {
            "type": "string",
            "enum": [
                "1.2"
            ],
            "description": "The software version the configuration was created for"
        },
        "reservedtime": {
            "type": "integer",
            "default": 1,
            "minimum": 0,
            "description": "The number of seconds to keep a slot reserved"
        },
        "listener": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "address": {
                    "description": "Listen address",
                    "anyOf": [
                        {
                            "$ref": "#/definitions/ipv4"
                        },
                        {
                            "$ref": "#/definitions/ipv6"
                        }
                    ]
                },
                "port": {
                    "type": "integer",
                    "maximum": 65535,
                    "default": 2530,
                    "minimum": 1,
                    "description": "Port number"
                }
            }
        },
        "pki": {
            "type": "object",
            "additionalProperties": false,
            "required": [
                "certificate",
                "privatekey"
            ],
            "oneOf": [
                {
                    "required": [
                        "clientcerts"
                    ]
                },
                {
                    "required": [
                        "clientnames"
                    ]
                }
            ],
            "properties": {
                "certificate": {
                    "oneOf": [
                        {
                            "type": "object",
                            "additionalProperties": false,
                            "required": [
                                "data"
                            ],
                            "properties": {
                                "data": {
                                    "type": "string",
                                    "minLength": 1,
                                    "description": "The PKCS #8 PEM data"
                                }
                            }
                        },
                        {
                            "type": "object",
                            "additionalProperties": false,
                            "required": [
                                "path"
                            ],
                            "properties": {
                                "path": {
                                    "type": "string",
                                    "minLength": 1,
                                    "description": "The PKCS #8 PEM path"
                                }
                            }
                        }
                    ]
                },
                "privatekey": {
                    "oneOf": [
                        {
                            "type": "object",
                            "additionalProperties": false,
                            "required": [
                                "data"
                            ],
                            "properties": {
                                "data": {
                                    "type": "string",
                                    "minLength": 1,
                                    "description": "The private key data"
                                }
                            }
                        },
                        {
                            "type": "object",
                            "additionalProperties": false,
                            "required": [
                                "path"
                            ],
                            "properties": {
                                "path": {
                                    "type": "string",
                                    "minLength": 1,
                                    "description": "The private key path"
                                }
                            }
                        }
                    ]
                },
                "cacerts": {
                    "type": "array",
                    "uniqueItems": true,
                    "description": "List of CA to trust",
                    "items": {
                        "oneOf": [
                            {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "data"
                                ],
                                "properties": {
                                    "data": {
                                        "type": "string",
                                        "minLength": 1,
                                        "description": "The PKCS #8 PEM path"
                                    }
                                }
                            },
                            {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "path"
                                ],
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "minLength": 1,
                                        "description": "The PKCS #8 PEM path"
                                    }
                                }
                            }
                        ]
                    }
                },
                "crls": {
                    "type": "array",
                    "uniqueItems": true,
                    "description": "List of CRLs",
                    "items": {
                        "oneOf": [
                            {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "data"
                                ],
                                "properties": {
                                    "data": {
                                        "type": "string",
                                        "minLength": 1,
                                        "description": "The PKCS #8 PEM path"
                                    }
                                }
                            },
                            {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "path"
                                ],
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "minLength": 1,
                                        "description": "The PKCS #8 PEM path"
                                    }
                                }
                            }
                        ]
                    }
                },
                "clientcerts": {
                    "type": "array",
                    "uniqueItems": true,
                    "description": "List of clientcertificates to allow",
                    "items": {
                        "oneOf": [
                            {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "data"
                                ],
                                "properties": {
                                    "data": {
                                        "type": "string",
                                        "minLength": 1,
                                        "description": "The PKCS #8 PEM path"
                                    }
                                }
                            },
                            {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "path"
                                ],
                                "properties": {
                                    "path": {
                                        "type": "string",
                                        "minLength": 1,
                                        "description": "The PKCS #8 PEM path"
                                    }
                                }
                            }
                        ]
                    }
                },
                "clientnames": {
                    "type": "array",
                    "uniqueItems": true,
                    "description": "List of clientcertificates names to allow (supports wildcards, eg. .example.com)",
                    "items": {
                        "type": "string"
                    }
                }
            }
        },
        "environment": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "privdrop": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "user": {
                            "type": "string",
                            "description": "Privdrop user"
                        },
                        "group": {
                            "type": "string",
                            "description": "Privdrop group"
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "mode": {
            "type": "string",
            "pattern": "^[0-7][0-7][0-7][0-7]$",
            "minLength": 4,
            "maxLength": 4
        },
        "ipv4": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|#.*|.*[*].*)$)(?:(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])(\\.(?!$)|$)){4}$",
            "minLength": 7
        },
        "ipv6": {
            "type": "string",
            "pattern": "^(?!(?:\/.*\/|#.*|.*[*].*)$)(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$",
            "minLength": 3
        }
    }
}
