Skip to content

Commit

Permalink
Merge pull request #46 from planetscale/set-user-agent
Browse files Browse the repository at this point in the history
http: set user-agent
  • Loading branch information
aybabtme authored Oct 26, 2023
2 parents eba4591 + 09c4ee1 commit a5e4875
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 8 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,14 @@ func (p *PlanetScaleProvider) Configure(ctx context.Context, req provider.Config
return
}

client := planetscale.NewClient(&http.Client{Transport: rt}, baseURL)
client := planetscale.NewClient(
&http.Client{
Transport: roundTripperFunc(func(r *http.Request) (*http.Response, error) {
r.Header.Set("User-Agent", "PlanetScale_Terraform_Provider/"+p.version+" (Terraform "+req.TerraformVersion+")")
return rt.RoundTrip(r)
}),
}, baseURL,
)

resp.DataSourceData = client
resp.ResourceData = client
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"flag"
"log"
"os"

"github.com/hashicorp/terraform-plugin-framework/providerserver"
"github.com/planetscale/terraform-provider-planetscale/internal/provider"
Expand Down Expand Up @@ -44,7 +45,8 @@ func main() {
Debug: debug,
}

err := providerserver.Serve(context.Background(), provider.New(version, debug), opts)
debugProvider := os.Getenv("TF_PS_PROVIDER_DEBUG") != ""
err := providerserver.Serve(context.Background(), provider.New(version, debug || debugProvider), opts)

if err != nil {
log.Fatal(err.Error())
Expand Down

0 comments on commit a5e4875

Please sign in to comment.