From 5c0670fdf48bdcabcc600116adcd669b9824e288 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 1 Sep 2017 16:05:05 -0700 Subject: [PATCH] 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. --- command/init.go | 5 +++-- command/meta.go | 4 ++++ command/plugins.go | 11 +++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/command/init.go b/command/init.go index 995ec6179..b81109ec2 100644 --- a/command/init.go +++ b/command/init.go @@ -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, diff --git a/command/meta.go b/command/meta.go index 8028c3fe6..4412929c7 100644 --- a/command/meta.go +++ b/command/meta.go @@ -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 //---------------------------------------------------------- diff --git a/command/plugins.go b/command/plugins.go index ce26b0f85..ba034a2a9 100644 --- a/command/plugins.go +++ b/command/plugins.go @@ -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 {