Commit b7e52630 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Add json schema generation

parent e83f996d
......@@ -2,8 +2,10 @@ module git.scc.kit.edu/feudal/feudalClient
require (
git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0
github.com/alecthomas/jsonschema v0.0.0-20190122210438-a6952de1bbe6
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/streadway/amqp v0.0.0-20181205114330-a314942b2fd9
github.com/stretchr/testify v1.3.0 // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
......
git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0 h1:3907HJ9XEZSuEZ0oAuijssG9SGFjAdmyDt8P7SlFFZY=
git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0/go.mod h1:EVXrOHOlnw3VZ02LZQDSN7bxldpJ7p31tfKZ5zqAEXA=
github.com/alecthomas/jsonschema v0.0.0-20190122210438-a6952de1bbe6 h1:xadBCbc8D9mmkaNfCsEBHbIoCjbayJXJNsY1JjPjNio=
github.com/alecthomas/jsonschema v0.0.0-20190122210438-a6952de1bbe6/go.mod h1:qpebaTNSsyUn5rPSJMsfqEtDw71TTggXM6stUDI16HA=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/streadway/amqp v0.0.0-20181205114330-a314942b2fd9 h1:37QTz/gdHBLQcsmgMTnQDSWCtKzJ7YnfI2M2yTdr4BQ=
......
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"git.scc.kit.edu/feudal/feudalClient/config"
"git.scc.kit.edu/feudal/feudalClient/deployments"
deps "git.scc.kit.edu/feudal/feudalClient/deployments"
"git.scc.kit.edu/feudal/feudalClient/sink"
"git.scc.kit.edu/feudal/feudalClient/sink/script"
"git.scc.kit.edu/feudal/feudalClient/source"
"git.scc.kit.edu/feudal/feudalClient/source/amqp"
"git.scc.kit.edu/feudal/feudalClient/source/rest"
"gopkg.in/alecthomas/kingpin.v2"
scripts "git.scc.kit.edu/feudal/feudalScripts/v2"
"github.com/alecthomas/jsonschema"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
......@@ -23,12 +27,14 @@ var (
).Author(
"Lukas Burgey",
).Version(
"v2.0.1",
"v2.1.0",
)
cmdStart = app.Command("start", "Starts the client in its normal operation mode.").Default()
cmdDeregister = app.Command("deregister", "Before disabling the client: Use deregister to inform the backend that the client ceases operation.")
cmdStart = app.Command("start", "Starts the client in its normal operation mode.").Default()
cmdDeregister = app.Command("deregister", "Before disabling the client: Use deregister to inform the backend that the client ceases operation.")
cmdSchema = app.Command("schema", "Can be used to generate JSON schemas (Draft 4, see json-schema.org) for the validation of script inputs and outputs.")
schemaSelector = cmdSchema.Arg("selector", "Select the schema to generate.").Required().Enum("input", "output", "config")
configFile = app.Flag("config", "Config file to file to use.").Short('c').Required().String()
configFile = app.Flag("config", "Config file to use.").Short('c').String()
scriptDebugging = app.Flag("debug-scripts", "Display debugging info concerning executed scripts").Bool()
backendDebugging = app.Flag("debug-backend", "Display debugging info concerning the backend").Bool()
debugAll = app.Flag("debug", "Display all debugging info").Bool()
......@@ -106,13 +112,39 @@ func start(conf *config.Config) {
}
}
func printSchema(i interface{}) {
schema := jsonschema.Reflect(i)
bs, err := json.MarshalIndent(schema, "", " ")
if err != nil {
panic(err)
}
fmt.Printf("%s", bs)
}
func main() {
var err error
// get arguments
cmd := kingpin.MustParse(app.Parse(os.Args[1:]))
// Do things that need no config or debugging
switch cmd {
case "schema":
switch *schemaSelector {
case "input":
printSchema(scripts.Input{})
case "output":
printSchema(scripts.Output{})
case "config":
printSchema(config.Config{})
}
return
}
// read the config file
if *configFile == "" {
log.Fatalf("No config file. Unable to proceed. Provide the --config flag")
}
conf, err := config.ReadConfig(*configFile)
if err != nil {
log.Fatalf("[Conf] %s", err)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment