aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/terraform/plugin/discovery/meta.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/hashicorp/terraform/plugin/discovery/meta.go')
-rw-r--r--vendor/github.com/hashicorp/terraform/plugin/discovery/meta.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/terraform/plugin/discovery/meta.go b/vendor/github.com/hashicorp/terraform/plugin/discovery/meta.go
new file mode 100644
index 0000000..bdcebcb
--- /dev/null
+++ b/vendor/github.com/hashicorp/terraform/plugin/discovery/meta.go
@@ -0,0 +1,41 @@
1package discovery
2
3import (
4 "crypto/sha256"
5 "io"
6 "os"
7)
8
9// PluginMeta is metadata about a plugin, useful for launching the plugin
10// and for understanding which plugins are available.
11type PluginMeta struct {
12 // Name is the name of the plugin, e.g. as inferred from the plugin
13 // binary's filename, or by explicit configuration.
14 Name string
15
16 // Version is the semver version of the plugin, expressed as a string
17 // that might not be semver-valid.
18 Version VersionStr
19
20 // Path is the absolute path of the executable that can be launched
21 // to provide the RPC server for this plugin.
22 Path string
23}
24
25// SHA256 returns a SHA256 hash of the content of the referenced executable
26// file, or an error if the file's contents cannot be read.
27func (m PluginMeta) SHA256() ([]byte, error) {
28 f, err := os.Open(m.Path)
29 if err != nil {
30 return nil, err
31 }
32 defer f.Close()
33
34 h := sha256.New()
35 _, err = io.Copy(h, f)
36 if err != nil {
37 return nil, err
38 }
39
40 return h.Sum(nil), nil
41}