From 551501575035f021f438212df83b4ea193d84b86 Mon Sep 17 00:00:00 2001 From: Carlos Gajardo Date: Wed, 31 Jul 2024 18:33:31 -0400 Subject: [PATCH] Allow appending to UserAgent with ldflag --- pagerduty/config.go | 15 +++++++++++++++ pagerdutyplugin/config.go | 7 ++++++- util/util.go | 2 ++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/pagerduty/config.go b/pagerduty/config.go index 38a453c11..5d81461e6 100644 --- a/pagerduty/config.go +++ b/pagerduty/config.go @@ -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" @@ -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 @@ -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 diff --git a/pagerdutyplugin/config.go b/pagerdutyplugin/config.go index 28b147a31..5ab319d8e 100644 --- a/pagerdutyplugin/config.go +++ b/pagerdutyplugin/config.go @@ -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), } diff --git a/util/util.go b/util/util.go index 72e91798d..3e3677d68 100644 --- a/util/util.go +++ b/util/util.go @@ -492,3 +492,5 @@ func CheckJSONEqual(expected string) resource.CheckResourceAttrWithFunc { return nil }) } + +var UserAgentAppend string