plugin_responses.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package types
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. )
  6. // PluginsListResponse contains the response for the Engine API
  7. type PluginsListResponse []*Plugin
  8. const (
  9. authzDriver = "AuthzDriver"
  10. graphDriver = "GraphDriver"
  11. ipamDriver = "IpamDriver"
  12. networkDriver = "NetworkDriver"
  13. volumeDriver = "VolumeDriver"
  14. )
  15. // UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType
  16. func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error {
  17. versionIndex := len(p)
  18. prefixIndex := 0
  19. if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' {
  20. return fmt.Errorf("%q is not a plugin interface type", p)
  21. }
  22. p = p[1 : len(p)-1]
  23. loop:
  24. for i, b := range p {
  25. switch b {
  26. case '.':
  27. prefixIndex = i
  28. case '/':
  29. versionIndex = i
  30. break loop
  31. }
  32. }
  33. t.Prefix = string(p[:prefixIndex])
  34. t.Capability = string(p[prefixIndex+1 : versionIndex])
  35. if versionIndex < len(p) {
  36. t.Version = string(p[versionIndex+1:])
  37. }
  38. return nil
  39. }
  40. // MarshalJSON implements json.Marshaler for PluginInterfaceType
  41. func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) {
  42. return json.Marshal(t.String())
  43. }
  44. // String implements fmt.Stringer for PluginInterfaceType
  45. func (t PluginInterfaceType) String() string {
  46. return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version)
  47. }
  48. // PluginPrivilege describes a permission the user has to accept
  49. // upon installing a plugin.
  50. type PluginPrivilege struct {
  51. Name string
  52. Description string
  53. Value []string
  54. }
  55. // PluginPrivileges is a list of PluginPrivilege
  56. type PluginPrivileges []PluginPrivilege