Skip to content

Commit

Permalink
Add ability to set custom user agent information (#249)
Browse files Browse the repository at this point in the history
* Add ability to set custom user agent information

* changelog
  • Loading branch information
patrickcping authored Dec 29, 2023
1 parent 1935a0e commit 4c4fa54
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/249.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
Added ability to append custom text information to the default User Agent.
```
8 changes: 8 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 generated by tfplugindocs -->
## Schema

Expand Down
1 change: 1 addition & 0 deletions examples/provider/provider-custom-user-agent.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$ export DAVINCI_TF_APPEND_USER_AGENT="Jenkins/2.426.2"
9 changes: 8 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package provider
import (
"context"
"fmt"
"os"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"
Expand Down Expand Up @@ -113,14 +114,20 @@ 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,
PingOneRegion: region,
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 {
Expand Down
6 changes: 6 additions & 0 deletions templates/index.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

0 comments on commit 4c4fa54

Please sign in to comment.