auth

package module
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2021 License: MIT Imports: 6 Imported by: 0

README

buildkite-auth Build statusGo Reference

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}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*http.Client
	Host string
}

Client for authing

func NewClient

func NewClient(ctx context.Context, apiToken string) *Client

NewClient with bearer token

func (*Client) GetHost

func (c *Client) GetHost() string

GetHost URL

func (*Client) RevokeToken

func (c *Client) RevokeToken() (*TokenResponse, error)

RevokeToken of the client https://buildkite.com/docs/rest-api/access-token

func (*Client) TokenScopes

func (c *Client) TokenScopes() (*TokenResponse, error)

TokenScopes of the client https://buildkite.com/docs/rest-api/access-token

type TokenResponse

type TokenResponse struct {
	UUID    string   `json:"uuid,omitempty"`
	Scopes  []string `json:"scopes,omitempty"`
	Message string   `json:"message,omitempty"`
}

TokenResponse from API

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL