This repository was archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathplugin.go
119 lines (102 loc) · 2.43 KB
/
plugin.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package models
// Plugin represents a single instance of a running plugin.
// This contains the configuration need to start this plugin instance.
// swagger:model
type Plugin struct {
Validation
Access
Meta
Owned
Bundled
Partialed
// The name of the plugin instance. THis must be unique across all
// plugins.
//
// required: true
Name string `index:",key"`
// A description of this plugin. This can contain any reference
// information for humans you want associated with the plugin.
Description string
// Documentation of this plugin. This should tell what
// the plugin is for, any special considerations that
// should be taken into account when using it, etc. in rich structured text (rst).
Documentation string
// Any additional parameters that may be needed to configure
// the plugin.
Params map[string]interface{}
// The plugin provider for this plugin
//
// required: true
Provider string
// Error unrelated to the object validity, but the execution
// of the plugin.
PluginErrors []string
}
func (p *Plugin) GetMeta() Meta {
return p.Meta
}
func (p *Plugin) SetMeta(d Meta) {
p.Meta = d
}
func (p *Plugin) GetDocumentation() string {
return p.Documentation
}
func (p *Plugin) GetDescription() string {
return p.Description
}
func (p *Plugin) Validate() {
p.AddError(ValidName("Invalid Name", p.Name))
p.AddError(ValidName("Invalid Provider", p.Provider))
for k := range p.Params {
p.AddError(ValidParamName("Invalid Param Name", k))
}
}
func (p *Plugin) SetName(s string) {
p.Name = s
}
func (n *Plugin) Prefix() string {
return "plugins"
}
func (n *Plugin) Key() string {
return n.Name
}
func (n *Plugin) KeyName() string {
return "Name"
}
func (n *Plugin) Fill() {
if n.Meta == nil {
n.Meta = Meta{}
}
n.Validation.fill(n)
if n.Params == nil {
n.Params = map[string]interface{}{}
}
if n.PluginErrors == nil {
n.PluginErrors = []string{}
}
}
func (n *Plugin) AuthKey() string {
return n.Key()
}
func (p *Plugin) SliceOf() interface{} {
s := []*Plugin{}
return &s
}
func (p *Plugin) ToModels(obj interface{}) []Model {
items := obj.(*[]*Plugin)
res := make([]Model, len(*items))
for i, item := range *items {
res[i] = Model(item)
}
return res
}
// match Paramer interface
func (p *Plugin) GetParams() map[string]interface{} {
return copyMap(p.Params)
}
func (p *Plugin) SetParams(pl map[string]interface{}) {
p.Params = copyMap(pl)
}
func (p *Plugin) CanHaveActions() bool {
return true
}