mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-05 20:32:57 +02:00
zero: add user-agent to requests (#5078)
This commit is contained in:
parent
86c82c0374
commit
2da4801d3a
3 changed files with 9 additions and 3 deletions
|
@ -11,6 +11,8 @@ import (
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/credentials"
|
"google.golang.org/grpc/credentials"
|
||||||
"google.golang.org/grpc/credentials/insecure"
|
"google.golang.org/grpc/credentials/insecure"
|
||||||
|
|
||||||
|
"github.com/pomerium/pomerium/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// config is the configuration for the gRPC client
|
// config is the configuration for the gRPC client
|
||||||
|
@ -29,6 +31,7 @@ func getConfig(
|
||||||
endpoint string,
|
endpoint string,
|
||||||
opts ...grpc.DialOption,
|
opts ...grpc.DialOption,
|
||||||
) (*config, error) {
|
) (*config, error) {
|
||||||
|
opts = append(opts, grpc.WithUserAgent(version.UserAgent()))
|
||||||
c := &config{opts: opts}
|
c := &config{opts: opts}
|
||||||
err := c.parseEndpoint(endpoint)
|
err := c.parseEndpoint(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package reconciler
|
package reconciler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/pomerium/pomerium/pkg/health"
|
"github.com/pomerium/pomerium/pkg/health"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +10,7 @@ func (c *service) ReportBundleAppliedSuccess(
|
||||||
) {
|
) {
|
||||||
var attr []health.Attr
|
var attr []health.Attr
|
||||||
for k, v := range metadata {
|
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...)
|
health.ReportOK(health.ZeroResourceBundle(bundleID), attr...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,16 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pomerium/pomerium/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultMinTokenTTL = time.Minute * 5
|
defaultMinTokenTTL = time.Minute * 5
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var userAgent = version.UserAgent()
|
||||||
|
|
||||||
type client struct {
|
type client struct {
|
||||||
tokenProvider TokenProviderFn
|
tokenProvider TokenProviderFn
|
||||||
httpClient *http.Client
|
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)
|
return nil, fmt.Errorf("error getting token: %w", err)
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Bearer "+token)
|
req.Header.Set("Authorization", "Bearer "+token)
|
||||||
|
req.Header.Set("User-Agent", userAgent)
|
||||||
|
|
||||||
return c.httpClient.Do(req)
|
return c.httpClient.Do(req)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue