/
types.go
93 lines (77 loc) · 1.91 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package template
import (
"encoding/gob"
"github.com/ovh/cds/sdk/plugin"
"github.com/ovh/cds/sdk"
)
func init() {
gob.Register(ApplyOptions{})
gob.Register(Parameters{})
gob.Register(sdk.Application{})
gob.Register(sdk.TemplateParam{})
}
//Interface is the interface for template extensions
type Interface interface {
Init(plugin.IOptions) string
Name() string
Description() string
Identifier() string
Author() string
Type() string
Parameters() []sdk.TemplateParam
ActionsNeeded() []string
Apply(opts IApplyOptions) (sdk.Application, error)
}
//MapVar is an interface for map[string]string
type MapVar interface {
All() map[string]string
Get(string) string
}
//Parameters represents the parameters map expected bu the template
type Parameters struct {
Data map[string]string
}
//IApplyOptions represents interface for Apply func arg
type IApplyOptions interface {
ProjetKey() string
ApplicationName() string
Parameters() MapVar
}
//ApplyOptions represents struct for Apply func arg
type ApplyOptions struct {
ProjKey string
AppName string
Params MapVar
}
//NewApplyOptions instanciate a ApplyOptions struct
func NewApplyOptions(proj, app string, params Parameters) ApplyOptions {
return ApplyOptions{
ProjKey: proj,
AppName: app,
Params: params,
}
}
//ProjetKey returns the project key
func (o ApplyOptions) ProjetKey() string {
return o.ProjKey
}
//ApplicationName returns the application name
func (o ApplyOptions) ApplicationName() string {
return o.AppName
}
//Parameters returns the list of parameters
func (o ApplyOptions) Parameters() MapVar {
return o.Params
}
//NewParameters instanciates a parameters struct
func NewParameters(d map[string]string) *Parameters {
return &Parameters{Data: d}
}
//All returns the map
func (d Parameters) All() map[string]string {
return d.Data
}
//Get returns the value in the map for the key k
func (d Parameters) Get(k string) string {
return d.Data[k]
}