Skip to content

Commit

Permalink
Validate the selected http client profile and keep a list
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfeidau committed Jan 28, 2025
1 parent 1011a41 commit a6ea19e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions clicommand/agent_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"github.com/buildkite/agent/v3/api"
"github.com/buildkite/agent/v3/core"
"github.com/buildkite/agent/v3/internal/agentapi"
"github.com/buildkite/agent/v3/internal/agenthttp"
"github.com/buildkite/agent/v3/internal/awslib"
awssigner "github.com/buildkite/agent/v3/internal/cryptosigner/aws"
"github.com/buildkite/agent/v3/internal/experiments"
Expand Down Expand Up @@ -1103,6 +1104,10 @@ var AgentStartCommand = cli.Command{

l.Info("Using http client profile: %s", cfg.HTTPClientProfile)

if !slices.Contains(agenthttp.ValidHTTPClientProfiles, cfg.HTTPClientProfile) {
l.Fatal("HTTP client profile %s is not in list of valid profiles: %v", cfg.HTTPClientProfile, agenthttp.ValidHTTPClientProfiles)
}

if len(cfg.AllowedRepositories) > 0 {
agentConf.AllowedRepositories = make([]*regexp.Regexp, 0, len(cfg.AllowedRepositories))
for _, v := range cfg.AllowedRepositories {
Expand Down
4 changes: 2 additions & 2 deletions clicommand/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ var (

HTTPClientProfileFlag = cli.StringFlag{
Name: "http-client-profile",
Usage: "Enable a http client profile, either standard, gcp or stdlib",
Value: "standard",
Usage: "Enable a http client profile, either default or stdlib",
Value: "default",
EnvVar: "BUILDKITE_AGENT_HTTP_CLIENT_PROFILE",
}

Expand Down
6 changes: 6 additions & 0 deletions internal/agenthttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"golang.org/x/net/http2"
)

var (
ValidHTTPClientProfiles = []string{"stdlib", "default"}
)

// NewClient creates a HTTP client. Note that the default timeout is 60 seconds;
// for some use cases (e.g. artifact operations) use [WithNoTimeout].
func NewClient(opts ...ClientOption) *http.Client {
Expand Down Expand Up @@ -47,6 +51,8 @@ func NewClient(opts ...ClientOption) *http.Client {
}
}

// fall back to the default http client profile

cacheKey := transportCacheKey{
AllowHTTP2: conf.AllowHTTP2,
TLSConfig: conf.TLSConfig,
Expand Down

0 comments on commit a6ea19e

Please sign in to comment.