-
Notifications
You must be signed in to change notification settings - Fork 43
/
metadata.go
72 lines (65 loc) · 1.88 KB
/
metadata.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
package proto
import "errors"
// GetMetadataRequest contains the parameters passed in a get-plugin-metadata
// request.
type GetMetadataRequest struct {
PluginConfig map[string]string `json:"pluginConfig,omitempty"`
}
func (GetMetadataRequest) Command() Command {
return CommandGetMetadata
}
// GetMetadataResponse provided by the plugin.
type GetMetadataResponse struct {
Name string `json:"name"`
Description string `json:"description"`
Version string `json:"version"`
URL string `json:"url"`
SupportedContractVersions []string `json:"supportedContractVersions"`
Capabilities []Capability `json:"capabilities"`
}
// Validate checks if the metadata is correctly populated.
func (resp *GetMetadataResponse) Validate() error {
if resp.Name == "" {
return errors.New("empty name")
}
if resp.Description == "" {
return errors.New("empty description")
}
if resp.Version == "" {
return errors.New("empty version")
}
if resp.URL == "" {
return errors.New("empty url")
}
if len(resp.Capabilities) == 0 {
return errors.New("empty capabilities")
}
if len(resp.SupportedContractVersions) == 0 {
return errors.New("empty supported contract versions")
}
return nil
}
// HasCapability return true if the metadata states that the
// capability is supported.
// Returns true if capability is empty.
func (resp *GetMetadataResponse) HasCapability(capability Capability) bool {
if capability == "" {
return true
}
for _, c := range resp.Capabilities {
if c == capability {
return true
}
}
return false
}
// SupportsContract return true if the metadata states that the
// contract version is supported.
func (resp *GetMetadataResponse) SupportsContract(ver string) bool {
for _, v := range resp.SupportedContractVersions {
if v == ver {
return true
}
}
return false
}