buildkite-auth
Simple client to authenticate against the Buildkite API (V2)
Installation
To get the package:
go get github.com/jayco/buildkite-auth/v2
API
Data Structures
TokenResponse
type TokenResponse struct {
UUID string `json:"uuid,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Message string `json:"message,omitempty"`
}
Methods
NewClient(ctx context.Context, apiToken string) *Client
Returns a new Auth Client.
package main
import (
"log"
"github.com/jayco/buildkite-auth/v2"
)
func main() {
c := client.NewClient(context.Background(), "your-api-token")
}
GetHost() string
Return the host URL of the client.
host := c.GetHost()
log.Println(host)
➜ go run main.go
2021/07/31 22:30:52 https://api.buildkite.com/v2
TokenScopes() (*TokenResponse, error)
Maps to GET https://buildkite.com/docs/rest-api/access-token
Get the current token
Returns details about the API Access Token that was used to authenticate the request.
resp, err := c.TokenScopes()
log.Println(resp)
➜ go run main.go
2021/07/29 18:25:52 &{12346789-o98u-hy65-okj7-9876yt54re32 [read_agents write_agents read_teams read_artifacts write_artifacts read_builds write_builds read_job_env read_build_logs write_build_logs read_organizations read_pipelines write_pipelines read_user graphql] }
RevokeToken() (*TokenResponse, error)
Maps to DELETE https://buildkite.com/docs/rest-api/access-token
Revokes the API Access Token that was used to authenticate the request. Once revoked, the token can no longer be used for further requests.
resp, err := c.RevokeToken()
log.Println(resp)
➜ bkstats go run main.go
2021/07/29 19:40:07 &{ [] 204 No Content}