{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://nocip.com/assets/api/target.schema.json",
 "title": "NOCIP test target",
 "description": "The release NOCIP downloads and tests itself, and how the test lab runs it headless. Placeholders: {port} (a free local port), {state} (an empty writable folder, also HOME), {file:NAME} (an uploaded file, e.g. a test licence), {in}/{out} (CLI processing), {text} (inside process.http.json). Currently supported: kind linux-x64-binary.",
 "type": "object",
 "additionalProperties": false,
 "required": [
  "schema",
  "kind",
  "version",
  "download_url",
  "sha256",
  "start",
  "process"
 ],
 "properties": {
  "schema": {
   "const": "nocip-test-target/1"
  },
  "kind": {
   "enum": [
    "linux-x64-binary"
   ]
  },
  "version": {
   "type": "string",
   "maxLength": 50
  },
  "download_url": {
   "type": "string",
   "pattern": "^https://\\S+$",
   "maxLength": 500,
   "description": "public download address; NOCIP downloads the file itself"
  },
  "download_auth": {
   "type": "string",
   "pattern": "^sha256:[0-9a-f]{64}$",
   "description": "for a download that needs a login: an uploaded text file with one HTTP header line (e.g. Authorization: Bearer ...), used only for this download and never logged"
  },
  "sha256": {
   "type": "string",
   "pattern": "^[0-9a-f]{64}$"
  },
  "size": {
   "type": "integer",
   "minimum": 1
  },
  "published_checksum_url": {
   "type": "string",
   "pattern": "^https://\\S+$",
   "maxLength": 500
  },
  "files": {
   "type": "object",
   "maxProperties": 10,
   "additionalProperties": {
    "type": "string",
    "pattern": "^sha256:[0-9a-f]{64}$"
   },
   "description": "NAME → an uploaded file (evidence), e.g. a test licence"
  },
  "network": {
   "type": "object",
   "additionalProperties": false,
   "properties": {
    "local_ips": {
     "type": "array",
     "maxItems": 4,
     "items": {
      "type": "string",
      "pattern": "^[0-9]{1,3}(\\.[0-9]{1,3}){3}$"
     },
     "description": "extra local IPv4 addresses inside the isolated lab network (e.g. for an IP-bound test licence)"
    }
   }
  },
  "selftest": {
   "type": "object",
   "additionalProperties": false,
   "required": [
    "args"
   ],
   "properties": {
    "args": {
     "type": "array",
     "maxItems": 60,
     "items": {
      "type": "string",
      "maxLength": 500
     }
    },
    "expect_exit": {
     "type": "integer"
    },
    "expect_stdout": {
     "type": "string",
     "maxLength": 200
    }
   }
  },
  "start": {
   "type": "object",
   "additionalProperties": false,
   "required": [
    "args",
    "ready_http"
   ],
   "properties": {
    "args": {
     "type": "array",
     "maxItems": 60,
     "items": {
      "type": "string",
      "maxLength": 500
     }
    },
    "ready_http": {
     "type": "string",
     "pattern": "^http://127\\.0\\.0\\.1:\\{port\\}/\\S*$"
    },
    "ready_timeout_s": {
     "type": "integer",
     "minimum": 5,
     "maximum": 300
    }
   }
  },
  "process": {
   "type": "object",
   "additionalProperties": false,
   "properties": {
    "http": {
     "type": "object",
     "additionalProperties": false,
     "required": [
      "url",
      "json"
     ],
     "properties": {
      "url": {
       "type": "string",
       "pattern": "^http://127\\.0\\.0\\.1:\\{port\\}/\\S*$"
      },
      "json": {
       "type": "object"
      },
      "expect_status": {
       "type": "array",
       "items": {
        "type": "integer"
       }
      }
     }
    },
    "cli": {
     "type": "object",
     "additionalProperties": false,
     "required": [
      "args"
     ],
     "properties": {
      "args": {
       "type": "array",
       "maxItems": 60,
       "items": {
        "type": "string",
        "maxLength": 500
       }
      }
     }
    }
   },
   "minProperties": 1,
   "maxProperties": 1
  }
 }
}
