2018-02-05 21:05:59 +00:00
|
|
|
package types // import "github.com/docker/docker/api/types"
|
2016-10-05 20:25:09 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2016-12-28 03:38:13 +00:00
|
|
|
"sort"
|
2016-10-05 20:25:09 +00:00
|
|
|
)
|
|
|
|
|
2016-11-15 19:45:20 +00:00
|
|
|
// PluginsListResponse contains the response for the Engine API
|
2016-10-05 20:25:09 +00:00
|
|
|
type PluginsListResponse []*Plugin
|
|
|
|
|
|
|
|
// UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType
|
|
|
|
func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error {
|
|
|
|
versionIndex := len(p)
|
|
|
|
prefixIndex := 0
|
|
|
|
if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' {
|
|
|
|
return fmt.Errorf("%q is not a plugin interface type", p)
|
|
|
|
}
|
|
|
|
p = p[1 : len(p)-1]
|
|
|
|
loop:
|
|
|
|
for i, b := range p {
|
|
|
|
switch b {
|
|
|
|
case '.':
|
|
|
|
prefixIndex = i
|
|
|
|
case '/':
|
|
|
|
versionIndex = i
|
|
|
|
break loop
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.Prefix = string(p[:prefixIndex])
|
|
|
|
t.Capability = string(p[prefixIndex+1 : versionIndex])
|
|
|
|
if versionIndex < len(p) {
|
|
|
|
t.Version = string(p[versionIndex+1:])
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalJSON implements json.Marshaler for PluginInterfaceType
|
|
|
|
func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) {
|
|
|
|
return json.Marshal(t.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
// String implements fmt.Stringer for PluginInterfaceType
|
|
|
|
func (t PluginInterfaceType) String() string {
|
|
|
|
return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version)
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginPrivilege describes a permission the user has to accept
|
|
|
|
// upon installing a plugin.
|
|
|
|
type PluginPrivilege struct {
|
|
|
|
Name string
|
|
|
|
Description string
|
|
|
|
Value []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// PluginPrivileges is a list of PluginPrivilege
|
|
|
|
type PluginPrivileges []PluginPrivilege
|
2016-12-28 03:38:13 +00:00
|
|
|
|
|
|
|
func (s PluginPrivileges) Len() int {
|
|
|
|
return len(s)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s PluginPrivileges) Less(i, j int) bool {
|
|
|
|
return s[i].Name < s[j].Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s PluginPrivileges) Swap(i, j int) {
|
|
|
|
sort.Strings(s[i].Value)
|
|
|
|
sort.Strings(s[j].Value)
|
|
|
|
s[i], s[j] = s[j], s[i]
|
|
|
|
}
|