deployments.go 2.53 KB
Newer Older
Lukas Burgey's avatar
Lukas Burgey committed
1
2
3
4
5
6
7
package deps

import (
	"fmt"
	"log"

	"git.scc.kit.edu/feudal/feudalClient/config"
Lukas Burgey's avatar
Lukas Burgey committed
8
	"git.scc.kit.edu/feudal/feudalScripts/v2"
Lukas Burgey's avatar
Lukas Burgey committed
9
10
11
12
13
14
15
16
17
18
)

type (
	// VO virtual organisation
	VO struct {
		ID           int    `json:"id"`
		Name         string `json:"name"`
		ResourceType string `json:"resourcetype"`
	}

19
	// Dep now relates to a DeploymentState at the backend
Lukas Burgey's avatar
Lukas Burgey committed
20
	Dep struct {
21
22
		// ID is the db primary key of th DeploymentState instance at the backend.
		ID int `json:"id"`
Lukas Burgey's avatar
Lukas Burgey committed
23

24
25
26
27
28
		// The StateTarget of the DeploymentState parent Deployment.
		StateTarget scripts.State `json:"state_target"`

		// The user for which we are supposed to deploy access.
		User scripts.User `json:"user"`
Lukas Burgey's avatar
Lukas Burgey committed
29

30
31
		// The Service which this Dep is related to.
		Service config.Service `json:"service"`
Lukas Burgey's avatar
Lukas Burgey committed
32

33
34
		// Optional Answers by the users. Must have the same keys as the related Questionnaire
		Answers map[string]string `json:"answers,omitempty"`
Lukas Burgey's avatar
Lukas Burgey committed
35
36
	}

37
	// Reply is used to patch the fields of the DeploymentState
Lukas Burgey's avatar
Lukas Burgey committed
38
	Reply struct {
39
40
		// ID is the db primary key of the DeploymentState instance at the backend.
		ID int `json:"id"`
Lukas Burgey's avatar
Lukas Burgey committed
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
		// 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 scripts.State `json:"state"`

		// 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,omitempty"`

		// Credentials for the user
		// Ignored when State is not Deployed
		// Maps a credential name to a credential value
		Credentials map[string]string `json:"credentials,omitempty"`

		// UserCredentialStates are the State s of the credentials found in Input.User.Credentials.
		UserCredentialStates scripts.UserCredentialStates `json:"credential_states,omitempty"`
Lukas Burgey's avatar
Lukas Burgey committed
62
63
64
65
	}
)

func (dep Dep) String() string {
Lukas Burgey's avatar
Lukas Burgey committed
66
67
68
69
	if dep.Service != (config.Service{}) {
		return fmt.Sprintf("Dep[%v]#%v", dep.Service.Name, dep.ID)
	}
	return fmt.Sprintf("Dep#%v", dep.ID)
Lukas Burgey's avatar
Lukas Burgey committed
70
71
72
73
74
75
76
77
}

// Log logs a message for a Dep
func (dep Dep) Log(formatString string, params ...interface{}) {
	log.Printf("%s "+formatString, append([]interface{}{dep}, params...)...)
}

func (rep Reply) String() string {
78
	return fmt.Sprintf("Rep[%s]#%v]", rep.State, rep.ID)
Lukas Burgey's avatar
Lukas Burgey committed
79
80
81
82
83
84
}

// Log logs a message for a Reply
func (rep Reply) Log(formatString string, params ...interface{}) {
	log.Printf("%s "+formatString, append([]interface{}{rep}, params...)...)
}