Skip to content

Commit

Permalink
Pass provider version as build number to CLI
Browse files Browse the repository at this point in the history
This converts the dot version of the provider into a build number that will be passed as user-agent info to the CLI.
  • Loading branch information
edif2008 committed Feb 27, 2024
1 parent 32525dc commit 2c589cc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion onepassword/cli/op.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"github.com/1Password/connect-sdk-go/onepassword"
"github.com/1Password/terraform-provider-onepassword/version"
"github.com/Masterminds/semver/v3"
"github.com/hashicorp/terraform-plugin-log/tflog"
)
Expand Down Expand Up @@ -220,9 +221,9 @@ func (op *OP) execRaw(ctx context.Context, stdin []byte, args ...opArg) ([]byte,
cmd := exec.CommandContext(ctx, op.binaryPath, cmdArgs...)
cmd.Env = append(cmd.Environ(),
"OP_FORMAT=json",
//"OP_INTEGRATION_BUILDNUMBER="+version.ProviderVersion, // causes bad request errors from CLI
"OP_INTEGRATION_NAME=terraform-provider",
"OP_INTEGRATION_ID=TFP",
"OP_INTEGRATION_BUILDNUMBER="+makeBuildVersion(version.ProviderVersion),
)
if op.serviceAccountToken != "" {
cmd.Env = append(cmd.Env, "OP_SERVICE_ACCOUNT_TOKEN="+op.serviceAccountToken)
Expand Down
16 changes: 16 additions & 0 deletions onepassword/cli/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,19 @@ func waitBeforeRetry(retryAttempts int) {
wait := time.Duration(retryTimeMilliseconds) * time.Millisecond
time.Sleep(wait)
}

func makeBuildVersion(version string) string {
parts := strings.Split(strings.ReplaceAll(version, "-beta", ""), ".")
buildVersion := parts[0]
for i := 1; i < len(parts); i++ {
if len(parts[i]) == 1 {
buildVersion += "0" + parts[i]
} else {
buildVersion += parts[i]
}
}
if len(parts) != 3 {
return buildVersion
}
return buildVersion + "01"
}
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package version

var (
// ProviderVersion is set during release.
ProviderVersion = "dev"
ProviderVersion = "1.4.2"
)

0 comments on commit 2c589cc

Please sign in to comment.