{
    "$id": "http://glue42.com/gd/gw.json",
    "$schema": "http://json-schema.org/draft-06/schema#",
    "title": "io.Connect Gateway Configuration",
    "description": "Configuration settings for the io.Connect Gateway.",
    "properties": {
        "embedded": {
            "description": "If `true`, will embed the io.Connect Gateway in **io.Connect Desktop**.",
            "type": "boolean"
        },
        "configuration": {
            "$ref": "#/definitions/configuration"
        },
        "url": {
            "description": "URL pointing to the location of the Gateway. Will be used only if `\"embedded\"` is set to `false`.",
            "type": "string"
        },
        "killPortOccupier": {
            "description": "If `true`, the app that has occupied the port will be killed.",
            "type": "boolean",
            "default": false
        },
        "discoveryTimeout": {
            "description": "Interval in seconds to wait for the Gateway to provide an endpoint.",
            "type": "number"
        },
        "useBeta": {
            "type": "boolean",
            "default": false
        },
        "useLegacy": {
            "type": "boolean",
            "default": false
        }
    },
    "definitions": {
        "configuration": {
            "description": "Gateway settings related to publishing metrics, authentication, logging, ports to use and more.",
            "type": "object",
            "properties": {
                "showConsole": {
                    "description": "If `true`, the console will be visible.",
                    "type": "boolean"
                },
                "port": {
                    "description": "Port on which the io.Connect Gateway will start. Accepts either a number or a string with comma-separated list of ports and port ranges (e.g., `\"8385,8390-8395\"`).",
                    "type": [
                        "string",
                        "integer"
                    ],
                    "default": 8080
                },
                "route": {
                    "description": "",
                    "type": "string"
                },
                "logLevel": {
                    "description": "",
                    "oneOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "object"
                        }
                    ]
                },
                "logConfig": {
                    "description": "",
                    "type": "object",
                    "properties": {
                        "appenders": {
                            "description": ""
                        },
                        "categories": {
                            "description": ""
                        }
                    },
                    "additionalProperties": true
                },
                "metrics": {
                    "description": "Settings for publishing metrics.",
                    "type": "object",
                    "properties": {
                        "publishers": {
                            "description": "List of enabled metrics publishers. Each publisher has its own configuration under a key that matches the publisher name (e.g., the configuration for a `\"rest\"` publisher is under the `\"rest\"` key).",
                            "type": "array",
                            "items": {
                                "type": "string",
                                "enum": [
                                    "raw",
                                    "file",
                                    "rest",
                                    "kafka"
                                ]
                            }
                        },
                        "file": {
                            "$ref": "#/definitions/FileMetricsPublisherConfig"
                        },
                        "rest": {
                            "$ref": "#/definitions/RestMetricsPublisherConfig"
                        },
                        "kafka": {
                            "$ref": "#/definitions/KafkaMetricsPublisherConfig"
                        },
                        "raw": {
                            "description": "Metrics publisher that will write the data in a local file. The only available setting for this type of publisher is the location of the file in which to write.",
                            "type": "object",
                            "required": [
                                "location"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "location": {
                                    "description": "The location of the file in which to write.",
                                    "type": "string"
                                }
                            }
                        }
                    }
                },
                "customMetricsPublishers": {
                    "description": "List of objects defining custom metrics publishers. Used for publishing metrics with Solace or via custom JavaScript publishers. The publishers can be local or fetched from a remote location.",
                    "type": "array",
                    "items": {
                        "anyOf": [
                            {
                                "description": "Settings for a local custom metrics publisher.",
                                "type": "object",
                                "required": [
                                    "file"
                                ],
                                "properties": {
                                    "file": {
                                        "description": "The path (absolute or relative) to the Node.js module that is to be loaded.",
                                        "type": "string"
                                    },
                                    "publisherConfiguration": {
                                        "description": "Custom configuration options that will be passed as an object argument to the function exported from the Node.js module defined in the `\"file\"` property."
                                    },
                                    "metricsConfiguration": {
                                        "$ref": "#/definitions/JsMetricsPublisherConfig"
                                    }
                                }
                            },
                            {
                                "description": "Settings for a remote custom metrics publisher.",
                                "type": "object",
                                "required": [
                                    "url"
                                ],
                                "properties": {
                                    "url": {
                                        "description": "URL pointing to the location of the Node.js module that is to be loaded.",
                                        "type": "string"
                                    },
                                    "timeout": {
                                        "description": "Interval in milliseconds to wait for a response from the server. The minimum accepted value is `10`. Defaults to `2000`.",
                                        "type": "number"
                                    },
                                    "rejectUnauthorized": {
                                        "description": "If `true`, the connection is to be rejected in case of an invalid certificate. Note that this property should be set to `false` only for testing purposes and never in production.",
                                        "type": "boolean"
                                    },
                                    "publisherConfiguration": {
                                        "description": "Custom configuration options that will be passed as an object argument to the function exported from the Node.js module defined in the `\"url\"` property."
                                    },
                                    "metricsConfiguration": {
                                        "$ref": "#/definitions/JsMetricsPublisherConfig"
                                    }
                                }
                            }
                        ]
                    }
                },
                "authentication": {
                    "description": "",
                    "type": "object",
                    "properties": {
                        "available": {
                            "description": "",
                            "type": "array",
                            "items": {
                                "description": "",
                                "type": "string"
                            },
                            "default": [
                                "basic"
                            ]
                        },
                        "default": {
                            "description": "",
                            "type": "string",
                            "default": "basic"
                        },
                        "basic": {
                            "description": "Configuration for the built-in basic authenticator.",
                            "type": "object",
                            "properties": {
                                "usernameCaseSensitive": {
                                    "description": "If gateway should treat usernames as case-sensitive.",
                                    "type": "boolean",
                                    "default": false
                                }
                            }
                        },
                        "token-ttl": {
                            "description": "Token time-to-live in seconds.",
                            "type": "integer",
                            "default": 60000
                        },
                        "timeout": {
                            "description": "",
                            "type": "integer",
                            "default": 5000
                        },
                        "max-pending-requests": {
                            "description": "",
                            "type": "integer",
                            "default": 20000
                        }
                    }
                },
                "customAuthenticators": {
                    "description": "",
                    "type": "object",
                    "additionalProperties": {
                        "description": "",
                        "type": "object",
                        "properties": {
                            "file": {
                                "description": "",
                                "type": "string"
                            },
                            "configuration": {
                                "description": "",
                                "type": "object"
                            }
                        },
                        "required": [
                            "file"
                        ],
                        "additionalProperties": false
                    }
                },
                "cluster": {
                    "description": "",
                    "type": "object",
                    "properties": {
                        "enabled": {
                            "description": "",
                            "type": "boolean",
                            "default": false
                        },
                        "type": {
                            "description": "",
                            "type": "string",
                            "default": "broker"
                        },
                        "embedded_broker": {
                            "description": "",
                            "type": "object",
                            "properties": {
                                "enabled": {
                                    "description": "",
                                    "type": "boolean"
                                },
                                "route": {
                                    "description": "",
                                    "type": "string"
                                }
                            }
                        },
                        "configuration": {
                            "description": "",
                            "type": "object",
                            "properties": {
                                "binding": {
                                    "description": "",
                                    "type": "object",
                                    "properties": {
                                        "port": {
                                            "description": "",
                                            "type": "number",
                                            "default": 8085
                                        },
                                        "ip": {
                                            "description": "",
                                            "type": "string",
                                            "default": "127.0.0.1"
                                        }
                                    },
                                    "additionalProperties": false
                                },
                                "node_id": {
                                    "description": "Specifies the unique node ID in the mesh - this is required for static directories. Make sure that different io.Connect Gateways in the same mesh have different IDs.",
                                    "type": "string"
                                },
                                "directory": {
                                    "description": "",
                                    "type": "object",
                                    "properties": {
                                        "type": {
                                            "description": "",
                                            "type": "string",
                                            "default": "rest"
                                        },
                                        "config": {
                                            "description": "",
                                            "type": "object",
                                            "properties": {
                                                "directory_uri": {
                                                    "description": "",
                                                    "type": "string",
                                                    "default": "http://localhost:8888"
                                                },
                                                "announce_interval": {
                                                    "description": "",
                                                    "type": "number",
                                                    "default": 10000
                                                }
                                            },
                                            "additionalProperties": false
                                        },
                                        "members": {
                                            "description": "",
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/definitions/meshStaticMember"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "contextLifetime": {
                    "type": "string",
                    "enum": [
                        "ref-counted",
                        "ownership",
                        "retained"
                    ],
                    "description": "The default context lifetime used by this gateway",
                    "default": "retained"
                }
            }
        },
        "JsMetricsPublisherConfig": {
            "title": "JsMetricsPublisherConfig",
            "description": "Configuration regarding the way the publisher will receive the metrics.",
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "split-size": {
                    "description": "The number of pieces the metrics batch is split into when it is pushed to the publisher.",
                    "type": "integer",
                    "default": 1
                },
                "conflation": {
                    "description": "Settings for sending metrics in batches.",
                    "type": "object",
                    "properties": {
                        "max-size": {
                            "description": "The number of metrics to collect before sending them to the publisher.",
                            "type": "integer",
                            "default": 0
                        },
                        "interval": {
                            "description": "Interval in milliseconds at which to send the metrics batches.",
                            "type": "integer",
                            "default": 1000
                        }
                    }
                },
                "buffer-size": {
                    "description": "The number of metrics to store before starting to drop them (e.g., when publishing is slow).",
                    "type": "integer",
                    "default": 10000
                },
                "heartbeats": {
                    "description": "Interval in milliseconds at which status messages will be generated. Set to `-1` to disable heartbeats.",
                    "type": "integer",
                    "default": 1000
                },
                "worker": {
                    "type": "object",
                    "properties": {
                        "url": {
                            "type": "string"
                        },
                        "options": {
                            "type": "object"
                        }
                    }
                },
                "publishFn": {
                    "type": "string"
                }
            }
        },
        "FileMetricsPublisherConfig": {
            "title": "FileMetricsPublisherConfig",
            "description": "Metrics publisher that will write the data in a local file.",
            "type": "object",
            "required": [
                "location"
            ],
            "additionalProperties": false,
            "properties": {
                "location": {
                    "description": "The location of the file in which to write.",
                    "type": "string"
                },
                "append": {
                    "description": "If `true`, will append the new metrics to the existing file on restart of **io.Connect Desktop**. Otherwise, will overwrite it.",
                    "type": "boolean",
                    "default": false
                },
                "conflation": {
                    "description": "Settings for sending metrics in batches.",
                    "type": "object",
                    "properties": {
                        "max-size": {
                            "description": "The number of metrics to collect before sending them to the publisher.",
                            "type": "integer",
                            "default": 0
                        },
                        "interval": {
                            "description": "Interval in milliseconds at which to send the metrics batches.",
                            "type": "integer",
                            "default": 1000
                        }
                    }
                },
                "buffer-size": {
                    "description": "The number of metrics to store before starting to drop them (e.g., when publishing is slow).",
                    "type": "integer",
                    "default": 10000
                },
                "heartbeats": {
                    "description": "Interval in milliseconds at which status messages will be generated. Set to `-1` to disable heartbeats.",
                    "type": "integer",
                    "default": 1000
                },
                "worker": {
                    "type": "object",
                    "properties": {
                        "url": {
                            "type": "string"
                        },
                        "options": {
                            "type": "object"
                        }
                    }
                },
                "publishFn": {
                    "type": "string"
                }
            }
        },
        "RestMetricsPublisherConfig": {
            "title": "RestMetricsPublisherConfig",
            "description": "Metrics publisher that will post the data to a REST service.",
            "type": "object",
            "required": [
                "endpoint"
            ],
            "additionalProperties": false,
            "properties": {
                "endpoint": {
                    "description": "URL pointing to the REST service where the metrics will be sent.",
                    "type": "string"
                },
                "authentication": {
                    "description": "Basic authentication configuration.",
                    "type": "object",
                    "properties": {
                        "user": {
                            "description": "Username.",
                            "type": "string"
                        },
                        "password": {
                            "description": "Password.",
                            "type": "string"
                        }
                    }
                },
                "user-agent": {
                    "description": "Value for the `User-Agent` HTTP header.",
                    "type": "string"
                },
                "conflation": {
                    "description": "Settings for sending metrics in batches.",
                    "type": "object",
                    "properties": {
                        "max-size": {
                            "description": "The number of metrics to collect before sending them to the publisher.",
                            "type": "integer",
                            "default": 0
                        },
                        "interval": {
                            "description": "Interval in milliseconds at which to send the metrics batches.",
                            "type": "integer",
                            "default": 1000
                        }
                    }
                },
                "buffer-size": {
                    "description": "The number of metrics to store before starting to drop them (e.g., when publishing is slow).",
                    "type": "integer",
                    "default": 10000
                },
                "heartbeats": {
                    "description": "Interval in milliseconds at which status messages will be generated. Set to `-1` to disable heartbeats.",
                    "type": "integer",
                    "default": 1000
                },
                "worker": {
                    "type": "object",
                    "properties": {
                        "url": {
                            "type": "string"
                        },
                        "options": {
                            "type": "object"
                        }
                    }
                },
                "publishFn": {
                    "type": "string"
                }
            }
        },
        "KafkaMetricsPublisherConfig": {
            "title": "KafkaMetricsPublisherConfig",
            "description": "Metrics publisher that will send the data via Kafka.",
            "type": "object",
            "required": [
                "topic"
            ],
            "additionalProperties": false,
            "properties": {
                "topic": {
                    "description": "Kafka topic to which the metrics will be published.",
                    "type": "string"
                },
                "publisher-config": {
                    "description": "Kafka producer settings."
                },
                "conflation": {
                    "description": "Settings for sending metrics in batches.",
                    "type": "object",
                    "properties": {
                        "max-size": {
                            "description": "The number of metrics to collect before sending them to the publisher.",
                            "type": "integer",
                            "default": 0
                        },
                        "interval": {
                            "description": "Interval in milliseconds at which to send the metrics batches.",
                            "type": "integer",
                            "default": 1000
                        }
                    }
                },
                "buffer-size": {
                    "description": "The number of metrics to store before starting to drop them (e.g., when publishing is slow).",
                    "type": "integer",
                    "default": 10000
                },
                "heartbeats": {
                    "description": "Interval in milliseconds at which status messages will be generated. Set to `-1` to disable heartbeats.",
                    "type": "integer",
                    "default": 1000
                }
            }
        },
        "meshStaticMember": {
            "description": "",
            "type": "object",
            "properties": {
                "node": {
                    "description": "",
                    "type": "number"
                },
                "endpoint": {
                    "description": "",
                    "type": "string"
                }
            }
        }
    },
    "additionalProperties": false
}
