mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
a1e29ae290
The semver library we were using doesn't have support for a "pessimistic constraint" where e.g. the user wants to accept only minor or patch version upgrades. This is important for providers since users will generally want to pin their dependencies to not inadvertantly accept breaking changes. So here we switch to hashicorp's home-grown go-version library, which has the ~> constraint operator for this sort of constraint. Given how much the old version object was already intruding into the interface and creating dependency noise in callers, this also now wraps the "raw" go-version objects in package-local structs, thus keeping the details encapsulated and allowing callers to deal just with this package's own types.
42 lines
983 B
Go
42 lines
983 B
Go
package discovery
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
// PluginMeta is metadata about a plugin, useful for launching the plugin
|
|
// and for understanding which plugins are available.
|
|
type PluginMeta struct {
|
|
// Name is the name of the plugin, e.g. as inferred from the plugin
|
|
// binary's filename, or by explicit configuration.
|
|
Name string
|
|
|
|
// Version is the semver version of the plugin, expressed as a string
|
|
// that might not be semver-valid.
|
|
Version VersionStr
|
|
|
|
// Path is the absolute path of the executable that can be launched
|
|
// to provide the RPC server for this plugin.
|
|
Path string
|
|
}
|
|
|
|
// SHA256 returns a SHA256 hash of the content of the referenced executable
|
|
// file, or an error if the file's contents cannot be read.
|
|
func (m PluginMeta) SHA256() ([]byte, error) {
|
|
f, err := os.Open(m.Path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
|
|
h := sha256.New()
|
|
_, err = io.Copy(h, f)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return h.Sum(nil), nil
|
|
}
|