Skip to content

Commit 6f68722

Browse files
committed
Set User-Agent header containing the agent version in all HTTP requests
This will make it easier to diagnose problems by allowing platform teams to parse HTTP server logs or intermediate HTTP proxy logs and know which version of the agent has made the request. Signed-off-by: Richard Wall <[email protected]>
1 parent 69318c7 commit 6f68722

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

pkg/client/client_api_token.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"time"
1212

1313
"github.com/jetstack/preflight/api"
14+
"github.com/jetstack/preflight/pkg/version"
1415
"k8s.io/client-go/transport"
1516
)
1617

@@ -90,6 +91,7 @@ func (c *APITokenClient) Post(ctx context.Context, path string, body io.Reader)
9091

9192
req.Header.Set("Content-Type", "application/json")
9293
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", c.apiToken))
94+
req.Header.Set("User-Agent", fmt.Sprintf("venafi-kubernetes-agent/%s", version.PreflightVersion))
9395

9496
return c.client.Do(req)
9597
}

pkg/client/client_oauth.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"k8s.io/client-go/transport"
1818

1919
"github.com/jetstack/preflight/api"
20+
"github.com/jetstack/preflight/pkg/version"
2021
)
2122

2223
type (
@@ -151,6 +152,7 @@ func (c *OAuthClient) Post(ctx context.Context, path string, body io.Reader) (*h
151152
}
152153

153154
req.Header.Set("Content-Type", "application/json")
155+
req.Header.Set("User-Agent", fmt.Sprintf("venafi-kubernetes-agent/%s", version.PreflightVersion))
154156

155157
if len(token.bearer) > 0 {
156158
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token.bearer))
@@ -188,6 +190,7 @@ func (c *OAuthClient) renewAccessToken(ctx context.Context) error {
188190
return errors.WithStack(err)
189191
}
190192
req.Header.Add("content-type", "application/x-www-form-urlencoded")
193+
req.Header.Set("User-Agent", fmt.Sprintf("venafi-kubernetes-agent/%s", version.PreflightVersion))
191194

192195
res, err := http.DefaultClient.Do(req)
193196
if err != nil {

pkg/client/client_venafi_cloud.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"k8s.io/client-go/transport"
3131

3232
"github.com/jetstack/preflight/api"
33+
"github.com/jetstack/preflight/pkg/version"
3334
)
3435

3536
type (
@@ -272,6 +273,7 @@ func (c *VenafiCloudClient) Post(ctx context.Context, path string, body io.Reade
272273

273274
req.Header.Set("Accept", "application/json")
274275
req.Header.Set("Content-Type", "application/json")
276+
req.Header.Set("User-Agent", fmt.Sprintf("venafi-kubernetes-agent/%s", version.PreflightVersion))
275277

276278
if len(token.accessToken) > 0 {
277279
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token.accessToken))
@@ -314,6 +316,7 @@ func (c *VenafiCloudClient) updateAccessToken(ctx context.Context) error {
314316

315317
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
316318
request.Header.Add("Content-Length", strconv.Itoa(len(encoded)))
319+
request.Header.Set("User-Agent", fmt.Sprintf("venafi-kubernetes-agent/%s", version.PreflightVersion))
317320

318321
now := time.Now()
319322
accessToken := accessTokenInformation{}

0 commit comments

Comments
 (0)