{
  "$id": "https://json.schemastore.org/azure-iot-edgeagent-deployment-1.0.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "definitions": {
    "moduleType": {
      "enum": ["docker"]
    },
    "status": {
      "enum": ["running", "stopped"]
    },
    "restartPolicy": {
      "enum": ["never", "on-failure", "on-unhealthy", "always"]
    },
    "moduleSettings": {
      "type": "object",
      "required": ["image"],
      "properties": {
        "image": {
          "type": "string",
          "examples": ["mcr.microsoft.com/azureiotedge-agent:1.0"]
        },
        "createOptions": {
          "$ref": "#/definitions/createOptions"
        }
      }
    },
    "env": {
      "type": "object",
      "patternProperties": {
        "^[^\\+#$\\s\\.]+$": {
          "type": "object",
          "required": ["value"],
          "properties": {
            "value": {
              "type": ["number", "string", "boolean"]
            }
          }
        }
      },
      "additionalProperties": false
    },
    "createOptions": {
      "type": "string",
      "contentMediaType": "application/json"
    }
  },
  "properties": {
    "$edgeAgent": {
      "type": "object",
      "title": "Configuration for the edgeAgent module",
      "required": ["properties.desired"],
      "properties": {
        "properties.desired": {
          "type": "object",
          "required": ["schemaVersion", "runtime", "systemModules", "modules"],
          "properties": {
            "schemaVersion": {
              "type": "string",
              "pattern": "1.0"
            },
            "runtime": {
              "type": "object",
              "required": ["type", "settings"],
              "properties": {
                "type": {
                  "$ref": "#/definitions/moduleType"
                },
                "settings": {
                  "type": "object",
                  "properties": {
                    "minDockerVersion": {
                      "type": "string",
                      "examples": ["v1.25"]
                    },
                    "loggingOptions": {
                      "type": "string"
                    },
                    "registryCredentials": {
                      "type": "object",
                      "patternProperties": {
                        "^.+$": {
                          "type": "object",
                          "required": ["username", "password", "address"],
                          "properties": {
                            "username": {
                              "type": "string"
                            },
                            "password": {
                              "type": "string"
                            },
                            "address": {
                              "type": "string",
                              "pattern": "^[^\\s]+$"
                            }
                          }
                        }
                      },
                      "additionalProperties": false
                    }
                  }
                }
              }
            },
            "systemModules": {
              "type": "object",
              "required": ["edgeAgent", "edgeHub"],
              "properties": {
                "edgeAgent": {
                  "type": "object",
                  "required": ["type", "settings"],
                  "properties": {
                    "type": {
                      "$ref": "#/definitions/moduleType"
                    },
                    "settings": {
                      "$ref": "#/definitions/moduleSettings"
                    },
                    "env": {
                      "$ref": "#/definitions/env"
                    }
                  }
                },
                "edgeHub": {
                  "type": "object",
                  "title": "The Edgehub Schema",
                  "required": ["type", "settings", "status", "restartPolicy"],
                  "properties": {
                    "type": {
                      "$ref": "#/definitions/moduleType"
                    },
                    "settings": {
                      "$ref": "#/definitions/moduleSettings"
                    },
                    "env": {
                      "$ref": "#/definitions/env"
                    },
                    "status": {
                      "$ref": "#/definitions/status"
                    },
                    "restartPolicy": {
                      "$ref": "#/definitions/restartPolicy"
                    }
                  }
                }
              },
              "additionalProperties": false
            },
            "modules": {
              "type": "object",
              "patternProperties": {
                "^[a-zA-Z0-9_-]+$": {
                  "type": "object",
                  "required": ["type", "status", "restartPolicy", "settings"],
                  "properties": {
                    "version": {
                      "type": "string",
                      "examples": ["1.0"]
                    },
                    "type": {
                      "$ref": "#/definitions/moduleType"
                    },
                    "status": {
                      "$ref": "#/definitions/status"
                    },
                    "restartPolicy": {
                      "$ref": "#/definitions/restartPolicy"
                    },
                    "env": {
                      "$ref": "#/definitions/env"
                    },
                    "settings": {
                      "$ref": "#/definitions/moduleSettings"
                    }
                  }
                }
              },
              "additionalProperties": false
            }
          }
        }
      }
    }
  },
  "required": ["$edgeAgent"],
  "title": "JSON schema for Azure IoT EdgeAgent Deployment version 1.0",
  "type": "object"
}
