jobapi

package
v3.46.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 24 Imported by: 1

Documentation

Overview

jobapi provides an API with which to interact with and mutate the currently executing job Pronunciation: /ˈdʒɑbapi/ /joh-bah-pee/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthMiddleware

func AuthMiddleware(token string) func(http.Handler) http.Handler

AuthMiddleware is a middleware that checks the Authorization header of an incoming request for a Bearer token and checks that that token is the correct one.

func Available

func Available() bool

func DefaultSocketPath

func DefaultSocketPath() (path, token string, err error)

DefaultSocketPath returns the socket path and access token, if available.

func HeadersMiddleware

func HeadersMiddleware(next http.Handler) http.Handler

HeadersMiddleware is a middleware that sets the common headers for all responses. At the moment, this is just Content-Type: application/json.

func LoggerMiddleware

func LoggerMiddleware(l shell.Logger) func(http.Handler) http.Handler

func NewSocketPath

func NewSocketPath(base string) (string, error)

NewSocketPath generates a path to a socket file (without actually creating the file itself) that can be used with the job api.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client connects to the Job API.

func NewClient

func NewClient(sock, token string) (*Client, error)

NewClient creates a new Client.

func NewDefaultClient

func NewDefaultClient() (*Client, error)

NewDefaultClient returns a new Client with the default socket path and token.

func (*Client) EnvDelete

func (c *Client) EnvDelete(ctx context.Context, del []string) (deleted []string, err error)

EnvDelete deletes environment variables within the job executor.

func (*Client) EnvGet

func (c *Client) EnvGet(ctx context.Context) (map[string]string, error)

EnvGet gets the current environment variables from within the job executor.

func (*Client) EnvUpdate

func (c *Client) EnvUpdate(ctx context.Context, req *EnvUpdateRequest) (*EnvUpdateResponse, error)

EnvUpdate updates environment variables within the job executor.

type EnvDeleteRequest

type EnvDeleteRequest struct {
	Keys []string `json:"keys"`
}

EnvDeleteRequest is the request body for the DELETE /env endpoint

type EnvDeleteResponse

type EnvDeleteResponse struct {
	Deleted []string `json:"deleted"`
}

EnvDeleteResponse is the response body for the DELETE /env endpoint

func (EnvDeleteResponse) Normalize

func (e EnvDeleteResponse) Normalize()

type EnvGetResponse

type EnvGetResponse struct {
	Env map[string]string `json:"env"` // Different to EnvUpdateRequest because we don't want to send nulls
}

EnvGetResponse is the response body for the GET /env endpoint

type EnvUpdateRequest

type EnvUpdateRequest struct {
	Env map[string]*string `json:"env"`
}

EnvUpdateRequest is the request body for the PATCH /env endpoint

type EnvUpdateResponse

type EnvUpdateResponse struct {
	Added   []string `json:"added"`
	Updated []string `json:"updated"`
}

EnvUpdateResponse is the response body for the PATCH /env endpoint

func (EnvUpdateResponse) Normalize

func (e EnvUpdateResponse) Normalize()

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

Error response is the response body for any errors that occur

type Server

type Server struct {
	// SocketPath is the path to the socket that the server is (or will be) listening on
	SocketPath string
	Logger     shell.Logger
	// contains filtered or unexported fields
}

Server is a Job API server. It provides an HTTP API with which to interact with the job currently running in the buildkite agent and allows jobs to introspect and mutate their own state

func NewServer

func NewServer(logger shell.Logger, socketPath string, environ *env.Environment) (server *Server, token string, err error)

NewServer creates a new Job API server socketPath is the path to the socket on which the server will listen environ is the environment which the server will mutate and inspect as part of its operation

func (*Server) Start

func (s *Server) Start() error

Start starts the server in a goroutine, returning an error if the server can't be started

func (*Server) Stop

func (s *Server) Stop() error

Stop gracefully shuts the server down, blocking until all requests have been served or the grace period has expired It returns an error if the server has not been started

Jump to

Keyboard shortcuts

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