Skip to content

Commit

Permalink
Add UserAgent to github, deps.dev, gcs, oci.
Browse files Browse the repository at this point in the history
Signed-off-by: Jeff Mendoza <[email protected]>
  • Loading branch information
jeffmendoza committed Apr 25, 2023
1 parent a594bed commit 41c4a6e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
8 changes: 7 additions & 1 deletion internal/client/githubclient/githubclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.
Expand Down
5 changes: 4 additions & 1 deletion pkg/handler/collector/deps_dev/deps_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/handler/collector/gcs/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/handler/collector/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 41c4a6e

Please sign in to comment.