Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): user-agent telemetry #339

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/http"
"os"
"regexp"
"strings"
"time"

"github.com/hashicorp/go-cleanhttp"
Expand Down Expand Up @@ -100,19 +101,11 @@ type Client struct {
ProjectOrganization *ProjectOrgHandler
}

// GetUserAgentOrDefault configures a default userAgent value, if one has not been provided.
func GetUserAgentOrDefault(userAgent string) string {
if userAgent != "" {
return userAgent
}
return "aiven-go-client/" + Version()
}

// NewMFAUserClient creates a new client based on email, one-time password and password.
func NewMFAUserClient(email, otp, password string, userAgent string) (*Client, error) {
c := &Client{
Client: buildHttpClient(),
UserAgent: GetUserAgentOrDefault(userAgent),
UserAgent: userAgent,
}

ctx := context.Background()
Expand All @@ -139,7 +132,7 @@ func NewTokenClient(key string, userAgent string) (*Client, error) {
c := &Client{
APIKey: key,
Client: buildHttpClient(),
UserAgent: GetUserAgentOrDefault(userAgent),
UserAgent: userAgent,
}
c.Init()

Expand Down Expand Up @@ -343,7 +336,14 @@ func (c *Client) doRequest(ctx context.Context, method, uri string, body interfa
}

req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", c.UserAgent)
req.Header.Set(
"User-Agent",
strings.TrimSpace(fmt.Sprintf(
"go-client/%s %s",
Serpentiel marked this conversation as resolved.
Show resolved Hide resolved
strings.TrimLeft(Version(), "v"),
c.UserAgent,
)),
)
req.Header.Set("Authorization", "aivenv1 "+c.APIKey)

// TODO: BAD hack to get around pagination in most cases
Expand Down
Loading