{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/gradle-build-cache-node/versions/4.0.json",
  "description": "The configuration format for build cache nodes",
  "x-lintel": {
    "source": "https://docs.gradle.com/develocity/build-cache-node/schema/build-cache-node-config-schema-4.json",
    "sourceSha256": "13dcd303563b877fb731ca2af828e85bc3298349519e76a9d86d8655c1027850",
    "fileMatch": [
      "*build-cache-node-config.yml",
      "*build-cache-node-config.yaml"
    ],
    "parsers": [
      "yaml"
    ]
  },
  "type": "object",
  "properties": {
    "version": {
      "const": 4,
      "description": "The version of the config file model (must be 4)."
    },
    "cache": {
      "allOf": [
        {
          "type": "object",
          "properties": {
            "accessControl": {
              "allOf": [
                {
                  "type": "object",
                  "properties": {
                    "anonymousLevel": {
                      "type": "string",
                      "enum": [
                        "none",
                        "read",
                        "readwrite"
                      ],
                      "description": "The level of the access for anonymous users"
                    },
                    "users": {
                      "type": "object",
                      "description": "The users of the cache and their access level",
                      "additionalProperties": {
                        "$ref": "#/$defs/NodeCacheUser"
                      }
                    }
                  },
                  "description": "These credentials are used to restrict access to the build cache",
                  "minProperties": 1,
                  "additionalProperties": false
                },
                {
                  "description": "The credentials for reading and writing to the cache"
                }
              ]
            },
            "freeSpaceBufferSize": {
              "type": "integer",
              "description": "The free space buffer to reserve in MiB",
              "minimum": 0
            },
            "maxArtifactSize": {
              "type": "integer",
              "description": "The maximum size of a single artifact in the cache in MiB",
              "minimum": 1
            },
            "maxEntryAgeInHours": {
              "type": [
                "integer",
                "null"
              ],
              "description": "The maximum age of an artifact in the cache in hours, if enabled",
              "minimum": 1
            },
            "targetSize": {
              "type": "object",
              "properties": {
                "type": {
                  "enum": [
                    "fixed",
                    "maxAvailable"
                  ]
                }
              },
              "required": [
                "type"
              ],
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "type": {
                        "const": "fixed"
                      }
                    }
                  },
                  "then": {
                    "$ref": "#/$defs/TargetSizeFixed"
                  }
                },
                {
                  "if": {
                    "properties": {
                      "type": {
                        "const": "maxAvailable"
                      }
                    }
                  },
                  "then": {
                    "$ref": "#/$defs/TargetSizeMaxAvailable"
                  }
                }
              ],
              "minProperties": 1
            }
          },
          "description": "Settings around cache size and access",
          "minProperties": 1,
          "additionalProperties": false
        },
        {
          "description": "The cache settings"
        }
      ]
    },
    "registration": {
      "allOf": [
        {
          "type": [
            "object",
            "null"
          ],
          "properties": {
            "key": {
              "type": "string",
              "description": "The key of the node (can be found on the nodes screen of Gradle Enterprise)"
            },
            "nodeAddress": {
              "type": "string",
              "description": "The URI of this build cache node",
              "format": "uri"
            },
            "secret": {
              "type": "string",
              "description": "The secret of the node (can be found on the nodes screen of Gradle Enterprise)"
            },
            "serverAddress": {
              "type": "string",
              "description": "The URI of the Gradle Enterprise instance",
              "format": "uri"
            }
          },
          "required": [
            "key",
            "nodeAddress",
            "secret",
            "serverAddress"
          ],
          "description": "Settings for connecting to Gradle Enterprise",
          "minProperties": 1,
          "additionalProperties": false
        },
        {
          "description": "The registration details to connect to Gradle Enterprise"
        }
      ]
    },
    "uiAccess": {
      "type": "object",
      "properties": {
        "type": {
          "enum": [
            "disabled",
            "open",
            "secure",
            "generated"
          ]
        }
      },
      "required": [
        "type"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "type": {
                "const": "disabled"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/UiAccessDisabled"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "open"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/UiAccessOpen"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "secure"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/UiAccessSecure"
          }
        },
        {
          "if": {
            "properties": {
              "type": {
                "const": "generated"
              }
            }
          },
          "then": {
            "$ref": "#/$defs/UiAccessGenerated"
          }
        }
      ],
      "minProperties": 1
    }
  },
  "$defs": {
    "Entry(String,NodeCacheUser)": {
      "type": "object",
      "properties": {
        "key": {
          "type": "string"
        },
        "value": {
          "$ref": "#/$defs/NodeCacheUser"
        },
        "hashCode()": {
          "type": "integer"
        }
      },
      "required": [
        "key",
        "value",
        "hashCode()"
      ],
      "minProperties": 1,
      "additionalProperties": false
    },
    "NodeCacheUser": {
      "type": "object",
      "properties": {
        "level": {
          "type": "string",
          "enum": [
            "read",
            "readwrite"
          ],
          "description": "The level of the access for the build cache user"
        },
        "note": {
          "type": [
            "string",
            "null"
          ],
          "description": "Some optional free text"
        },
        "password": {
          "allOf": [
            {
              "$ref": "#/$defs/Sha256HashedSecretString"
            },
            {
              "description": "The hashed password of the user"
            }
          ]
        }
      },
      "required": [
        "level",
        "password"
      ],
      "description": "A user of the build cache",
      "minProperties": 1,
      "additionalProperties": false
    },
    "Sha256HashedSecretString": {
      "type": "string",
      "pattern": "^(?:\\s*[A-Za-z0-9+/]){43}(?:\\s*=):(?:(?:\\s*[A-Za-z0-9+/]){4})*(?:(?:\\s*[A-Za-z0-9+/]){2}(?:\\s*=){2}|(?:\\s*[A-Za-z0-9+/]){3}(?:\\s*=))?\\s*$"
    },
    "TargetSizeFixed": {
      "type": "object",
      "description": "Use a fixed target cache size",
      "properties": {
        "type": {
          "const": "fixed"
        },
        "size": {
          "type": "integer",
          "description": "The total available size of the cache in MiB",
          "minimum": 1
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },
    "TargetSizeMaxAvailable": {
      "type": "object",
      "description": "Set the target cache size dynamically based on the disk volume's capacity",
      "properties": {
        "type": {
          "const": "maxAvailable"
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },
    "UiAccessDisabled": {
      "type": "object",
      "description": "Access to the build cache node UI is disabled",
      "properties": {
        "type": {
          "const": "disabled"
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },
    "UiAccessGenerated": {
      "type": "object",
      "description": "Generated as startup credentials used for secure access to cache node UI",
      "properties": {
        "type": {
          "const": "generated"
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },
    "UiAccessOpen": {
      "type": "object",
      "description": "Access to the build cache node UI is open for anyone",
      "properties": {
        "type": {
          "const": "open"
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    },
    "UiAccessSecure": {
      "type": "object",
      "required": [
        "password",
        "username"
      ],
      "description": "Credentials used for secure access to cache node UI",
      "properties": {
        "type": {
          "const": "secure"
        },
        "password": {
          "allOf": [
            {
              "$ref": "#/$defs/Sha256HashedSecretString"
            },
            {
              "description": "The hashed password for securing the cache node UI"
            }
          ]
        },
        "username": {
          "type": "string",
          "description": "The username for securing the cache node UI"
        }
      },
      "minProperties": 1,
      "additionalProperties": false
    }
  },
  "additionalProperties": false,
  "minProperties": 1,
  "required": [
    "version"
  ]
}
