Remove the last vestiges of sdk/version. (#19068)
This commit is contained in:
parent
e4eb9e5376
commit
ec2af04ec6
|
@ -0,0 +1,3 @@
|
|||
```release-note:change
|
||||
sdk: Remove version package, make useragent.String versionless.
|
||||
```
|
|
@ -7,7 +7,7 @@ import (
|
|||
_ "unsafe" // for go:linkname
|
||||
|
||||
goversion "github.com/hashicorp/go-version"
|
||||
"github.com/hashicorp/vault/sdk/version"
|
||||
"github.com/hashicorp/vault/version"
|
||||
)
|
||||
|
||||
const sha1PatchVersionsBefore = "1.12.0"
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/hashicorp/vault/sdk/logical"
|
||||
"github.com/hashicorp/vault/sdk/version"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -15,34 +14,29 @@ var (
|
|||
|
||||
// rt is the runtime - variable for tests.
|
||||
rt = runtime.Version()
|
||||
|
||||
// versionFunc is the func that returns the current version. This is a
|
||||
// function to take into account the different build processes and distinguish
|
||||
// between enterprise and oss builds.
|
||||
versionFunc = func() string {
|
||||
return version.GetVersion().VersionNumber()
|
||||
}
|
||||
)
|
||||
|
||||
// String returns the consistent user-agent string for Vault.
|
||||
//
|
||||
// e.g. Vault/0.10.4 (+https://www.vaultproject.io/; go1.10.1)
|
||||
//
|
||||
// Given comments will be appended to the semicolon-delimited comment section.
|
||||
//
|
||||
// e.g. Vault/0.10.4 (+https://www.vaultproject.io/; go1.10.1; comment-0; comment-1)
|
||||
//
|
||||
// Deprecated: use PluginString instead.
|
||||
//
|
||||
// Example output:
|
||||
//
|
||||
// Vault (+https://www.vaultproject.io/; go1.19.5)
|
||||
//
|
||||
// Given comments will be appended to the semicolon-delimited comment section:
|
||||
//
|
||||
// Vault (+https://www.vaultproject.io/; go1.19.5; comment-0; comment-1)
|
||||
//
|
||||
// At one point the user-agent string returned contained the Vault
|
||||
// version hardcoded into the vault/sdk/version/ package. This works for builtin
|
||||
// version hardcoded into the vault/sdk/version/ package. This worked for builtin
|
||||
// plugins that are compiled into the `vault` binary, in that it correctly described
|
||||
// the version of that Vault binary. It does not work for external plugins: for them,
|
||||
// the version of that Vault binary. It did not work for external plugins: for them,
|
||||
// the version will be based on the version stored in the sdk based on the
|
||||
// contents of the external plugin's go.mod. Now that we're no longer updating
|
||||
// the version in vault/sdk/version/, it is even less meaningful than ever.
|
||||
// contents of the external plugin's go.mod. We've kept the String method around
|
||||
// to avoid breaking builds, but you should be using PluginString.
|
||||
func String(comments ...string) string {
|
||||
c := append([]string{"+" + projectURL, rt}, comments...)
|
||||
return fmt.Sprintf("Vault/%s (%s)", versionFunc(), strings.Join(c, "; "))
|
||||
return fmt.Sprintf("Vault (%s)", strings.Join(c, "; "))
|
||||
}
|
||||
|
||||
// PluginString is usable by plugins to return a user-agent string reflecting
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
func TestUserAgent(t *testing.T) {
|
||||
projectURL = "https://vault-test.com"
|
||||
rt = "go5.0"
|
||||
versionFunc = func() string { return "1.2.3" }
|
||||
|
||||
type args struct {
|
||||
comments []string
|
||||
|
@ -22,21 +21,21 @@ func TestUserAgent(t *testing.T) {
|
|||
{
|
||||
name: "User agent",
|
||||
args: args{},
|
||||
want: "Vault/1.2.3 (+https://vault-test.com; go5.0)",
|
||||
want: "Vault (+https://vault-test.com; go5.0)",
|
||||
},
|
||||
{
|
||||
name: "User agent with additional comment",
|
||||
args: args{
|
||||
comments: []string{"pid-abcdefg"},
|
||||
},
|
||||
want: "Vault/1.2.3 (+https://vault-test.com; go5.0; pid-abcdefg)",
|
||||
want: "Vault (+https://vault-test.com; go5.0; pid-abcdefg)",
|
||||
},
|
||||
{
|
||||
name: "User agent with additional comments",
|
||||
args: args{
|
||||
comments: []string{"pid-abcdefg", "cloud-provider"},
|
||||
},
|
||||
want: "Vault/1.2.3 (+https://vault-test.com; go5.0; pid-abcdefg; cloud-provider)",
|
||||
want: "Vault (+https://vault-test.com; go5.0; pid-abcdefg; cloud-provider)",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
//go:build cgo
|
||||
|
||||
package version
|
||||
|
||||
func init() {
|
||||
CgoEnabled = true
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
package version
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// VersionInfo
|
||||
type VersionInfo struct {
|
||||
Revision string `json:"revision,omitempty"`
|
||||
Version string `json:"version,omitempty"`
|
||||
VersionPrerelease string `json:"version_prerelease,omitempty"`
|
||||
VersionMetadata string `json:"version_metadata,omitempty"`
|
||||
BuildDate string `json:"build_date,omitempty"`
|
||||
}
|
||||
|
||||
func GetVersion() *VersionInfo {
|
||||
ver := Version
|
||||
rel := VersionPrerelease
|
||||
md := VersionMetadata
|
||||
if GitDescribe != "" {
|
||||
ver = GitDescribe
|
||||
}
|
||||
if GitDescribe == "" && rel == "" && VersionPrerelease != "" {
|
||||
rel = "dev"
|
||||
}
|
||||
|
||||
return &VersionInfo{
|
||||
Revision: GitCommit,
|
||||
Version: ver,
|
||||
VersionPrerelease: rel,
|
||||
VersionMetadata: md,
|
||||
BuildDate: BuildDate,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *VersionInfo) VersionNumber() string {
|
||||
if Version == "unknown" && VersionPrerelease == "unknown" {
|
||||
return "(version unknown)"
|
||||
}
|
||||
|
||||
version := c.Version
|
||||
|
||||
if c.VersionPrerelease != "" {
|
||||
version = fmt.Sprintf("%s-%s", version, c.VersionPrerelease)
|
||||
}
|
||||
|
||||
if c.VersionMetadata != "" {
|
||||
version = fmt.Sprintf("%s+%s", version, c.VersionMetadata)
|
||||
}
|
||||
|
||||
return version
|
||||
}
|
||||
|
||||
func (c *VersionInfo) FullVersionNumber(rev bool) string {
|
||||
var versionString bytes.Buffer
|
||||
|
||||
if Version == "unknown" && VersionPrerelease == "unknown" {
|
||||
return "Vault (version unknown)"
|
||||
}
|
||||
|
||||
fmt.Fprintf(&versionString, "Vault v%s", c.Version)
|
||||
if c.VersionPrerelease != "" {
|
||||
fmt.Fprintf(&versionString, "-%s", c.VersionPrerelease)
|
||||
}
|
||||
|
||||
if c.VersionMetadata != "" {
|
||||
fmt.Fprintf(&versionString, "+%s", c.VersionMetadata)
|
||||
}
|
||||
|
||||
if rev && c.Revision != "" {
|
||||
fmt.Fprintf(&versionString, " (%s)", c.Revision)
|
||||
}
|
||||
|
||||
if c.BuildDate != "" {
|
||||
fmt.Fprintf(&versionString, ", built %s", c.BuildDate)
|
||||
}
|
||||
|
||||
return versionString.String()
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package version
|
||||
|
||||
var (
|
||||
// The git commit that was compiled. This will be filled in by the compiler.
|
||||
GitCommit string
|
||||
GitDescribe string
|
||||
|
||||
// The compilation date. This will be filled in by the compiler.
|
||||
BuildDate string
|
||||
|
||||
// Whether cgo is enabled or not; set at build time
|
||||
CgoEnabled bool
|
||||
|
||||
Version = "1.13.0"
|
||||
VersionPrerelease = "dev1"
|
||||
VersionMetadata = ""
|
||||
)
|
|
@ -13,7 +13,6 @@ import (
|
|||
linkConfig "github.com/hashicorp/hcp-link/pkg/config"
|
||||
scada "github.com/hashicorp/hcp-scada-provider"
|
||||
"github.com/hashicorp/vault/internalshared/configutil"
|
||||
vaultVersion "github.com/hashicorp/vault/sdk/version"
|
||||
"github.com/hashicorp/vault/vault"
|
||||
"github.com/hashicorp/vault/vault/hcp_link/capabilities"
|
||||
"github.com/hashicorp/vault/vault/hcp_link/capabilities/api_capability"
|
||||
|
@ -21,6 +20,7 @@ import (
|
|||
"github.com/hashicorp/vault/vault/hcp_link/capabilities/meta"
|
||||
"github.com/hashicorp/vault/vault/hcp_link/capabilities/node_status"
|
||||
"github.com/hashicorp/vault/vault/hcp_link/internal"
|
||||
vaultVersion "github.com/hashicorp/vault/version"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
Loading…
Reference in New Issue