Skip to content

Commit

Permalink
Merge pull request #37 from hashicorp/meta-package
Browse files Browse the repository at this point in the history
meta package
  • Loading branch information
kmoe authored Sep 10, 2019
2 parents 65da824 + 9f40692 commit 53994dd
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
4 changes: 3 additions & 1 deletion httpclient/useragent.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"log"
"os"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/meta"
)

const uaEnvVar = "TF_APPEND_USER_AGENT"

func TerraformUserAgent(version string) string {
ua := fmt.Sprintf("HashiCorp Terraform/%s (+https://www.terraform.io)", version)
ua := fmt.Sprintf("HashiCorp Terraform/%s (+https://www.terraform.io) Terraform Plugin SDK/%s", version, meta.SDKVersionString())

if add := os.Getenv(uaEnvVar); add != "" {
add = strings.TrimSpace(add)
Expand Down
4 changes: 3 additions & 1 deletion httpclient/useragent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/meta"
)

func TestUserAgentAppendViaEnvVar(t *testing.T) {
Expand All @@ -13,7 +15,7 @@ func TestUserAgentAppendViaEnvVar(t *testing.T) {
defer os.Unsetenv(uaEnvVar)
}

expectedBase := "HashiCorp Terraform/0.0.0 (+https://www.terraform.io)"
expectedBase := "HashiCorp Terraform/0.0.0 (+https://www.terraform.io) Terraform Plugin SDK/" + meta.SDKVersionString()

testCases := []struct {
envVarValue string
Expand Down
36 changes: 36 additions & 0 deletions meta/meta.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// The meta package provides a location to set the release version
// and any other relevant metadata for the SDK.
//
// This package should not import any other SDK packages.
package meta

import (
"fmt"

version "github.com/hashicorp/go-version"
)

// The main version number that is being run at the moment.
var SDKVersion = "1.0.0"

// A pre-release marker for the version. If this is "" (empty string)
// then it means that it is a final release. Otherwise, this is a pre-release
// such as "dev" (in development), "beta", "rc1", etc.
var SDKPrerelease = "dev"

// SemVer is an instance of version.Version. This has the secondary
// benefit of verifying during tests and init time that our version is a
// proper semantic version, which should always be the case.
var SemVer *version.Version

func init() {
SemVer = version.Must(version.NewVersion(SDKVersion))
}

// VersionString returns the complete version string, including prerelease
func SDKVersionString() string {
if SDKPrerelease != "" {
return fmt.Sprintf("%s-%s", SDKVersion, SDKPrerelease)
}
return SDKVersion
}

0 comments on commit 53994dd

Please sign in to comment.