-
Notifications
You must be signed in to change notification settings - Fork 51
PIPE-1084: remove org as stack parameter #609
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package api | ||
|
|
||
| import ( | ||
| "context" | ||
| "net/http" | ||
| "net/url" | ||
| "time" | ||
| ) | ||
|
|
||
| // This is a special agent client: it can only be used to query the GET /token API. | ||
| // Meaning for this client to function, there isn't a need for a cluster id nor queue id. | ||
| func NewAgentTokenClient(token, endpoint string) (*AgentTokenClient, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we combine this with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was my plan but
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, you showed that
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see what you mean now. I agree. |
||
| if endpoint == "" { | ||
| endpoint = "https://agent.buildkite.com/v3" | ||
| } | ||
| endpointURL, err := url.Parse(endpoint) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return &AgentTokenClient{ | ||
| endpoint: endpointURL, | ||
| httpClient: &http.Client{ | ||
| Timeout: 60 * time.Second, | ||
| Transport: NewLogger(NewAuthedTransportWithToken(http.DefaultTransport, token)), | ||
| }, | ||
| }, nil | ||
| } | ||
|
|
||
| type AgentTokenClient struct { | ||
| endpoint *url.URL | ||
| httpClient *http.Client | ||
| } | ||
|
|
||
| // AgentTokenIdentity describes the token identity information. | ||
| type AgentTokenIdentity struct { | ||
| UUID string `json:"uuid"` | ||
| Description string `json:"description"` | ||
| TokenType string `json:"token_type"` | ||
| OrganizationSlug string `json:"organization_slug"` | ||
| OrganizationUUID string `json:"organization_uuid"` | ||
| ClusterUUID string `json:"cluster_uuid"` | ||
| ClusterName string `json:"cluster_name"` | ||
| OrganizationQueueUUID string `json:"organization_queue_uuid"` | ||
| OrganizationQueueKey string `json:"organization_queue_key"` | ||
| } | ||
|
|
||
| // GetJobState gets the state of a specific job. | ||
| func (c *AgentTokenClient) GetTokenIdentity(ctx context.Context) (result *AgentTokenIdentity, retryAfter time.Duration, err error) { | ||
| u := c.endpoint.JoinPath("token") | ||
|
|
||
| resp, err := c.httpClient.Get(u.String()) | ||
| if err != nil { | ||
| return nil, 0, err | ||
| } | ||
| defer resp.Body.Close() | ||
|
|
||
| return decodeResponse[AgentTokenIdentity](resp) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.