From 41c4a6e0b457423d36efe4e263d437037300de76 Mon Sep 17 00:00:00 2001 From: Jeff Mendoza Date: Tue, 25 Apr 2023 13:40:45 -0700 Subject: [PATCH] Add UserAgent to github, deps.dev, gcs, oci. Signed-off-by: Jeff Mendoza --- internal/client/githubclient/githubclient.go | 8 +++++++- pkg/handler/collector/deps_dev/deps_dev.go | 5 ++++- pkg/handler/collector/gcs/gcs.go | 5 ++++- pkg/handler/collector/oci/oci.go | 2 ++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/client/githubclient/githubclient.go b/internal/client/githubclient/githubclient.go index eb97a6970c..d3f5267eeb 100644 --- a/internal/client/githubclient/githubclient.go +++ b/internal/client/githubclient/githubclient.go @@ -23,6 +23,7 @@ import ( "github.com/google/go-github/v50/github" "github.com/guacsec/guac/internal/client" + "github.com/guacsec/guac/pkg/version" "golang.org/x/oauth2" ) @@ -56,7 +57,12 @@ var _ GithubClient = &githubClient{} func NewGithubClient(ctx context.Context, token string) (*githubClient, error) { ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token}) - tc := oauth2.NewClient(ctx, ts) + tc := &http.Client{ + Transport: &oauth2.Transport{ + Source: ts, + Base: version.UATransport, + }, + } gc := github.NewClient(tc) // Run a simple API call to verify authentication to Github API. diff --git a/pkg/handler/collector/deps_dev/deps_dev.go b/pkg/handler/collector/deps_dev/deps_dev.go index 65d99cbbba..37b14714e9 100644 --- a/pkg/handler/collector/deps_dev/deps_dev.go +++ b/pkg/handler/collector/deps_dev/deps_dev.go @@ -29,6 +29,7 @@ import ( pb "github.com/guacsec/guac/pkg/handler/collector/deps_dev/internal" "github.com/guacsec/guac/pkg/handler/processor" "github.com/guacsec/guac/pkg/logging" + "github.com/guacsec/guac/pkg/version" "google.golang.org/grpc" "google.golang.org/grpc/credentials" ) @@ -74,7 +75,9 @@ func NewDepsCollector(ctx context.Context, collectDataSource datasource.CollectS // Connect to the service using TLS. creds := credentials.NewClientTLSFromCert(sysPool, "") - conn, err := grpc.Dial("api.deps.dev:443", grpc.WithTransportCredentials(creds)) + conn, err := grpc.Dial("api.deps.dev:443", + grpc.WithTransportCredentials(creds), + grpc.WithUserAgent(version.UserAgent)) if err != nil { return nil, fmt.Errorf("failed to connect to api.deps.dev: %w", err) } diff --git a/pkg/handler/collector/gcs/gcs.go b/pkg/handler/collector/gcs/gcs.go index dd09ae6703..1ee238769c 100644 --- a/pkg/handler/collector/gcs/gcs.go +++ b/pkg/handler/collector/gcs/gcs.go @@ -29,6 +29,7 @@ import ( "github.com/guacsec/guac/pkg/handler/processor" "github.com/guacsec/guac/pkg/logging" + "github.com/guacsec/guac/pkg/version" ) type gcs struct { @@ -67,7 +68,9 @@ func NewGCSClient(ctx context.Context, poll bool, interval time.Duration) (*gcs, if getCredsPath() == "" { return nil, errors.New("gcs bucket not specified") } - client, err := storage.NewClient(ctx, option.WithCredentialsFile(os.Getenv(gcsCredsEnv))) + client, err := storage.NewClient(ctx, + option.WithCredentialsFile(os.Getenv(gcsCredsEnv)), + option.WithUserAgent(version.UserAgent)) if err != nil { return nil, err } diff --git a/pkg/handler/collector/oci/oci.go b/pkg/handler/collector/oci/oci.go index 18756413c0..2569f5dd24 100644 --- a/pkg/handler/collector/oci/oci.go +++ b/pkg/handler/collector/oci/oci.go @@ -24,6 +24,7 @@ import ( "github.com/guacsec/guac/pkg/collectsub/datasource" "github.com/guacsec/guac/pkg/handler/processor" "github.com/guacsec/guac/pkg/logging" + "github.com/guacsec/guac/pkg/version" "github.com/pkg/errors" "github.com/regclient/regclient" "github.com/regclient/regclient/types/manifest" @@ -128,6 +129,7 @@ func (o *ociCollector) getTagsAndFetch(ctx context.Context, repo string, tags [] rcOpts := []regclient.Opt{} rcOpts = append(rcOpts, regclient.WithDockerCreds()) rcOpts = append(rcOpts, regclient.WithDockerCerts()) + rcOpts = append(rcOpts, regclient.WithUserAgent(version.UserAgent)) if len(tags) > 0 { for _, tag := range tags {