zero: add user-agent to requests (#5078)

This commit is contained in:
Denis Mishin 2024-04-19 11:33:43 -04:00 committed by GitHub
parent 86c82c0374
commit 2da4801d3a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 3 deletions

View file

@ -11,6 +11,8 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"github.com/pomerium/pomerium/internal/version"
)
// config is the configuration for the gRPC client
@ -29,6 +31,7 @@ func getConfig(
endpoint string,
opts ...grpc.DialOption,
) (*config, error) {
opts = append(opts, grpc.WithUserAgent(version.UserAgent()))
c := &config{opts: opts}
err := c.parseEndpoint(endpoint)
if err != nil {

View file

@ -1,8 +1,6 @@
package reconciler
import (
"fmt"
"github.com/pomerium/pomerium/pkg/health"
)
@ -12,7 +10,7 @@ func (c *service) ReportBundleAppliedSuccess(
) {
var attr []health.Attr
for k, v := range metadata {
attr = append(attr, health.StrAttr(fmt.Sprintf("download-metadata-%s", k), v))
attr = append(attr, health.StrAttr(k, v))
}
health.ReportOK(health.ZeroResourceBundle(bundleID), attr...)
}

View file

@ -6,12 +6,16 @@ import (
"fmt"
"net/http"
"time"
"github.com/pomerium/pomerium/internal/version"
)
const (
defaultMinTokenTTL = time.Minute * 5
)
var userAgent = version.UserAgent()
type client struct {
tokenProvider TokenProviderFn
httpClient *http.Client
@ -44,6 +48,7 @@ func (c *client) Do(req *http.Request) (*http.Response, error) {
return nil, fmt.Errorf("error getting token: %w", err)
}
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("User-Agent", userAgent)
return c.httpClient.Do(req)
}