{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://paulkov.github.io/dpone/schemas/gitops/deployment-set.schema.json",
  "title": "dpone GitOps deployment-set",
  "type": "object",
  "required": [
    "schema",
    "deployment_id",
    "environment",
    "release_ref",
    "runtime_artifact_delivery"
  ],
  "additionalProperties": true,
  "properties": {
    "schema": {
      "const": "dpone.deployment-set.v1"
    },
    "deployment_id": {
      "$ref": "#/$defs/identity"
    },
    "deployment_type": {
      "enum": [
        "preview",
        "environment"
      ]
    },
    "runnable": {
      "type": "boolean"
    },
    "environment": {
      "type": "string",
      "minLength": 1
    },
    "release_ref": {
      "$ref": "#/$defs/identity"
    },
    "binding_set_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "connection_registry_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "credential_runtime_ref": {
      "anyOf": [
        {
          "$ref": "#/$defs/identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "runtime_image_digest": {
      "anyOf": [
        {
          "$ref": "#/$defs/identity"
        },
        {
          "type": "null"
        }
      ]
    },
    "airflow_bundle_ref": {
      "type": [
        "string",
        "null"
      ]
    },
    "runtime_artifact_delivery": {
      "type": "object",
      "additionalProperties": true,
      "properties": {
        "mode": {
          "enum": [
            "local_preview",
            "init_fetch",
            "shared_pvc",
            "embedded_bundle",
            "csi_volume",
            "inline"
          ]
        },
        "artifact_registry_ref": {
          "type": "string",
          "pattern": "^(?!.*%)(?!(?:[Cc][Uu][Rr][Rr][Ee][Nn][Tt]|[Ll][Aa][Tt][Ee][Ss][Tt])(?:$|[/:@?#=&]))(?!.*[/:@?#=&](?:[Cc][Uu][Rr][Rr][Ee][Nn][Tt]|[Ll][Aa][Tt][Ee][Ss][Tt])(?:$|[/:@?#=&]))\\S+$"
        },
        "identity": {
          "type": "object",
          "required": [
            "method",
            "service_account"
          ],
          "additionalProperties": true,
          "properties": {
            "method": {
              "enum": [
                "kubernetes_workload_identity"
              ]
            },
            "service_account": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "source": {
          "type": "object",
          "required": [
            "artifact_registry_ref"
          ],
          "additionalProperties": true,
          "properties": {
            "artifact_registry_ref": {
              "type": "string",
              "pattern": "^(?!.*%)(?!(?:[Cc][Uu][Rr][Rr][Ee][Nn][Tt]|[Ll][Aa][Tt][Ee][Ss][Tt])(?:$|[/:@?#=&]))(?!.*[/:@?#=&](?:[Cc][Uu][Rr][Rr][Ee][Nn][Tt]|[Ll][Aa][Tt][Ee][Ss][Tt])(?:$|[/:@?#=&]))\\S+$"
            }
          }
        },
        "verify": {
          "type": "object",
          "required": [
            "checksums",
            "attestations"
          ],
          "additionalProperties": true,
          "properties": {
            "checksums": {
              "enum": [
                "required"
              ]
            },
            "attestations": {
              "enum": [
                "optional",
                "required_for_prod"
              ]
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "mode": {
                "const": "init_fetch"
              }
            },
            "required": [
              "mode"
            ]
          },
          "then": {
            "required": [
              "artifact_registry_ref",
              "identity",
              "source",
              "verify"
            ]
          }
        }
      ],
      "required": [
        "mode"
      ]
    }
  },
  "$defs": {
    "identity": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    }
  }
}
