https://github.com/jayco/buildkite-auth
Simple client to authenticate against the Buildkite API
https://github.com/jayco/buildkite-auth
Last synced: 6 months ago
JSON representation
Simple client to authenticate against the Buildkite API
- Host: GitHub
- URL: https://github.com/jayco/buildkite-auth
- Owner: jayco
- License: mit
- Created: 2021-07-29T08:44:05.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-31T13:07:45.000Z (almost 5 years ago)
- Last Synced: 2024-06-21T12:52:11.963Z (about 2 years ago)
- Language: Go
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# buildkite-auth [](https://buildkite.com/jayco/buildkite-auth)[](https://pkg.go.dev/github.com/jayco/buildkite-auth/v2)
Simple client to authenticate against the Buildkite API (V2)
# Installation
To get the package:
```shell
go get github.com/jayco/buildkite-auth/v2
```
# API
## Data Structures
### TokenResponse
```go
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.
```go
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.
```go
host := c.GetHost()
log.Println(host)
```
```shell
➜ 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](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.
```go
resp, err := c.TokenScopes()
log.Println(resp)
```
```shell
➜ 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](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.
```go
resp, err := c.RevokeToken()
log.Println(resp)
```
```shell
➜ bkstats go run main.go
2021/07/29 19:40:07 &{ [] 204 No Content}
```