diff --git a/internal/artieclient/client.go b/internal/artieclient/client.go index df5adb8..3037e4b 100644 --- a/internal/artieclient/client.go +++ b/internal/artieclient/client.go @@ -31,14 +31,15 @@ func (he HttpError) Error() string { type Client struct { endpoint string apiKey string + version string } -func New(endpoint string, apiKey string) (Client, error) { +func New(endpoint string, apiKey string, version string) (Client, error) { if !strings.HasPrefix(apiKey, "arsk_") { return Client{}, fmt.Errorf("artie-client: api key is malformed (should start with arsk_)") } - return Client{endpoint: endpoint, apiKey: apiKey}, nil + return Client{endpoint: endpoint, apiKey: apiKey, version: version}, nil } func buildError(resp *http.Response) error { @@ -78,6 +79,7 @@ func (c Client) makeRequest(ctx context.Context, method string, path string, bod return fmt.Errorf("artie-client: failed to create request: %w", err) } req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.apiKey)) + req.Header.Set("User-Agent", "terraform-provider-artie/"+c.version) resp, err := http.DefaultClient.Do(req) if err != nil { diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 0524354..85b6a0e 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -33,10 +33,11 @@ type ArtieProviderModel struct { type ArtieProviderData struct { Endpoint string APIKey string + version string } func (a ArtieProviderData) NewClient() (artieclient.Client, error) { - return artieclient.New(a.Endpoint, a.APIKey) + return artieclient.New(a.Endpoint, a.APIKey, a.version) } func (p *ArtieProvider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { @@ -75,6 +76,7 @@ func (p *ArtieProvider) Configure(ctx context.Context, req provider.ConfigureReq providerData := ArtieProviderData{ Endpoint: endpoint, APIKey: configData.APIKey.ValueString(), + version: p.version, } resp.DataSourceData = providerData