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:
Martin Atkins 2017-09-01 16:05:05 -07:00
parent 879899d434
commit 5c0670fdf4
3 changed files with 18 additions and 2 deletions

View File

@ -71,10 +71,11 @@ func (c *InitCommand) Run(args []string) int {
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 {
c.providerInstaller = &discovery.ProviderInstaller{
Dir: c.pluginDir(),
Dir: c.pluginDir(),
Cache: c.pluginCache(),
PluginProtocolVersion: plugin.Handshake.ProtocolVersion,
SkipVerify: !flagVerifyPlugins,
Ui: c.Ui,

View File

@ -55,6 +55,10 @@ type Meta struct {
// the specific commands being run.
RunningInAutomation bool
// PluginCacheDir, if non-empty, enables caching of downloaded plugins
// into the given directory.
PluginCacheDir string
//----------------------------------------------------------
// Protected: commands can set these
//----------------------------------------------------------

View File

@ -168,6 +168,17 @@ func (m *Meta) pluginDirs(includeAutoInstalled bool) []string {
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
// the defined search paths.
func (m *Meta) providerPluginSet() discovery.PluginMetaSet {