Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
feudal
feudalScripts
Commits
3da1bbd5
Commit
3da1bbd5
authored
Jan 23, 2020
by
Lukas Burgey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parameters to the stubscript.
This way is can e.g. be a script that always fails.
parent
ae5f4826
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
93 additions
and
7 deletions
+93
-7
stubScript/go.mod
stubScript/go.mod
+8
-1
stubScript/go.sum
stubScript/go.sum
+17
-0
stubScript/stub-script.go
stubScript/stub-script.go
+68
-6
No files found.
stubScript/go.mod
View file @
3da1bbd5
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
stubScript/go.sum
View file @
3da1bbd5
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/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=
stubScript/stub-script.go
View file @
3da1bbd5
...
...
@@ -9,7 +9,8 @@ import (
"os"
"time"
"git.scc.kit.edu/feudal/feudalScripts/v2"
scripts
"git.scc.kit.edu/feudal/feudalScripts/v2"
"gopkg.in/alecthomas/kingpin.v2"
)
const
(
...
...
@@ -18,6 +19,20 @@ const (
var
(
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
)
{
...
...
@@ -29,7 +44,7 @@ func check(err error) {
func
deploy
(
input
scripts
.
Input
)
(
output
scripts
.
Output
,
err
error
)
{
time
.
Sleep
(
time
.
Second
)
output
.
State
=
scripts
.
Deployed
output
.
Msg
=
"
deployed
"
output
.
Msg
=
"
Duty is done
"
output
.
Credentials
=
map
[
string
]
string
{
"password"
:
"stub password"
,
"url"
:
"stub.kit.de"
,
...
...
@@ -37,10 +52,46 @@ func deploy(input scripts.Input) (output scripts.Output, err error) {
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
)
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
}
...
...
@@ -57,9 +108,18 @@ func handleInput() (output scripts.Output, err error) {
switch
input
.
StateTarget
{
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"
:
output
,
err
=
withdraw
(
input
)
output
,
err
=
remove
(
input
)
default
:
err
=
fmt
.
Errorf
(
"Not implemented"
)
}
...
...
@@ -67,6 +127,8 @@ func handleInput() (output scripts.Output, err error) {
}
func
main
()
{
command
=
kingpin
.
MustParse
(
app
.
Parse
(
os
.
Args
[
1
:
]))
log
.
SetOutput
(
os
.
Stderr
)
output
,
err
:=
handleInput
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment