github.com/fabiokung/docker@v0.11.2-0.20170222101415-4534dcd49497/api/types/plugin_responses.go (about) 1 package types 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "sort" 7 ) 8 9 // PluginsListResponse contains the response for the Engine API 10 type PluginsListResponse []*Plugin 11 12 const ( 13 authzDriver = "AuthzDriver" 14 graphDriver = "GraphDriver" 15 ipamDriver = "IpamDriver" 16 networkDriver = "NetworkDriver" 17 volumeDriver = "VolumeDriver" 18 ) 19 20 // UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType 21 func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error { 22 versionIndex := len(p) 23 prefixIndex := 0 24 if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' { 25 return fmt.Errorf("%q is not a plugin interface type", p) 26 } 27 p = p[1 : len(p)-1] 28 loop: 29 for i, b := range p { 30 switch b { 31 case '.': 32 prefixIndex = i 33 case '/': 34 versionIndex = i 35 break loop 36 } 37 } 38 t.Prefix = string(p[:prefixIndex]) 39 t.Capability = string(p[prefixIndex+1 : versionIndex]) 40 if versionIndex < len(p) { 41 t.Version = string(p[versionIndex+1:]) 42 } 43 return nil 44 } 45 46 // MarshalJSON implements json.Marshaler for PluginInterfaceType 47 func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) { 48 return json.Marshal(t.String()) 49 } 50 51 // String implements fmt.Stringer for PluginInterfaceType 52 func (t PluginInterfaceType) String() string { 53 return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version) 54 } 55 56 // PluginPrivilege describes a permission the user has to accept 57 // upon installing a plugin. 58 type PluginPrivilege struct { 59 Name string 60 Description string 61 Value []string 62 } 63 64 // PluginPrivileges is a list of PluginPrivilege 65 type PluginPrivileges []PluginPrivilege 66 67 func (s PluginPrivileges) Len() int { 68 return len(s) 69 } 70 71 func (s PluginPrivileges) Less(i, j int) bool { 72 return s[i].Name < s[j].Name 73 } 74 75 func (s PluginPrivileges) Swap(i, j int) { 76 sort.Strings(s[i].Value) 77 sort.Strings(s[j].Value) 78 s[i], s[j] = s[j], s[i] 79 }