github.com/pquerna/agent@v2.1.8+incompatible/agent/api_client.go (about) 1 package agent 2 3 import ( 4 "net" 5 "net/http" 6 "net/url" 7 "runtime" 8 "time" 9 10 "github.com/buildkite/agent/api" 11 ) 12 13 var debug = false 14 15 type APIClient struct { 16 Endpoint string 17 Token string 18 } 19 20 func APIClientEnableHTTPDebug() { 21 debug = true 22 } 23 24 func (a APIClient) Create() *api.Client { 25 // Create the transport used when making the Buildkite Agent API calls 26 transport := &api.AuthenticatedTransport{ 27 Token: a.Token, 28 Transport: &http.Transport{ 29 Proxy: http.ProxyFromEnvironment, 30 DisableKeepAlives: false, 31 DisableCompression: false, 32 Dial: (&net.Dialer{ 33 Timeout: 30 * time.Second, 34 KeepAlive: 30 * time.Second, 35 }).Dial, 36 TLSHandshakeTimeout: 30 * time.Second, 37 }, 38 } 39 40 // From the transport, create the a http client 41 httpClient := transport.Client() 42 httpClient.Timeout = 60 * time.Second 43 44 // Create the Buildkite Agent API Client 45 client := api.NewClient(httpClient) 46 client.BaseURL, _ = url.Parse(a.Endpoint) 47 client.UserAgent = a.UserAgent() 48 client.DebugHTTP = debug 49 50 return client 51 } 52 53 func (a APIClient) UserAgent() string { 54 return "buildkite-agent/" + Version() + " (" + runtime.GOOS + "; " + runtime.GOARCH + ")" 55 }