diff --git a/changelog/19068.txt b/changelog/19068.txt new file mode 100644 index 000000000..6edb29fe1 --- /dev/null +++ b/changelog/19068.txt @@ -0,0 +1,3 @@ +```release-note:change +sdk: Remove version package, make useragent.String versionless. +``` diff --git a/internal/go118_sha1_patch.go b/internal/go118_sha1_patch.go index f3b3cea68..c7f94844e 100644 --- a/internal/go118_sha1_patch.go +++ b/internal/go118_sha1_patch.go @@ -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" diff --git a/sdk/helper/useragent/useragent.go b/sdk/helper/useragent/useragent.go index 33b2a23b8..0dc4b2c9e 100644 --- a/sdk/helper/useragent/useragent.go +++ b/sdk/helper/useragent/useragent.go @@ -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 diff --git a/sdk/helper/useragent/useragent_test.go b/sdk/helper/useragent/useragent_test.go index f0d014f6c..c21b0c947 100644 --- a/sdk/helper/useragent/useragent_test.go +++ b/sdk/helper/useragent/useragent_test.go @@ -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 { diff --git a/sdk/version/cgo.go b/sdk/version/cgo.go deleted file mode 100644 index 5bc93e5bf..000000000 --- a/sdk/version/cgo.go +++ /dev/null @@ -1,7 +0,0 @@ -//go:build cgo - -package version - -func init() { - CgoEnabled = true -} diff --git a/sdk/version/version.go b/sdk/version/version.go deleted file mode 100644 index 78b8eb829..000000000 --- a/sdk/version/version.go +++ /dev/null @@ -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() -} diff --git a/sdk/version/version_base.go b/sdk/version/version_base.go deleted file mode 100644 index e45626e2c..000000000 --- a/sdk/version/version_base.go +++ /dev/null @@ -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 = "" -) diff --git a/vault/hcp_link/link.go b/vault/hcp_link/link.go index e33d47b2f..cf2c4d72b 100644 --- a/vault/hcp_link/link.go +++ b/vault/hcp_link/link.go @@ -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 (