Skip to content

Commit

Permalink
Merge pull request #74 from SaaldjorMike/mike/custom_useragent
Browse files Browse the repository at this point in the history
Allow custom 'User-Agent' header
  • Loading branch information
SaaldjorMike authored Jun 15, 2021
2 parents ce92f7b + 2fc3ed0 commit 36ca7bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ import (
"github.com/shurcooL/graphql"
)

const defaultUserAgent = "Humio-go-client/unknown"

type Client struct {
config Config
}

type Config struct {
Address *url.URL
UserAgent string
Token string
CACertificatePEM string
Insecure bool
Expand Down Expand Up @@ -57,6 +60,10 @@ func NewClient(config Config) *Client {
config.Address.Path = config.Address.Path + "/"
}

if config.UserAgent == "" {
config.UserAgent = defaultUserAgent
}

return &Client{
config: config,
}
Expand All @@ -73,6 +80,10 @@ func (c *Client) headers() map[string]string {
headers["ProxyOrganization"] = c.config.ProxyOrganization
}

if c.config.UserAgent != "" {
headers["User-Agent"] = c.config.UserAgent
}

return headers
}

Expand Down
1 change: 1 addition & 0 deletions cmd/humioctl/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func newApiClientE(cmd *cobra.Command, opts ...func(config *api.Config)) (*api.C
config.CACertificatePEM = viper.GetString(viperkey.CACertificate)
config.Insecure = viper.GetBool(viperkey.Insecure)
config.ProxyOrganization = viper.GetString(viperkey.ProxyOrganization)
config.UserAgent = fmt.Sprintf("humioctl/%s (%s on %s)", version, commit, date)

for _, opt := range opts {
opt(&config)
Expand Down

0 comments on commit 36ca7bd

Please sign in to comment.