MCPcopy Create free account
hub / github.com/buildkite/agent-stack-k8s / NewAgentTokenClient

Function NewAgentTokenClient

api/agent_token_client.go:39–71  ·  view source on GitHub ↗

NewAgentTokenClient creates a new AgentTokenClient.

(opts AgentTokenClientOpts)

Source from the content-addressed store, hash-verified

37
38// NewAgentTokenClient creates a new AgentTokenClient.
39func NewAgentTokenClient(opts AgentTokenClientOpts) (*AgentTokenClient, error) {
40 if opts.Token == "" {
41 return nil, errors.New("token must not be empty")
42 }
43
44 if opts.Logger == nil {
45 opts.Logger = slog.New(slog.DiscardHandler)
46 }
47
48 httpTimeout := opts.HTTPTimeout
49 if httpTimeout == 0 {
50 httpTimeout = DefaultHTTPTimeout
51 }
52
53 endpoint := opts.Endpoint
54 if endpoint == "" {
55 endpoint = "https://agent.buildkite.com/v3"
56 }
57
58 endpointURL, err := url.Parse(endpoint)
59 if err != nil {
60 return nil, err
61 }
62
63 return &AgentTokenClient{
64 endpoint: endpointURL,
65 token: opts.Token,
66 httpClient: &http.Client{
67 Timeout: httpTimeout,
68 Transport: NewLogTransport(http.DefaultTransport, opts.Logger, opts.LogHTTPPayloads),
69 },
70 }, nil
71}
72
73// AgentTokenIdentity describes the token identity information.
74type AgentTokenIdentity struct {

Callers 1

RunFunction · 0.92

Calls 1

NewLogTransportFunction · 0.85

Tested by

no test coverage detected