Commit 3da1bbd5 authored by Lukas Burgey's avatar Lukas Burgey

Add parameters to the stubscript.

This way is can e.g. be a script that always fails.
parent ae5f4826
module git.scc.kit.edu/feudal/feudalScripts/stubScript module git.scc.kit.edu/feudal/feudalScripts/stubScript
require git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0 require (
git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
gopkg.in/alecthomas/kingpin.v2 v2.2.6
)
go 1.13
git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0 h1:3907HJ9XEZSuEZ0oAuijssG9SGFjAdmyDt8P7SlFFZY= 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= git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0/go.mod h1:EVXrOHOlnw3VZ02LZQDSN7bxldpJ7p31tfKZ5zqAEXA=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
...@@ -9,7 +9,8 @@ import ( ...@@ -9,7 +9,8 @@ import (
"os" "os"
"time" "time"
"git.scc.kit.edu/feudal/feudalScripts/v2" scripts "git.scc.kit.edu/feudal/feudalScripts/v2"
"gopkg.in/alecthomas/kingpin.v2"
) )
const ( const (
...@@ -18,6 +19,20 @@ const ( ...@@ -18,6 +19,20 @@ const (
var ( var (
httpClient = &http.Client{} httpClient = &http.Client{}
app = kingpin.New(
"StubScript",
"Stubscript for evaluation. Takes parameters to change behavior",
).Author(
"Lukas Burgey",
).Version(
"v1.0.0",
)
cmdSucceed = app.Command("succeed", "All deployment requests succeed.").Default()
cmdFail = app.Command("fail", "All deployment requests fail.")
cmdReject = app.Command("reject", "All requests are rejected.")
cmdQuestionnare = app.Command("questionnaire", "All requests cause a questionnaire.")
command = ""
) )
func check(err error) { func check(err error) {
...@@ -29,7 +44,7 @@ func check(err error) { ...@@ -29,7 +44,7 @@ func check(err error) {
func deploy(input scripts.Input) (output scripts.Output, err error) { func deploy(input scripts.Input) (output scripts.Output, err error) {
time.Sleep(time.Second) time.Sleep(time.Second)
output.State = scripts.Deployed output.State = scripts.Deployed
output.Msg = "deployed" output.Msg = "Duty is done"
output.Credentials = map[string]string{ output.Credentials = map[string]string{
"password": "stub password", "password": "stub password",
"url": "stub.kit.de", "url": "stub.kit.de",
...@@ -37,10 +52,46 @@ func deploy(input scripts.Input) (output scripts.Output, err error) { ...@@ -37,10 +52,46 @@ func deploy(input scripts.Input) (output scripts.Output, err error) {
return return
} }
func withdraw(input scripts.Input) (output scripts.Output, err error) { func questionnaire(input scripts.Input) (output scripts.Output, err error) {
time.Sleep(time.Second)
if input.Answers != nil {
_, fooOK := input.Answers["Question-Foo"]
_, barOK := input.Answers["Question-Bar"]
if fooOK && barOK {
output.State = scripts.Deployed
output.Msg = "I got all the answers"
return
}
}
output.State = scripts.Questionnaire
output.Msg = "I need some answers"
output.Questionnaire = map[string]string{
"Question-Foo": "Description of question foo",
"Question-Bar": "Description of question bar",
}
return
}
func remove(input scripts.Input) (output scripts.Output, err error) {
time.Sleep(time.Second) time.Sleep(time.Second)
output.State = scripts.NotDeployed output.State = scripts.NotDeployed
output.Msg = "stub remove" output.Msg = "Removal complete"
return
}
func reject(input scripts.Input) (output scripts.Output, err error) {
time.Sleep(time.Second)
output.State = scripts.Rejected
output.Msg = "We don't like you!"
return
}
func fail(input scripts.Input) (output scripts.Output, err error) {
time.Sleep(time.Second)
output.State = scripts.Failed
output.Msg = "The server broke down. Sorry"
return return
} }
...@@ -57,9 +108,18 @@ func handleInput() (output scripts.Output, err error) { ...@@ -57,9 +108,18 @@ func handleInput() (output scripts.Output, err error) {
switch input.StateTarget { switch input.StateTarget {
case "deployed": case "deployed":
output, err = deploy(input) switch command {
case "succeed":
output, err = deploy(input)
case "fail":
output, err = fail(input)
case "reject":
output, err = reject(input)
case "questionnaire":
output, err = questionnaire(input)
}
case "not_deployed": case "not_deployed":
output, err = withdraw(input) output, err = remove(input)
default: default:
err = fmt.Errorf("Not implemented") err = fmt.Errorf("Not implemented")
} }
...@@ -67,6 +127,8 @@ func handleInput() (output scripts.Output, err error) { ...@@ -67,6 +127,8 @@ func handleInput() (output scripts.Output, err error) {
} }
func main() { func main() {
command = kingpin.MustParse(app.Parse(os.Args[1:]))
log.SetOutput(os.Stderr) log.SetOutput(os.Stderr)
output, err := handleInput() output, err := handleInput()
......
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