github.com/vieux/docker@v0.6.3-0.20161004191708-e097c2a938c7/api/types/plugin.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  // PluginInstallOptions holds parameters to install a plugin.
     9  type PluginInstallOptions struct {
    10  	Disabled              bool
    11  	AcceptAllPermissions  bool
    12  	RegistryAuth          string // RegistryAuth is the base64 encoded credentials for the registry
    13  	PrivilegeFunc         RequestPrivilegeFunc
    14  	AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
    15  }
    16  
    17  // PluginConfig represents the values of settings potentially modifiable by a user
    18  type PluginConfig struct {
    19  	Mounts  []PluginMount
    20  	Env     []string
    21  	Args    []string
    22  	Devices []PluginDevice
    23  }
    24  
    25  // Plugin represents a Docker plugin for the remote API
    26  type Plugin struct {
    27  	ID   string `json:"Id,omitempty"`
    28  	Name string
    29  	Tag  string
    30  	// Enabled is true when the plugin is running, is false when the plugin is not running, only installed.
    31  	Enabled  bool
    32  	Config   PluginConfig
    33  	Manifest PluginManifest
    34  }
    35  
    36  // PluginsListResponse contains the response for the remote API
    37  type PluginsListResponse []*Plugin
    38  
    39  const (
    40  	authzDriver   = "AuthzDriver"
    41  	graphDriver   = "GraphDriver"
    42  	ipamDriver    = "IpamDriver"
    43  	networkDriver = "NetworkDriver"
    44  	volumeDriver  = "VolumeDriver"
    45  )
    46  
    47  // PluginInterfaceType represents a type that a plugin implements.
    48  type PluginInterfaceType struct {
    49  	Prefix     string // This is always "docker"
    50  	Capability string // Capability should be validated against the above list.
    51  	Version    string // Plugin API version. Depends on the capability
    52  }
    53  
    54  // UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType
    55  func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error {
    56  	versionIndex := len(p)
    57  	prefixIndex := 0
    58  	if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' {
    59  		return fmt.Errorf("%q is not a plugin interface type", p)
    60  	}
    61  	p = p[1 : len(p)-1]
    62  loop:
    63  	for i, b := range p {
    64  		switch b {
    65  		case '.':
    66  			prefixIndex = i
    67  		case '/':
    68  			versionIndex = i
    69  			break loop
    70  		}
    71  	}
    72  	t.Prefix = string(p[:prefixIndex])
    73  	t.Capability = string(p[prefixIndex+1 : versionIndex])
    74  	if versionIndex < len(p) {
    75  		t.Version = string(p[versionIndex+1:])
    76  	}
    77  	return nil
    78  }
    79  
    80  // MarshalJSON implements json.Marshaler for PluginInterfaceType
    81  func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) {
    82  	return json.Marshal(t.String())
    83  }
    84  
    85  // String implements fmt.Stringer for PluginInterfaceType
    86  func (t PluginInterfaceType) String() string {
    87  	return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version)
    88  }
    89  
    90  // PluginInterface describes the interface between Docker and plugin
    91  type PluginInterface struct {
    92  	Types  []PluginInterfaceType
    93  	Socket string
    94  }
    95  
    96  // PluginSetting is to be embedded in other structs, if they are supposed to be
    97  // modifiable by the user.
    98  type PluginSetting struct {
    99  	Name        string
   100  	Description string
   101  	Settable    []string
   102  }
   103  
   104  // PluginNetwork represents the network configuration for a plugin
   105  type PluginNetwork struct {
   106  	Type string
   107  }
   108  
   109  // PluginMount represents the mount configuration for a plugin
   110  type PluginMount struct {
   111  	PluginSetting
   112  	Source      *string
   113  	Destination string
   114  	Type        string
   115  	Options     []string
   116  }
   117  
   118  // PluginEnv represents an environment variable for a plugin
   119  type PluginEnv struct {
   120  	PluginSetting
   121  	Value *string
   122  }
   123  
   124  // PluginArgs represents the command line arguments for a plugin
   125  type PluginArgs struct {
   126  	PluginSetting
   127  	Value []string
   128  }
   129  
   130  // PluginDevice represents a device for a plugin
   131  type PluginDevice struct {
   132  	PluginSetting
   133  	Path *string
   134  }
   135  
   136  // PluginUser represents the user for the plugin's process
   137  type PluginUser struct {
   138  	UID uint32 `json:"Uid,omitempty"`
   139  	GID uint32 `json:"Gid,omitempty"`
   140  }
   141  
   142  // PluginManifest represents the manifest of a plugin
   143  type PluginManifest struct {
   144  	ManifestVersion string
   145  	Description     string
   146  	Documentation   string
   147  	Interface       PluginInterface
   148  	Entrypoint      []string
   149  	Workdir         string
   150  	User            PluginUser `json:",omitempty"`
   151  	Network         PluginNetwork
   152  	Capabilities    []string
   153  	Mounts          []PluginMount
   154  	Devices         []PluginDevice
   155  	Env             []PluginEnv
   156  	Args            PluginArgs
   157  }
   158  
   159  // PluginPrivilege describes a permission the user has to accept
   160  // upon installing a plugin.
   161  type PluginPrivilege struct {
   162  	Name        string
   163  	Description string
   164  	Value       []string
   165  }
   166  
   167  // PluginPrivileges is a list of PluginPrivilege
   168  type PluginPrivileges []PluginPrivilege