github.com/devdivbcp/moby@v17.12.0-ce-rc1.0.20200726071732-2d4bfdc789ad+incompatible/plugin/defs.go (about) 1 package plugin // import "github.com/docker/docker/plugin" 2 3 import ( 4 "sync" 5 6 "github.com/docker/docker/pkg/plugins" 7 "github.com/docker/docker/plugin/v2" 8 "github.com/opencontainers/runtime-spec/specs-go" 9 ) 10 11 // Store manages the plugin inventory in memory and on-disk 12 type Store struct { 13 sync.RWMutex 14 plugins map[string]*v2.Plugin 15 specOpts map[string][]SpecOpt 16 /* handlers are necessary for transition path of legacy plugins 17 * to the new model. Legacy plugins use Handle() for registering an 18 * activation callback.*/ 19 handlers map[string][]func(string, *plugins.Client) 20 } 21 22 // NewStore creates a Store. 23 func NewStore() *Store { 24 return &Store{ 25 plugins: make(map[string]*v2.Plugin), 26 specOpts: make(map[string][]SpecOpt), 27 handlers: make(map[string][]func(string, *plugins.Client)), 28 } 29 } 30 31 // SpecOpt is used for subsystems that need to modify the runtime spec of a plugin 32 type SpecOpt func(*specs.Spec) 33 34 // CreateOpt is used to configure specific plugin details when created 35 type CreateOpt func(p *v2.Plugin) 36 37 // WithSwarmService is a CreateOpt that flags the passed in a plugin as a plugin 38 // managed by swarm 39 func WithSwarmService(id string) CreateOpt { 40 return func(p *v2.Plugin) { 41 p.SwarmServiceID = id 42 } 43 } 44 45 // WithSpecMounts is a SpecOpt which appends the provided mounts to the runtime spec 46 func WithSpecMounts(mounts []specs.Mount) SpecOpt { 47 return func(s *specs.Spec) { 48 s.Mounts = append(s.Mounts, mounts...) 49 } 50 }