command: allow callers to activate a plugin cache
Here we add a new caller-settable field to command.Meta that activates a read-through cache directory for plugin installation.
This commit is contained in:
parent
879899d434
commit
5c0670fdf4
|
@ -71,10 +71,11 @@ func (c *InitCommand) Run(args []string) int {
|
||||||
c.getPlugins = false
|
c.getPlugins = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// set getProvider if we don't have a test version already
|
// set providerInstaller if we don't have a test version already
|
||||||
if c.providerInstaller == nil {
|
if c.providerInstaller == nil {
|
||||||
c.providerInstaller = &discovery.ProviderInstaller{
|
c.providerInstaller = &discovery.ProviderInstaller{
|
||||||
Dir: c.pluginDir(),
|
Dir: c.pluginDir(),
|
||||||
|
Cache: c.pluginCache(),
|
||||||
PluginProtocolVersion: plugin.Handshake.ProtocolVersion,
|
PluginProtocolVersion: plugin.Handshake.ProtocolVersion,
|
||||||
SkipVerify: !flagVerifyPlugins,
|
SkipVerify: !flagVerifyPlugins,
|
||||||
Ui: c.Ui,
|
Ui: c.Ui,
|
||||||
|
|
|
@ -55,6 +55,10 @@ type Meta struct {
|
||||||
// the specific commands being run.
|
// the specific commands being run.
|
||||||
RunningInAutomation bool
|
RunningInAutomation bool
|
||||||
|
|
||||||
|
// PluginCacheDir, if non-empty, enables caching of downloaded plugins
|
||||||
|
// into the given directory.
|
||||||
|
PluginCacheDir string
|
||||||
|
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
// Protected: commands can set these
|
// Protected: commands can set these
|
||||||
//----------------------------------------------------------
|
//----------------------------------------------------------
|
||||||
|
|
|
@ -168,6 +168,17 @@ func (m *Meta) pluginDirs(includeAutoInstalled bool) []string {
|
||||||
return dirs
|
return dirs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Meta) pluginCache() discovery.PluginCache {
|
||||||
|
dir := m.PluginCacheDir
|
||||||
|
if dir == "" {
|
||||||
|
return nil // cache disabled
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = filepath.Join(dir, pluginMachineName)
|
||||||
|
|
||||||
|
return discovery.NewLocalPluginCache(dir)
|
||||||
|
}
|
||||||
|
|
||||||
// providerPluginSet returns the set of valid providers that were discovered in
|
// providerPluginSet returns the set of valid providers that were discovered in
|
||||||
// the defined search paths.
|
// the defined search paths.
|
||||||
func (m *Meta) providerPluginSet() discovery.PluginMetaSet {
|
func (m *Meta) providerPluginSet() discovery.PluginMetaSet {
|
||||||
|
|
Loading…
Reference in New Issue