NewAgentTokenClient creates a new AgentTokenClient.
(opts AgentTokenClientOpts)
| 37 | |
| 38 | // NewAgentTokenClient creates a new AgentTokenClient. |
| 39 | func 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. |
| 74 | type AgentTokenIdentity struct { |
no test coverage detected