385140ee6b
* Use version to determine plugin protocol to use * Remove field from ServeOpts * Fix missing assignment, handle errors * contraint -> constraint * Inject the version string from the vault side * Fix the version check * Add grpc support check to database plugins * Default to use grpc unless missing env var or fail on contraint check * Add GRPCSupport test * Add greater than test case * Add go-version dep
41 lines
800 B
Go
41 lines
800 B
Go
package pluginutil
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/hashicorp/go-version"
|
|
)
|
|
|
|
var (
|
|
// PluginVaultVersionEnv is the ENV name used to pass the version of the
|
|
// vault server to the plugin
|
|
PluginVaultVersionEnv = "VAULT_VERSION"
|
|
)
|
|
|
|
// GRPCSupport defaults to returning true, unless VAULT_VERSION is missing or
|
|
// it fails to meet the version constraint.
|
|
func GRPCSupport() bool {
|
|
verString := os.Getenv(PluginVaultVersionEnv)
|
|
|
|
// If the env var is empty, we fall back to netrpc for backward compatibility.
|
|
if verString == "" {
|
|
return false
|
|
}
|
|
|
|
if verString != "unknown" {
|
|
ver, err := version.NewVersion(verString)
|
|
if err != nil {
|
|
return true
|
|
}
|
|
|
|
constraint, err := version.NewConstraint(">= 0.9.2")
|
|
if err != nil {
|
|
return true
|
|
}
|
|
|
|
return constraint.Check(ver)
|
|
}
|
|
|
|
return true
|
|
}
|