From 0334796b5ee69872fce9a66cdaf4497eb87896d4 Mon Sep 17 00:00:00 2001 From: Soner Sayakci Date: Tue, 7 May 2024 11:38:48 +0200 Subject: [PATCH] feat: add user-agent to all account api requests --- account-api/client.go | 7 +++++++ cmd/root.go | 2 ++ 2 files changed, 9 insertions(+) diff --git a/account-api/client.go b/account-api/client.go index 0497c6cc..52be717e 100644 --- a/account-api/client.go +++ b/account-api/client.go @@ -13,6 +13,12 @@ import ( "github.com/FriendsOfShopware/shopware-cli/logging" ) +var httpUserAgent = "shopware-cli/0.0.0" + +func SetUserAgent(userAgent string) { + httpUserAgent = userAgent +} + type Client struct { Token token `json:"token"` ActiveMembership Membership `json:"active_membership"` @@ -29,6 +35,7 @@ func (c *Client) NewAuthenticatedRequest(ctx context.Context, method, path strin r.Header.Set("content-type", "application/json") r.Header.Set("accept", "application/json") r.Header.Set("x-shopware-token", c.Token.Token) + r.Header.Set("user-agent", httpUserAgent) return r, nil } diff --git a/cmd/root.go b/cmd/root.go index 8159965a..f8c5beb0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -26,6 +26,8 @@ var rootCmd = &cobra.Command{ } func Execute(ctx context.Context) { + accountApi.SetUserAgent("shopware-cli/" + version) + if err := rootCmd.ExecuteContext(ctx); err != nil { logging.FromContext(ctx).Fatalln(err) }