Commit 7616ff62 authored by Lukas Burgey's avatar Lukas Burgey

Rework README.md

parent 0e8d3ff0
FEUDAL Scripts
=
FEUDAL scripts are executed by a FEUDAL client to facilitate the customized deployment process
of an arbitrary service.
FEUDAL scripts are executed by a [feudalClient](https://git.scc.kit.edu/feudal/feudalClient) to facilitate the customized deployment process
of a service.
They use the JSON encoding for input and output. The specific formats are outlined below.
Schema files for [input](schema-input.json) and [output](schema-output.json) are also available.
The scripts use the JSON encoding for input and output. The specific formats are loosely outlined below.
The input is passed to the scripts via stdin.
The [feudalClient](https://git.scc.kit.edu/feudal/feudalClient) can be used to generate and validate JSON schema for input
and output, see:
```
feudalClient schema --help
feudalClient validate --help
```
Input Format
-
......@@ -15,26 +21,28 @@ Input Format
// The state which is to be reached by this script execution
//
// deployed -> the script is supposed to deploy the user
// not_deployed -> the script is supposed to remove the user
// not_deployed -> the script is supposed to remove the user
"state_target": "deployed" or "not_deployed",
// The user which is requesting access
"user": {
"userinfo": <OpenID Connect userinfo as json dict>
// The credentials from the user, which need to be deployed
// The dict maps a credential type to a list of credentials of this type.
"credentials": {
"ssh_key": [
{
"name": "unity_key",
"value": "ssh-... ..."
}
]
},
},
// The credentials from the user, which need to be deployed
// The dict maps a credential type to a list of credentials of this type.
"credentials": {
"ssh_key": [
{
"name": "unity_key",
"value": "ssh-... ..."
}
]
},
// Answers to a previously requested questionnaire
// Answers to a previously requested questionnaire, may not be present
"questionnaire": {
"question_name": "user answer to this question"
}
......@@ -54,17 +62,17 @@ Output Format
// rejected -> The user is not permitted to use this service, for whatever reason
// questionnaire-> The script needs more information to deploy the user
"state": "deployed" or "not_deployed" or "failed" or "rejected" or "questionnaire",
"message": "<message for the user, in case state is 'failed' or 'rejected'>",
// In case we need more info from the user: set state to "questionnaire" and put
"message": "<message for the user describing what happened. Must not be empty.",
// In case we need more info from the user: set state to "questionnaire" and put
// questions in this dictionary.
// The user can answer these questions (and we will receive the answers some input in the future)
// The user can answer these questions (and we will receive the answers some input in the future)
"questionnaire": {
"question_name": "question"
},
// additional credentials and instructions, the user needs to access the service (in addition to her credentials from the Input)
// an example would be the user name of the provisioned user.
"credentials": {
......
module git.scc.kit.edu/feudal/feudalScripts/sshScript
require git.scc.kit.edu/feudal/feudalScripts/v2 v2.0.0
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=
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"time"
scripts "git.scc.kit.edu/feudal/feudalScripts/v2"
)
const (
version = "0.1.0"
)
var (
httpClient = &http.Client{}
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func deploy(input scripts.Input) (output scripts.Output, err error) {
time.Sleep(time.Second)
output.State = scripts.Deployed
output.Msg = "deployed"
output.Credentials = map[string]string{
"ssh_user": "feudal",
"ssh_host": "ssh.stub.kit.de",
}
return
}
func withdraw(input scripts.Input) (output scripts.Output, err error) {
time.Sleep(time.Second)
output.State = scripts.NotDeployed
output.Msg = "stub remove"
return
}
func handleInput() (output scripts.Output, err error) {
inputBytes, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return
}
input, err := scripts.UnmarshalInput(inputBytes)
if err != nil {
return
}
switch input.StateTarget {
case "deployed":
output, err = deploy(input)
case "not_deployed":
output, err = withdraw(input)
default:
err = fmt.Errorf("Not implemented")
}
return
}
func main() {
log.SetOutput(os.Stderr)
output, err := handleInput()
if err != nil {
output = scripts.Output{
State: scripts.Failed,
Msg: fmt.Sprintf("%s", err),
}
}
outputBytes, err := json.MarshalIndent(output, "", " ")
fmt.Fprintf(os.Stdout, "%s", outputBytes)
}
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