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

Move scripts to separate repository

parent 78d82748
package scripts
import (
type (
// SSHKey of a user
SSHKey struct {
Name string `json:"name"`
Key string `json:"key"`
// Group a group of which User is a member of
Group struct {
Name string `json:"name"`
// UserInfo info about the user
UserInfo map[string]interface{}
// User describes the user info
User struct {
// TODO maybe just handover the raw userinfo
Email string `json:"email"`
// TODO maybe just handover the raw userinfo
Groups []Group `json:"groups"`
UserInfo UserInfo `json:"userinfo"`
// Input of the deployment script
Input struct {
// StateTarget is the state which is to be reached by this deployment task
// StateTarget is either Deployed or NotDeployed
StateTarget State `json:"state_target"`
// User describes the user of this deployment task
User User `json:"user"`
// Key contains the ssh key of this deployment task
Key SSHKey `json:"key"`
// Questionnaire is an answered questionnaire
// Maps a question name to the answer of the user
// The keys (question names) *must* be identical to those of the Output.Questionnaire
// containing the questions
Questionnaire map[string]string `json:"questionnaire"`
// Output of the deployment script
Output struct {
// State of the deployment, after the script execution
// when State == Questionnaire then Output.Questionnaire *must* be set
// when State == Deployed then Output.Credentials *can* be set
State State `json:"state"`
// TODO use this correctly
// Message for the user
Msg string `json:"message"`
// Questionnaire requested by the script
// Ignored when State is not Questionnaire
// Maps a question name to a description of the question
Questionnaire map[string]string `json:"questionnaire"`
// Credentials for the user
// Ignored when State is not Deployed
// Maps a credential name to a credential value
Credentials map[string]string `json:"credentials"`
// State is a string enum
// The enum values for State are listed below
State string
const (
// Deployed value for State
Deployed State = "deployed"
// NotDeployed value for State
NotDeployed State = "not_deployed"
// Rejected value for State
// the user can never be deployed
Rejected State = "rejected"
// Failed value for State
// the deployment can be retried
Failed State = "failed"
// Questionnaire value for State
// the user has to fill the questionnaire
// with the questionnaire data the deployment can be retried
Questionnaire State = "questionnaire"
func (u User) String() string {
return u.Email
func (k SSHKey) String() string {
return k.Name
func (i Input) String() string {
iBytes, err := i.Marshal()
if err != nil {
return string(iBytes)
func (o Output) String() string {
oBytes, err := o.Marshal()
if err != nil {
return string(oBytes)
// Marshal encodes an Input as json
func (i Input) Marshal() (iBytes []byte, err error) {
iBytes, err = json.MarshalIndent(i, "", " ")
// Marshal encodes an Output as json
func (o Output) Marshal() (oBytes []byte, err error) {
oBytes, err = json.MarshalIndent(o, "", " ")
// UnmarshalInput decodes a json encoded input
func UnmarshalInput(inputBytes []byte) (i Input, err error) {
err = json.Unmarshal(inputBytes, &i)
// UnmarshalOutput decodes a json encoded output
func UnmarshalOutput(inputBytes []byte) (i Output, err error) {
err = json.Unmarshal(inputBytes, &i)
......@@ -11,7 +11,7 @@ import (
s ""
type (
......@@ -27,9 +27,9 @@ type (
task struct {
ID int `json:"id"`
StateTarget string `json:"state_target"`
User scripts.User `json:"user"`
Key scripts.SSHKey `json:"key"`
StateTarget s.State `json:"state_target"`
User s.User `json:"user"`
Key s.SSHKey `json:"key"`
Questionnaire map[string]string `json:"questionnaire"`
Group group `json:"group"`
......@@ -43,8 +43,8 @@ type (
taskExecution struct {
// ID of the according task (at the backend: DeploymentState)
ID int `json:"id"`
Output scripts.Output `json:"output"`
ID int `json:"id"`
Output s.Output `json:"output"`
// we need to inform the backend for which service we deployed
Service service `json:"service"`
......@@ -149,8 +149,8 @@ func (c *config) taskHandler() {
log.Printf("[Task] Error handling task: %s", err)
c.DoneTasks <- taskExecution{
ID: t.ID,
Output: scripts.Output{
Status: scripts.Failed,
Output: s.Output{
State: s.Failed,
// TODO maybe another message for the user
Msg: fmt.Sprint(err),
......@@ -255,10 +255,10 @@ func (c *config) scheduleTask(ti task) (err error) {
func (c *config) handleTask(ti task) (err error) {
var output scripts.Output
var output s.Output
// encode input as json
input := scripts.Input{
input := s.Input{
StateTarget: ti.StateTarget,
User: ti.User,
Key: ti.Key,
Supports Markdown
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