From 4c4fa54a1a142c53a7137e42ea806bc700802ef0 Mon Sep 17 00:00:00 2001 From: Patrick Cowland <44225864+patrickcping@users.noreply.github.com> Date: Fri, 29 Dec 2023 15:54:19 +0000 Subject: [PATCH] Add ability to set custom user agent information (#249) * Add ability to set custom user agent information * changelog --- .changelog/249.txt | 3 +++ docs/index.md | 8 ++++++++ examples/provider/provider-custom-user-agent.sh | 1 + internal/provider/provider.go | 9 ++++++++- templates/index.md.tmpl | 6 ++++++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 .changelog/249.txt create mode 100644 examples/provider/provider-custom-user-agent.sh diff --git a/.changelog/249.txt b/.changelog/249.txt new file mode 100644 index 00000000..6c4d6b73 --- /dev/null +++ b/.changelog/249.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +Added ability to append custom text information to the default User Agent. +``` diff --git a/docs/index.md b/docs/index.md index cc52dca3..e40c53bb 100644 --- a/docs/index.md +++ b/docs/index.md @@ -216,6 +216,14 @@ resource "davinci_flow" "mainflow" { > This above example was updated to reflect new DaVinci roles added on August 5th, 2023. The `DaVinci Admin` role is now required for user SSO and interaction with DaVinci APIs. +### Custom User Agent information + +The DaVinci provider allows custom information to be appended to the default user agent string (that includes Terraform provider version information) by setting the `DAVINCI_TF_APPEND_USER_AGENT` environment variable. This can be useful when troubleshooting issues with Ping Identity Support, or adding context to HTTP requests. + +```shell +$ export DAVINCI_TF_APPEND_USER_AGENT="Jenkins/2.426.2" +``` + ## Schema diff --git a/examples/provider/provider-custom-user-agent.sh b/examples/provider/provider-custom-user-agent.sh new file mode 100644 index 00000000..8ee47095 --- /dev/null +++ b/examples/provider/provider-custom-user-agent.sh @@ -0,0 +1 @@ +$ export DAVINCI_TF_APPEND_USER_AGENT="Jenkins/2.426.2" diff --git a/internal/provider/provider.go b/internal/provider/provider.go index ea62afac..89ae202a 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -3,6 +3,7 @@ package provider import ( "context" "fmt" + "os" "strings" "github.com/hashicorp/terraform-plugin-log/tflog" @@ -113,6 +114,12 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema var diags diag.Diagnostics + userAgent := fmt.Sprintf("terraform-provider-davinci/%s", version) + + if v := strings.TrimSpace(os.Getenv("DAVINCI_TF_APPEND_USER_AGENT")); v != "" { + userAgent += fmt.Sprintf(" %s", v) + } + cInput := client.ClientInput{ Username: username, Password: password, @@ -120,7 +127,7 @@ func configure(version string, p *schema.Provider) func(context.Context, *schema PingOneSSOEnvId: environment_id, HostURL: host_url, AccessToken: accessToken, - UserAgent: fmt.Sprintf("terraform-provider-davinci/%s/go", version), + UserAgent: userAgent, } c, err := retryableClient(&cInput) if err != nil { diff --git a/templates/index.md.tmpl b/templates/index.md.tmpl index 2b84482a..fb953c80 100644 --- a/templates/index.md.tmpl +++ b/templates/index.md.tmpl @@ -48,4 +48,10 @@ The following assumes that the PingOne worker app has been provided the `Environ > This above example was updated to reflect new DaVinci roles added on August 5th, 2023. The `DaVinci Admin` role is now required for user SSO and interaction with DaVinci APIs. +### Custom User Agent information + +The DaVinci provider allows custom information to be appended to the default user agent string (that includes Terraform provider version information) by setting the `DAVINCI_TF_APPEND_USER_AGENT` environment variable. This can be useful when troubleshooting issues with Ping Identity Support, or adding context to HTTP requests. + +{{ codefile "shell" (printf "%s" "examples/provider/provider-custom-user-agent.sh") }} + {{ .SchemaMarkdown | trimspace }}