Skip to content

Commit

Permalink
Updated code for provider version in User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
patryk committed Oct 22, 2018
1 parent 6ee7a1a commit 489fd0f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
3 changes: 1 addition & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ VERSION=$(shell git describe --tags --always)
default: build

build: fmtcheck
go install -ldflags="-X github.com/terraform-providers/terraform-provider-cloudflare/cloudflare.pluginVersion=$(VERSION)"
go install -ldflags="-X github.com/terraform-providers/terraform-provider-cloudflare/version.ProviderVersion=$(VERSION)"

test: fmtcheck
go test -i $(TEST) || exit 1
Expand Down Expand Up @@ -61,4 +61,3 @@ endif
@$(MAKE) -C $(GOPATH)/src/$(WEBSITE_REPO) website-provider-test PROVIDER_PATH=$(shell pwd) PROVIDER_NAME=$(PKG_NAME)

.PHONY: build test testacc vet fmt fmtcheck errcheck vendor-status test-compile website website-test

14 changes: 9 additions & 5 deletions cloudflare/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ package cloudflare
import (
"log"
"os"
"strings"

"fmt"

"github.com/cloudflare/cloudflare-go"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/httpclient"
"github.com/hashicorp/terraform/terraform"
"github.com/terraform-providers/terraform-provider-cloudflare/version"
)

var pluginVersion string

// Provider returns a terraform.ResourceProvider.
func Provider() terraform.ResourceProvider {
return &schema.Provider{
Expand Down Expand Up @@ -163,9 +164,12 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
return client, err
}

if pluginVersion != "" {
options = append(options, cloudflare.UserAgent("terraform-provider-cloudflare/"+pluginVersion))
}
// TODO: This is the SDK version not the CLI version, once we are on 0.12, should revisit
tfUserAgent := httpclient.UserAgentString()

pv := version.ProviderVersion
providerUserAgent := fmt.Sprintf("%s terraform-provider-cloudflare/%s", tfUserAgent, pv)
options = append(options, cloudflare.UserAgent(strings.TrimSpace(fmt.Sprintf("%s %s", client.UserAgent, providerUserAgent))))

config = Config{
Email: d.Get("email").(string),
Expand Down
6 changes: 6 additions & 0 deletions version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package version

var (
// ProviderVersion is set during the release process to the release version of the binary
ProviderVersion = "dev"
)

0 comments on commit 489fd0f

Please sign in to comment.