{
  "$schema" : "http://json-schema.org/draft-07/schema#",
  "definitions" : {
    "Entry(String,NodeCacheUser)" : {
      "type" : "object",
      "properties" : {
        "key" : {
          "type" : "string"
        },
        "value" : {
          "$ref" : "#/definitions/NodeCacheUser"
        },
        "hashCode()" : {
          "type" : "integer"
        }
      },
      "required" : [ "key", "value", "hashCode()" ],
      "additionalProperties" : false,
      "minProperties" : 1
    },
    "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" : "#/definitions/Sha256HashedSecretString"
          }, {
            "description" : "The hashed password of the user"
          } ]
        }
      },
      "required" : [ "level", "password" ],
      "description" : "A user of the build cache",
      "additionalProperties" : false,
      "minProperties" : 1
    },
    "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",
      "additionalProperties" : false,
      "minProperties" : 1,
      "properties" : {
        "type" : {
          "const" : "fixed"
        },
        "size" : {
          "type" : "integer",
          "description" : "The total available size of the cache in MiB",
          "minimum" : 1
        }
      }
    },
    "TargetSizeMaxAvailable" : {
      "type" : "object",
      "description" : "Set the target cache size dynamically based on the disk volume's capacity",
      "additionalProperties" : false,
      "minProperties" : 1,
      "properties" : {
        "type" : {
          "const" : "maxAvailable"
        }
      }
    },
    "UiAccessDisabled" : {
      "type" : "object",
      "description" : "Access to the build cache node UI is disabled",
      "additionalProperties" : false,
      "minProperties" : 1,
      "properties" : {
        "type" : {
          "const" : "disabled"
        }
      }
    },
    "UiAccessGenerated" : {
      "type" : "object",
      "description" : "Generated as startup credentials used for secure access to cache node UI",
      "additionalProperties" : false,
      "minProperties" : 1,
      "properties" : {
        "type" : {
          "const" : "generated"
        }
      }
    },
    "UiAccessOpen" : {
      "type" : "object",
      "description" : "Access to the build cache node UI is open for anyone",
      "additionalProperties" : false,
      "minProperties" : 1,
      "properties" : {
        "type" : {
          "const" : "open"
        }
      }
    },
    "UiAccessSecure" : {
      "type" : "object",
      "required" : [ "password", "username" ],
      "description" : "Credentials used for secure access to cache node UI",
      "additionalProperties" : false,
      "minProperties" : 1,
      "properties" : {
        "type" : {
          "const" : "secure"
        },
        "password" : {
          "allOf" : [ {
            "$ref" : "#/definitions/Sha256HashedSecretString"
          }, {
            "description" : "The hashed password for securing the cache node UI"
          } ]
        },
        "username" : {
          "type" : "string",
          "description" : "The username for securing the cache node UI"
        }
      }
    }
  },
  "type" : "object",
  "description" : "The configuration format for build cache nodes",
  "additionalProperties" : false,
  "minProperties" : 1,
  "properties" : {
    "version" : {
      "const" : 5,
      "description" : "The version of the config file model (must be 5)."
    },
    "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",
                  "additionalProperties" : {
                    "$ref" : "#/definitions/NodeCacheUser"
                  },
                  "description" : "The users of the cache and their access level"
                }
              },
              "description" : "These credentials are used to restrict access to the build cache",
              "additionalProperties" : false,
              "minProperties" : 1
            }, {
              "description" : "The credentials for reading and writing to the cache"
            } ]
          },
          "freeSpaceBufferSize" : {
            "type" : "integer",
            "description" : "The free space buffer to reserve in MiB",
            "minimum" : 256
          },
          "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" : "#/definitions/TargetSizeFixed"
              }
            }, {
              "if" : {
                "properties" : {
                  "type" : {
                    "const" : "maxAvailable"
                  }
                }
              },
              "then" : {
                "$ref" : "#/definitions/TargetSizeMaxAvailable"
              }
            } ],
            "minProperties" : 1
          }
        },
        "description" : "Settings around cache size and access",
        "additionalProperties" : false,
        "minProperties" : 1
      }, {
        "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",
        "additionalProperties" : false,
        "minProperties" : 1
      }, {
        "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" : "#/definitions/UiAccessDisabled"
        }
      }, {
        "if" : {
          "properties" : {
            "type" : {
              "const" : "open"
            }
          }
        },
        "then" : {
          "$ref" : "#/definitions/UiAccessOpen"
        }
      }, {
        "if" : {
          "properties" : {
            "type" : {
              "const" : "secure"
            }
          }
        },
        "then" : {
          "$ref" : "#/definitions/UiAccessSecure"
        }
      }, {
        "if" : {
          "properties" : {
            "type" : {
              "const" : "generated"
            }
          }
        },
        "then" : {
          "$ref" : "#/definitions/UiAccessGenerated"
        }
      } ],
      "minProperties" : 1
    }
  },
  "required" : [ "version" ]
}