{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://paulkov.github.io/dpone/schemas/gitops/airflow-evidence-bundle.schema.json",
  "title": "dpone GitOps Airflow evidence bundle contract",
  "type": "object",
  "required": [
    "kind",
    "schema_version",
    "producer",
    "runner_policy",
    "attempt",
    "pod",
    "artifacts"
  ],
  "properties": {
    "kind": {
      "const": "gitops.airflow_evidence_bundle"
    },
    "schema_version": {
      "type": "string"
    },
    "producer": {
      "type": "string"
    },
    "runner_policy": {
      "type": "string"
    },
    "attempt": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "dag_id",
        "task_id",
        "run_id",
        "try_number",
        "map_index"
      ],
      "properties": {
        "dag_id": {
          "type": "string"
        },
        "task_id": {
          "type": "string"
        },
        "run_id": {
          "type": "string"
        },
        "try_number": {
          "type": "integer"
        },
        "map_index": {
          "type": "integer"
        }
      }
    },
    "pod": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "pod_name",
        "pod_uid",
        "namespace",
        "service_account",
        "image",
        "image_digest"
      ],
      "properties": {
        "pod_name": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "pod_uid": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "namespace": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "service_account": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "image": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        },
        "image_digest": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "artifacts": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": true,
        "required": [
          "name",
          "path",
          "expected_kind",
          "actual_kind",
          "required",
          "exists",
          "sha256",
          "bytes",
          "passed",
          "reason"
        ],
        "properties": {
          "name": {
            "type": "string"
          },
          "path": {
            "type": "string"
          },
          "expected_kind": {
            "type": "string"
          },
          "actual_kind": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "required": {
            "type": "boolean"
          },
          "exists": {
            "type": "boolean"
          },
          "sha256": {
            "anyOf": [
              {
                "type": "string"
              },
              {
                "type": "null"
              }
            ]
          },
          "bytes": {
            "anyOf": [
              {
                "type": "integer"
              },
              {
                "type": "null"
              }
            ]
          },
          "passed": {
            "type": "boolean"
          },
          "reason": {
            "type": "string"
          }
        }
      }
    },
    "run_identity": {
      "type": "object",
      "required": [
        "schema",
        "release_id",
        "deployment_id",
        "dag_spec",
        "workload_pack",
        "runtime_image_digest",
        "binding_set_ref",
        "connection_registry_ref",
        "credential_runtime_ref",
        "airflow_bundle"
      ],
      "additionalProperties": false,
      "properties": {
        "schema": {
          "const": "dpone.airflow-run-identity.v1"
        },
        "release_id": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "deployment_id": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "dag_spec": {
          "anyOf": [
            {
              "type": "object",
              "required": [
                "id",
                "sha256"
              ],
              "additionalProperties": false,
              "properties": {
                "id": {
                  "type": "string",
                  "minLength": 1
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                }
              }
            },
            {
              "type": "null"
            }
          ]
        },
        "workload_pack": {
          "type": "object",
          "required": [
            "id",
            "sha256"
          ],
          "additionalProperties": false,
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "sha256": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            }
          }
        },
        "runtime_image_digest": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "binding_set_ref": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "connection_registry_ref": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "credential_runtime_ref": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "airflow_bundle": {
          "anyOf": [
            {
              "type": "object",
              "required": [
                "backend",
                "ref",
                "versioned",
                "version",
                "snapshot_ref"
              ],
              "additionalProperties": false,
              "properties": {
                "backend": {
                  "type": "string",
                  "minLength": 1
                },
                "ref": {
                  "type": "string",
                  "minLength": 1,
                  "pattern": "^\\S+$",
                  "not": {
                    "pattern": "(?:[?&](?:token|password|signature|credential|x-amz-signature|x-goog-signature)=|://[^/]*@)"
                  }
                },
                "versioned": {
                  "type": "boolean"
                },
                "version": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "snapshot_ref": {
                  "anyOf": [
                    {
                      "type": "string",
                      "pattern": "^sha256:[0-9a-f]{64}$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "allOf": [
                {
                  "if": {
                    "properties": {
                      "versioned": {
                        "const": true
                      }
                    }
                  },
                  "then": {
                    "properties": {
                      "version": {
                        "type": "string",
                        "minLength": 1
                      }
                    }
                  },
                  "else": {
                    "properties": {
                      "version": {
                        "type": "null"
                      }
                    }
                  }
                }
              ]
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "correlation": {
      "type": "object",
      "required": [
        "schema",
        "correlation_id",
        "attempt_ref",
        "airflow",
        "dpone",
        "artifacts",
        "pod"
      ],
      "additionalProperties": false,
      "properties": {
        "schema": {
          "const": "dpone.airflow-correlation.v1"
        },
        "correlation_id": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "attempt_ref": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "airflow": {
          "type": "object",
          "required": [
            "dag_id",
            "task_id",
            "run_id",
            "try_number",
            "map_index"
          ],
          "additionalProperties": false,
          "properties": {
            "dag_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1024
            },
            "task_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1024
            },
            "run_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 1024
            },
            "try_number": {
              "type": "integer",
              "minimum": 1
            },
            "map_index": {
              "type": "integer",
              "minimum": -1
            }
          }
        },
        "dpone": {
          "type": "object",
          "required": [
            "run_id",
            "process"
          ],
          "additionalProperties": false,
          "properties": {
            "run_id": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1024
                },
                {
                  "type": "null"
                }
              ]
            },
            "process": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 253
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "artifacts": {
          "type": "object",
          "required": [
            "release_id",
            "deployment_id",
            "workload_id",
            "workload_pack_sha256",
            "runtime_evidence_sha256"
          ],
          "additionalProperties": false,
          "properties": {
            "release_id": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "deployment_id": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "workload_id": {
              "type": "string",
              "minLength": 1,
              "maxLength": 253
            },
            "workload_pack_sha256": {
              "type": "string",
              "pattern": "^sha256:[0-9a-f]{64}$"
            },
            "runtime_evidence_sha256": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        },
        "pod": {
          "type": "object",
          "required": [
            "name",
            "uid",
            "namespace",
            "image_digest"
          ],
          "additionalProperties": false,
          "properties": {
            "name": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 253
                },
                {
                  "type": "null"
                }
              ]
            },
            "uid": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 1024
                },
                {
                  "type": "null"
                }
              ]
            },
            "namespace": {
              "anyOf": [
                {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 253
                },
                {
                  "type": "null"
                }
              ]
            },
            "image_digest": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^sha256:[0-9a-f]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        }
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/issue"
      }
    },
    "blockers": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/issue"
      }
    }
  },
  "$defs": {
    "issue": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "code",
        "message",
        "path",
        "source"
      ],
      "properties": {
        "code": {
          "type": "string"
        },
        "message": {
          "type": "string"
        },
        "path": {
          "type": "string"
        },
        "source": {
          "type": "string"
        }
      }
    }
  },
  "additionalProperties": true
}
