{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "#/$defs/NetworkPolicy",
  "$defs": {
    "APTSource": {
      "properties": {
        "urls": {
          "items": {
            "type": "string",
            "pattern": "^https?://[^/?#@]+(/[^?#]*)?$"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "purlNamespace": {
          "type": "string",
          "pattern": "^(?:$|[a-z0-9][a-z0-9._-]*)$"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "urls"
      ]
    },
    "CargoSource": {
      "properties": {
        "indexUrl": {
          "type": "string",
          "pattern": "^https?://[^/?#@]+(/[^?#]*)?$"
        },
        "downloadUrl": {
          "type": "string",
          "pattern": "^https?://[^/?#@]+(/[^?#]*)?$"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "indexUrl",
        "downloadUrl"
      ]
    },
    "Connection": {
      "oneOf": [
        {
          "required": [
            "tls"
          ],
          "title": "tls"
        },
        {
          "required": [
            "tcp"
          ],
          "title": "tcp"
        },
        {
          "required": [
            "udp"
          ],
          "title": "udp"
        },
        {
          "required": [
            "icmp"
          ],
          "title": "icmp"
        }
      ],
      "properties": {
        "tls": {
          "$ref": "#/$defs/TLSConnection"
        },
        "tcp": {
          "$ref": "#/$defs/TCPConnection"
        },
        "udp": {
          "$ref": "#/$defs/UDPConnection"
        },
        "icmp": {
          "$ref": "#/$defs/ICMPConnection"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "GitHTTPSTransport": {
      "properties": {
        "baseUrl": {
          "type": "string",
          "pattern": "^https?://[^/?#@]+(/[^?#]*)?$"
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "baseUrl"
      ]
    },
    "GitSSHTransport": {
      "properties": {
        "host": {
          "type": "string",
          "pattern": "^(\\*\\.)?[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$"
        },
        "port": {
          "type": "integer",
          "maximum": 65535,
          "minimum": 1
        },
        "user": {
          "type": "string"
        },
        "upstreamKnownHosts": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "host",
        "port"
      ]
    },
    "GitSource": {
      "anyOf": [
        {
          "required": [
            "https"
          ],
          "title": "https"
        },
        {
          "required": [
            "ssh"
          ],
          "title": "ssh"
        }
      ],
      "properties": {
        "repositoryPatterns": {
          "items": {
            "type": "string",
            "format": "repository-pattern"
          },
          "type": "array",
          "uniqueItems": true
        },
        "https": {
          "items": {
            "$ref": "#/$defs/GitHTTPSTransport"
          },
          "type": "array",
          "minItems": 1
        },
        "ssh": {
          "items": {
            "$ref": "#/$defs/GitSSHTransport"
          },
          "type": "array",
          "minItems": 1
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "HTTPSource": {
      "properties": {
        "urls": {
          "items": {
            "type": "string",
            "pattern": "^https?://[^/?#@]+(/[^?#]*)?$"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "urls"
      ]
    },
    "ICMPConnection": {
      "properties": {
        "cidrs": {
          "items": {
            "type": "string",
            "format": "ipv4-or-prefix"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "cidrs"
      ]
    },
    "NetworkPolicy": {
      "properties": {
        "default": {
          "type": "string",
          "enum": [
            "deny",
            "allow"
          ],
          "default": "deny"
        },
        "presets": {
          "items": {
            "$ref": "#/$defs/Preset"
          },
          "type": "array",
          "uniqueItems": true,
          "description": "Built-in network policies to enable. When omitted, presets marked as enabled by default are used. Set this to an empty list to disable every built-in preset.",
          "default": [
            "alpine",
            "bitbucket",
            "cache-nixos-org",
            "cargo",
            "debian",
            "docker-apt",
            "dockerhub",
            "ecr-public",
            "fonts",
            "gcr",
            "ghcr",
            "github",
            "gitlab",
            "golang",
            "googlesource",
            "nodesource",
            "npm",
            "openembedded",
            "pypi",
            "quay",
            "raspbian",
            "rubygems",
            "ubuntu",
            "yocto",
            "generic-http"
          ]
        },
        "sources": {
          "items": {
            "$ref": "#/$defs/Source"
          },
          "type": "array"
        },
        "connections": {
          "items": {
            "$ref": "#/$defs/Connection"
          },
          "type": "array"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "OCISource": {
      "properties": {
        "urls": {
          "items": {
            "type": "string",
            "pattern": "^https?://[^/?#@]+(/[^?#]*)?$"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "repositoryPatterns": {
          "items": {
            "type": "string",
            "format": "repository-pattern"
          },
          "type": "array",
          "uniqueItems": true
        },
        "operations": {
          "items": {
            "type": "string",
            "enum": [
              "pull",
              "push",
              "delete"
            ]
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "urls",
        "operations"
      ]
    },
    "Preset": {
      "type": "string",
      "enum": [
        "alpine",
        "bitbucket",
        "cache-nixos-org",
        "cargo",
        "debian",
        "docker-apt",
        "dockerhub",
        "ecr-public",
        "fonts",
        "gcr",
        "ghcr",
        "github",
        "gitlab",
        "golang",
        "googlesource",
        "nodesource",
        "npm",
        "openembedded",
        "pypi",
        "quay",
        "raspbian",
        "rubygems",
        "ubuntu",
        "yocto",
        "generic-http"
      ]
    },
    "Source": {
      "oneOf": [
        {
          "required": [
            "pypi"
          ],
          "title": "pypi"
        },
        {
          "required": [
            "npm"
          ],
          "title": "npm"
        },
        {
          "required": [
            "rubygems"
          ],
          "title": "rubygems"
        },
        {
          "required": [
            "oci"
          ],
          "title": "oci"
        },
        {
          "required": [
            "git"
          ],
          "title": "git"
        },
        {
          "required": [
            "apt"
          ],
          "title": "apt"
        },
        {
          "required": [
            "apk"
          ],
          "title": "apk"
        },
        {
          "required": [
            "cargo"
          ],
          "title": "cargo"
        },
        {
          "required": [
            "golang"
          ],
          "title": "golang"
        },
        {
          "required": [
            "nix"
          ],
          "title": "nix"
        }
      ],
      "properties": {
        "pypi": {
          "$ref": "#/$defs/HTTPSource"
        },
        "npm": {
          "$ref": "#/$defs/HTTPSource"
        },
        "rubygems": {
          "$ref": "#/$defs/HTTPSource"
        },
        "oci": {
          "$ref": "#/$defs/OCISource"
        },
        "git": {
          "$ref": "#/$defs/GitSource"
        },
        "apt": {
          "$ref": "#/$defs/APTSource"
        },
        "apk": {
          "$ref": "#/$defs/HTTPSource"
        },
        "cargo": {
          "$ref": "#/$defs/CargoSource"
        },
        "golang": {
          "$ref": "#/$defs/HTTPSource"
        },
        "nix": {
          "$ref": "#/$defs/HTTPSource"
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "TCPConnection": {
      "anyOf": [
        {
          "required": [
            "hostPatterns"
          ],
          "title": "hosts"
        },
        {
          "required": [
            "cidrs"
          ],
          "title": "cidrs"
        }
      ],
      "properties": {
        "hostPatterns": {
          "items": {
            "type": "string",
            "pattern": "^(\\*\\.)?[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "cidrs": {
          "items": {
            "type": "string",
            "format": "ip-or-prefix"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "ports": {
          "items": {
            "type": "integer",
            "maximum": 65535,
            "minimum": 1
          },
          "type": "array",
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "type": "object"
    },
    "TLSConnection": {
      "anyOf": [
        {
          "required": [
            "serverNamePatterns"
          ],
          "title": "serverNames"
        },
        {
          "required": [
            "cidrs"
          ],
          "title": "cidrs"
        }
      ],
      "properties": {
        "serverNamePatterns": {
          "items": {
            "type": "string",
            "pattern": "^(\\*\\.)?[A-Za-z0-9]([A-Za-z0-9.-]*[A-Za-z0-9])?$"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "cidrs": {
          "items": {
            "type": "string",
            "format": "ip-or-prefix"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "ports": {
          "items": {
            "type": "integer",
            "maximum": 65535,
            "minimum": 1
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "alpn": {
          "items": {
            "type": "string",
            "minLength": 1
          },
          "type": "array",
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "ports"
      ]
    },
    "UDPConnection": {
      "properties": {
        "cidrs": {
          "items": {
            "type": "string",
            "format": "ipv4-or-prefix"
          },
          "type": "array",
          "minItems": 1,
          "uniqueItems": true
        },
        "ports": {
          "items": {
            "type": "integer",
            "maximum": 65535,
            "minimum": 1
          },
          "type": "array",
          "uniqueItems": true
        }
      },
      "additionalProperties": false,
      "type": "object",
      "required": [
        "cidrs"
      ]
    }
  }
}
