Skip to content

Commit

Permalink
Allow appending to UserAgent with ldflag
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgajard committed Jul 31, 2024
1 parent a706ae2 commit 5515015
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
15 changes: 15 additions & 0 deletions pagerduty/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"sync"
"time"

"github.com/PagerDuty/terraform-provider-pagerduty/util"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
"github.com/heimweh/go-pagerduty/pagerduty"
"github.com/heimweh/go-pagerduty/persistentconfig"
Expand Down Expand Up @@ -98,6 +99,13 @@ func (c *Config) Client() (*pagerduty.Client, error) {
APIAuthTokenType: c.APITokenType,
}

if util.UserAgentAppend != "" {
if config.UserAgent == "" {
config.UserAgent = "heimweh/go-pagerduty(terraform)"
}
config.UserAgent += " " + util.UserAgentAppend
}

client, err := pagerduty.NewClient(config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -149,6 +157,13 @@ func (c *Config) SlackClient() (*pagerduty.Client, error) {
UserAgent: c.UserAgent,
}

if util.UserAgentAppend != "" {
if config.UserAgent == "" {
config.UserAgent = "heimweh/go-pagerduty(terraform)"
}
config.UserAgent += " " + util.UserAgentAppend
}

client, err := pagerduty.NewClient(config)
if err != nil {
return nil, err
Expand Down
7 changes: 6 additions & 1 deletion pagerdutyplugin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,15 @@ func (c *Config) Client(ctx context.Context) (*pagerduty.Client, error) {
maxRetries := 1
retryInterval := 60 // seconds

userAgentVersion := c.TerraformVersion
if util.UserAgentAppend != "" {
userAgentVersion += " " + util.UserAgentAppend
}

clientOpts := []pagerduty.ClientOptions{
WithHTTPClient(httpClient),
pagerduty.WithAPIEndpoint(apiURL),
pagerduty.WithTerraformProvider(c.TerraformVersion),
pagerduty.WithTerraformProvider(userAgentVersion),
pagerduty.WithRetryPolicy(maxRetries, retryInterval),
}

Expand Down
2 changes: 2 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,3 +492,5 @@ func CheckJSONEqual(expected string) resource.CheckResourceAttrWithFunc {
return nil
})
}

var UserAgentAppend string

0 comments on commit 5515015

Please sign in to comment.