Skip to content

Commit

Permalink
feat: Added JSON schema for YAML config; fix naming
Browse files Browse the repository at this point in the history
Signed-off-by: Stuart Carnie <stuart.carnie@gmail.com>
  • Loading branch information
stuartcarnie committed Jun 13, 2020
1 parent c433f54 commit 94c5cd9
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 39 deletions.
179 changes: 179 additions & 0 deletions gopm-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "gopm config schema",
"type": "object",
"properties": {
"grpc_server": {
"type": "object",
"required": ["address"],
"properties": {
"address": {
"type": "string"
}
}
},
"http_server": {
"type": "object",
"required": ["port"],
"properties": {
"port": {
"type": "string"
}
}
},
"programs": {
"type": "array",
"items": {
"$ref": "#/definitions/Program"
}
},
"file_system": {
"type": "object",
"required": ["root"],
"properties": {
"root": {
"type": "string"
},
"files": {
"type": "array",
"items": {
"$ref": "#/definitions/File"
}
}
}
}
},
"definitions": {
"Program": {
"type": "object",
"required": ["name", "command"],
"properties": {
"name": {
"type": "string",
"pattern": "^\\w+$"
},
"directory": {
"type": "string"
},
"command": {
"type": "string"
},
"environment": {
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^\\w+$": {"type": "string"}
}
},
"user": {
"type": "string"
},
"exit_codes": {
"type": "array",
"items": {
"type": "integer",
"minimum": 0,
"maximum": 255
}
},
"priority": {
"type": "integer"
},
"restart_pause": {
"type": "integer"
},
"start_retries": {
"type": "integer",
"minimum": 0
},
"start_seconds": {
"type": "integer"
},
"cron": {
"type": "string"
},
"auto_start": {
"type": "boolean"
},
"auto_restart": {
"type": "boolean"
},
"restart_directory_monitor": {
"description": "Path to a directory to monitor and automatically restart the process if changes are detected",
"type": "string"
},
"restart_file_pattern": {
"description": "A pattern used to monitor a path and automatically restart the process if changes are detected",
"type": "string"
},
"restart_when_binary_changed": {
"description": "Automatically restart the process if changes to the binary are detected",
"type": "boolean"
},
"stop_signals": {
"type": "array",
"items": {
"type": "string",
"uniqueItems": true,
"enum": ["HUP", "INT", "QUIT", "KILL", "TERM", "USR1", "USR2"]
}
},
"stop_wait_seconds": {
"description": "The number of seconds to wait for the process to stop before killing",
"type": "integer"
},
"stop_as_group": {
"type": "boolean"
},
"kill_as_group": {
"type": "boolean"
},
"stdout_logfile": {
"type": "string"
},
"stdout_logfile_backups": {
"type": "integer"
},
"stdout_logfile_max_bytes": {
"type": "integer"
},
"redirect_stderr": {
"description": "Redirect STDERR to STDOUT",
"type": "boolean"
},
"stderr_logfile": {
"type": "string"
},
"stderr_logfile_backups": {
"type": "integer"
},
"stderr_logfile_max_bytes": {
"type": "integer"
},
"depends_on": {
"description": "A list of process names that must be started before starting this process",
"type": "array",
"items": {
"type": "string"
}
}
}
},
"File": {
"type": "object",
"required": ["name", "path", "content"],
"properties": {
"name": {
"type": "string",
"pattern": "^\\w+$"
},
"path": {
"type": "string"
},
"content": {
"type": "string"
}
}
}
}
}
2 changes: 0 additions & 2 deletions model/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package model
import "github.com/creasty/defaults"

type Program struct {
Group string `yaml:"-"`

Name string `yaml:"name"`
Directory string `yaml:"directory"`
Command string `yaml:"command"`
Expand Down
7 changes: 7 additions & 0 deletions model/visitor_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func (v *validator) Err() error {
func (v *validator) Visit(node Node) Visitor {
switch n := node.(type) {
case *HTTPServer:
if len(n.Port) == 0 {
multierr.AppendInto(&v.err, errors.New("http_server port missing"))
}
case *GrpcServer:
if len(n.Address) == 0 {
multierr.AppendInto(&v.err, errors.New("grpc_server address missing"))
}

case *Program:
if len(n.Name) == 0 {
Expand Down
Loading

0 comments on commit 94c5cd9

Please sign in to comment.