mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
b40a4fb741
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package discovery
|
|
|
|
// PluginCache is an interface implemented by objects that are able to maintain
|
|
// a cache of plugins.
|
|
type PluginCache interface {
|
|
// CachedPluginPath returns a path where the requested plugin is already
|
|
// cached, or an empty string if the requested plugin is not yet cached.
|
|
CachedPluginPath(kind string, name string, version Version) string
|
|
|
|
// InstallDir returns the directory that new plugins should be installed into
|
|
// in order to populate the cache. This directory should be used as the
|
|
// first argument to getter.Get when downloading plugins with go-getter.
|
|
//
|
|
// After installing into this directory, use CachedPluginPath to obtain the
|
|
// path where the plugin was installed.
|
|
InstallDir() string
|
|
}
|
|
|
|
// NewLocalPluginCache returns a PluginCache that caches plugins in a
|
|
// given local directory.
|
|
func NewLocalPluginCache(dir string) PluginCache {
|
|
return &pluginCache{
|
|
Dir: dir,
|
|
}
|
|
}
|
|
|
|
type pluginCache struct {
|
|
Dir string
|
|
}
|
|
|
|
func (c *pluginCache) CachedPluginPath(kind string, name string, version Version) string {
|
|
allPlugins := FindPlugins(kind, []string{c.Dir})
|
|
plugins := allPlugins.WithName(name).WithVersion(version)
|
|
|
|
if plugins.Count() == 0 {
|
|
// nothing cached
|
|
return ""
|
|
}
|
|
|
|
// There should generally be only one plugin here; if there's more than
|
|
// one match for some reason then we'll just choose one arbitrarily.
|
|
plugin := plugins.Newest()
|
|
return plugin.Path
|
|
}
|
|
|
|
func (c *pluginCache) InstallDir() string {
|
|
return c.Dir
|
|
}
|