Skip to content

Commit

Permalink
Merge pull request #921 from cjgajard/user-agent-append
Browse files Browse the repository at this point in the history
Allow appending to UserAgent with ldflag
  • Loading branch information
imjaroiswebdev authored Jul 31, 2024
2 parents a706ae2 + 5515015 commit 1d0190d
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 1d0190d

Please sign in to comment.