Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

meta package #37

Merged
merged 2 commits into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}