apiclient

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 12 Imported by: 0

README

Legacy appliance API client

This package retains the appliance HTTP client and protocol constants for existing integrations. The desktop CLI has no hosted authentication or upload commands and does not link this client.

CLI protocol

Requests name the client protocol in X-Baum-CLI-Protocol. Responses name the supported range in X-Baum-CLI-Protocol-Min and X-Baum-CLI-Protocol-Max. A client outside that range stops with an error identifying which side needs updating. A response without a range counts as protocol 1, except a 5xx response, which may come from a proxy rather than the appliance.

Protocol changes when the client contract changes, including the supported upload manifest version. The appliance retains these constants for older clients; removing desktop CLI commands does not remove its API endpoints.

Documentation

Overview

Package apiclient retains the legacy appliance HTTP client and shared protocol constants. The desktop CLI does not use this client.

Index

Constants

View Source
const (
	GateRequiredHeader      = "X-Baum-Gate"
	GateRequiredHeaderValue = "required"
)

GateRequiredHeader marks a response a deployment's shared-password gate refused, rather than ordinary authentication. Clients key off the header because 403 alone cannot be told apart from a real authorization failure. The server's gate sets these values, so they live here, where both sides read them.

View Source
const (
	ProtocolHeader    = "X-Baum-CLI-Protocol"
	MinProtocolHeader = "X-Baum-CLI-Protocol-Min"
	MaxProtocolHeader = "X-Baum-CLI-Protocol-Max"
)

The handshake headers. Every request names the client's protocol, and every response of a server that knows the handshake names the range it accepts.

View Source
const Protocol = 1

Protocol is the version of the hosted API contract this client speaks. One baum binary runs against servers of many releases, so the two agree on this number rather than on release versions: raise it when the client starts to depend on an API change a server of an earlier release does not have, or stops working with one it used to. A server built from the same commit accepts it, because it advertises this value as its maximum.

Variables

View Source
var (
	ErrAuthorizationPending = errors.New("authorization_pending")
	ErrSlowDown             = errors.New("slow_down")
	ErrExpiredToken         = errors.New("expired_token")
	ErrAccessDenied         = errors.New("access_denied")

	// ErrUnauthenticated is any 401 answer: a missing, revoked, or expired
	// API token. A gated deployment refuses an unusable bearer token with 403
	// and X-Baum-Gate: required instead, because it never learns
	// whether the token was bad or merely absent; since a valid token always
	// passes the gate, that answer means the same thing to a client that sent
	// one.
	ErrUnauthenticated = errors.New("unauthenticated")
)

Device-flow poll answers, matching the RFC 8628 error strings the server uses as client-safe messages.

Functions

This section is empty.

Types

type Client

type Client struct {
	BaseURL string
	Token   string
	HTTP    *http.Client
	// UserAgent, when set, names the client and its version in requests.
	UserAgent string
}

Client calls the baum API. Token, when set, is sent as a bearer credential.

func (*Client) FindGitHubRepository

func (c *Client) FindGitHubRepository(ctx context.Context, fullName string) (GitHubRepository, error)

FindGitHubRepository returns one connected repository by its GitHub full name.

func (*Client) ListGitHubInstallations

func (c *Client) ListGitHubInstallations(ctx context.Context) ([]GitHubRepository, error)

ListGitHubInstallations returns every non-archived repository connected to the authenticated user, flattened across GitHub App installations.

func (*Client) Me

func (c *Client) Me(ctx context.Context) (User, error)

Me returns the user the client's token authenticates as.

func (*Client) PollDeviceToken

func (c *Client) PollDeviceToken(ctx context.Context, deviceCode string) (DeviceToken, error)

PollDeviceToken asks whether the device login was approved. Pending, throttled, denied, and expired answers surface as the package sentinels.

func (*Client) RequestGitHubRepositorySync

func (c *Client) RequestGitHubRepositorySync(ctx context.Context, repositoryID string) error

RequestGitHubRepositorySync queues synchronization for a repository.

func (*Client) RevokeCurrentToken

func (c *Client) RevokeCurrentToken(ctx context.Context) error

RevokeCurrentToken revokes the token this client authenticates with.

func (*Client) StartDeviceAuthorization

func (c *Client) StartDeviceAuthorization(ctx context.Context, name string) (DeviceAuthorizationStart, error)

StartDeviceAuthorization opens a device-flow login named after the device.

func (*Client) UploadRepositoryTraces

func (c *Client) UploadRepositoryTraces(ctx context.Context, repositoryID string, archive io.Reader, size int64) error

UploadRepositoryTraces streams a tar.gz trace bundle to a repository.

type DeviceAuthorizationStart

type DeviceAuthorizationStart struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	VerificationURIComplete string `json:"verification_uri_complete"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
}

DeviceAuthorizationStart mirrors the POST /auth/device response.

type DeviceToken

type DeviceToken struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
	User      User      `json:"user"`
}

DeviceToken mirrors the POST /auth/device/token success response.

type GitHubRepository

type GitHubRepository struct {
	ID       string `json:"id"`
	FullName string `json:"full_name"`
	// Enabled is baum's own switch; the server works on a repository only while
	// it is on.
	Enabled bool `json:"enabled"`
}

GitHubRepository is a repository connected to the authenticated user.

type IncompatibleServerError

type IncompatibleServerError struct {
	Server   string
	Client   int
	Min, Max int
	// Legacy is a server that predates the handshake.
	Legacy bool
}

IncompatibleServerError says the client and the server it called cannot work together, and which side has to be updated.

func (*IncompatibleServerError) Error

func (e *IncompatibleServerError) Error() string

type User

type User struct {
	ID          string  `json:"id"`
	GitHubLogin string  `json:"github_login"`
	Name        *string `json:"name"`
	Email       *string `json:"email"`
}

User mirrors the GET /api/me response.

Jump to

Keyboard shortcuts

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