{
 "$schema": "https://kairos.io/v1.6.0/cloud-config.json",
 "title": "Kairos Schema",
 "description": "Defines all valid Kairos configuration attributes.",
 "required": [
  "users"
 ],
 "definitions": {
  "SchemasBundleSchema": {
   "properties": {
    "db_path": {
     "type": "string"
    },
    "local_file": {
     "type": "boolean"
    },
    "repository": {
     "type": "string"
    },
    "rootfs_path": {
     "type": "string"
    },
    "targets": {
     "items": {
      "type": "string"
     },
     "type": "array"
    }
   },
   "type": "object"
  },
  "SchemasGrubOptionsSchema": {
   "properties": {
    "default_fallback": {
     "description": "Sets default fallback logic",
     "type": "string"
    },
    "default_menu_entry": {
     "description": "Change GRUB menu entry",
     "type": "string"
    },
    "extra_active_cmdline": {
     "description": "Additional Kernel option cmdline to apply just for active",
     "type": "string"
    },
    "extra_cmdline": {
     "description": "Additional Kernel option cmdline to apply",
     "type": "string"
    },
    "extra_passive_cmdline": {
     "description": "Additional Kernel option cmdline to apply just for passive",
     "type": "string"
    },
    "extra_recovery_cmdline": {
     "description": "Set additional boot commands when booting into recovery",
     "type": "string"
    },
    "next_entry": {
     "description": "Set the next reboot entry.",
     "type": "string"
    },
    "saved_entry": {
     "description": "Set the default boot entry.",
     "type": "string"
    }
   },
   "type": "object"
  },
  "SchemasInstallSchema": {
   "title": "Kairos Schema: Install block",
   "description": "The install block is to drive automatic installations without user interaction.",
   "properties": {
    "auto": {
     "description": "Set to true when installing without Pairing",
     "type": "boolean"
    },
    "bind_mounts": {
     "items": {
      "type": "string"
     },
     "type": "array"
    },
    "bundles": {
     "description": "Add bundles in runtime",
     "items": {
      "$ref": "#/definitions/SchemasBundleSchema"
     },
     "type": "array"
    },
    "device": {
     "description": "Device for automated installs",
     "examples": [
      "auto",
      "/dev/sda"
     ],
     "pattern": "^(auto|/|(/[a-zA-Z0-9_-]+)+)$",
     "type": "string"
    },
    "encrypted_partitions": {
     "items": {
      "type": "string"
     },
     "type": "array"
    },
    "env": {
     "items": {},
     "type": "array"
    },
    "ephemeral_mounts": {
     "items": {
      "type": "string"
     },
     "type": "array"
    },
    "grub_options": {
     "$ref": "#/definitions/SchemasGrubOptionsSchema"
    },
    "image": {
     "description": "Use a different container image for the installation",
     "type": "string"
    },
    "skip_copy_kcrypt_plugin": {
     "type": "boolean"
    }
   },
   "type": "object",
   "oneOf": [
    {
     "$ref": "#/definitions/SchemasNoPowerManagement"
    },
    {
     "$ref": "#/definitions/SchemasRebootOnly"
    },
    {
     "$ref": "#/definitions/SchemasPowerOffOnly"
    }
   ]
  },
  "SchemasNoPowerManagement": {
   "properties": {
    "poweroff": {
     "description": "Power off after installation",
     "default": false,
     "const": false,
     "type": "boolean"
    },
    "reboot": {
     "description": "Reboot after installation",
     "default": false,
     "const": false,
     "type": "boolean"
    }
   },
   "type": "object"
  },
  "SchemasP2PAutoDisabled": {
   "required": [
    "network_token"
   ],
   "properties": {
    "auto": {
     "required": [
      "enable"
     ],
     "properties": {
      "enable": {
       "const": false,
       "type": "boolean"
      },
      "ha": {
       "properties": {
        "enable": {
         "const": false,
         "type": "boolean"
        }
       },
       "type": "object"
      }
     },
     "type": "object"
    },
    "network_token": {
     "const": "",
     "type": "string"
    }
   },
   "type": "object"
  },
  "SchemasP2PAutoEnabled": {
   "required": [
    "network_token"
   ],
   "properties": {
    "auto": {
     "properties": {
      "enable": {
       "const": true,
       "type": "boolean"
      },
      "ha": {
       "properties": {
        "enable": {
         "const": true,
         "type": "boolean"
        },
        "master_nodes": {
         "description": "Number of HA additional master nodes. A master node is always required for creating the cluster and is implied.",
         "minimum": 1,
         "type": "integer"
        }
       },
       "type": "object"
      }
     },
     "type": "object"
    },
    "network_token": {
     "description": "network_token is the shared secret used by the nodes to co-ordinate with p2p",
     "minLength": 1,
     "type": "string"
    }
   },
   "type": "object"
  },
  "SchemasP2PSchema": {
   "title": "Kairos Schema: P2P block",
   "description": "The p2p block enables the p2p full-mesh functionalities.",
   "properties": {
    "disable_dht": {
     "description": "Disabling DHT makes co-ordination to discover nodes only in the local network",
     "default": true,
     "type": "boolean"
    },
    "dns": {
     "description": "Enable embedded DNS See also: https://mudler.github.io/edgevpn/docs/concepts/overview/dns/",
     "type": "boolean"
    },
    "network_id": {
     "description": "User defined network-id. Can be used to have multiple clusters in the same network",
     "type": "string"
    },
    "role": {
     "default": "none",
     "enum": [
      "master",
      "worker",
      "none"
     ],
     "type": "string"
    },
    "vpn": {
     "$ref": "#/definitions/SchemasVPN"
    }
   },
   "type": "object",
   "oneOf": [
    {
     "$ref": "#/definitions/SchemasP2PAutoEnabled"
    },
    {
     "$ref": "#/definitions/SchemasP2PAutoDisabled"
    }
   ]
  },
  "SchemasPowerOffOnly": {
   "required": [
    "poweroff"
   ],
   "properties": {
    "poweroff": {
     "description": "Power off after installation",
     "default": false,
     "const": true,
     "type": "boolean"
    },
    "reboot": {
     "description": "Reboot after installation",
     "default": false,
     "const": false,
     "type": "boolean"
    }
   },
   "type": "object"
  },
  "SchemasRebootOnly": {
   "required": [
    "reboot"
   ],
   "properties": {
    "poweroff": {
     "description": "Power off after installation",
     "default": false,
     "const": false,
     "type": "boolean"
    },
    "reboot": {
     "description": "Reboot after installation",
     "default": false,
     "const": true,
     "type": "boolean"
    }
   },
   "type": "object"
  },
  "SchemasUserSchema": {
   "title": "Kairos Schema: Users block",
   "description": "The users block allows you to create users in the system.",
   "required": [
    "name"
   ],
   "properties": {
    "groups": {
     "examples": [
      "admin"
     ],
     "type": "string"
    },
    "lockPasswd": {
     "examples": [
      true
     ],
     "type": "boolean"
    },
    "name": {
     "examples": [
      "kairos"
     ],
     "pattern": "([a-z_][a-z0-9_]{0,30})",
     "type": "string"
    },
    "passwd": {
     "examples": [
      "kairos"
     ],
     "type": "string"
    },
    "ssh_authorized_keys": {
     "examples": [
      "github:USERNAME",
      "ssh-ed25519 AAAF00BA5"
     ],
     "items": {
      "type": "string"
     },
     "type": "array"
    }
   },
   "type": "object"
  },
  "SchemasVPN": {
   "properties": {
    "env": {
     "items": {},
     "type": "array"
    },
    "use": {
     "default": true,
     "type": "boolean"
    },
    "vpn": {
     "default": true,
     "type": "boolean"
    }
   },
   "type": "object"
  }
 },
 "properties": {
  "bundles": {
   "description": "Add bundles in runtime",
   "items": {
    "$ref": "#/definitions/SchemasBundleSchema"
   },
   "type": "array"
  },
  "config_url": {
   "description": "URL download configuration from.",
   "type": "string"
  },
  "env": {
   "items": {
    "type": "string"
   },
   "type": "array"
  },
  "fail_on_bundles_errors": {
   "type": "boolean"
  },
  "grub_options": {
   "$ref": "#/definitions/SchemasGrubOptionsSchema"
  },
  "install": {
   "$ref": "#/definitions/SchemasInstallSchema"
  },
  "options": {
   "description": "Various options.",
   "items": {},
   "type": "array"
  },
  "p2p": {
   "$ref": "#/definitions/SchemasP2PSchema"
  },
  "users": {
   "items": {
    "$ref": "#/definitions/SchemasUserSchema"
   },
   "minItems": 1,
   "type": "array"
  }
 },
 "type": "object"
}
