Documentation
¶
Overview ¶
Package apiclient retains the legacy appliance HTTP client and shared protocol constants. The desktop CLI does not use this client.
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) FindGitHubRepository(ctx context.Context, fullName string) (GitHubRepository, error)
- func (c *Client) ListGitHubInstallations(ctx context.Context) ([]GitHubRepository, error)
- func (c *Client) Me(ctx context.Context) (User, error)
- func (c *Client) PollDeviceToken(ctx context.Context, deviceCode string) (DeviceToken, error)
- func (c *Client) RequestGitHubRepositorySync(ctx context.Context, repositoryID string) error
- func (c *Client) RevokeCurrentToken(ctx context.Context) error
- func (c *Client) StartDeviceAuthorization(ctx context.Context, name string) (DeviceAuthorizationStart, error)
- func (c *Client) UploadRepositoryTraces(ctx context.Context, repositoryID string, archive io.Reader, size int64) error
- type DeviceAuthorizationStart
- type DeviceToken
- type GitHubRepository
- type IncompatibleServerError
- type User
Constants ¶
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.
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.
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 ¶
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) PollDeviceToken ¶
PollDeviceToken asks whether the device login was approved. Pending, throttled, denied, and expired answers surface as the package sentinels.
func (*Client) RequestGitHubRepositorySync ¶
RequestGitHubRepositorySync queues synchronization for a repository.
func (*Client) RevokeCurrentToken ¶
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.
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