Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce http client profile option for custom configuration #3165

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Validate the selected http client profile and keep a list
wolfeidau committed Feb 19, 2025
commit 5b03bac733b6fc65d2b406626abad40e0718222d
5 changes: 5 additions & 0 deletions clicommand/agent_start.go
Original file line number Diff line number Diff line change
@@ -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"
@@ -1122,6 +1123,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 {
4 changes: 2 additions & 2 deletions clicommand/global.go
Original file line number Diff line number Diff line change
@@ -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",
}

6 changes: 6 additions & 0 deletions internal/agenthttp/client.go
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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,