client

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package client provides the authenticated REST/SSE Harbor Protocol client.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidConnection reports an unusable base URL or token source.
	ErrInvalidConnection = errors.New("protocol client: invalid connection")
	// ErrTokenRequired reports that the token source returned an empty token.
	ErrTokenRequired = errors.New("protocol client: bearer token required")
	// ErrTokenIdentityMismatch reports that a token cannot authenticate the requested identity.
	ErrTokenIdentityMismatch = errors.New("protocol client: bearer token identity mismatch")
	// ErrIdentityRequired reports an incomplete client isolation identity.
	ErrIdentityRequired = errors.New("protocol client: complete identity required")
	// ErrResponseTooLarge reports a response beyond the configured safety bound.
	ErrResponseTooLarge = errors.New("protocol client: response body too large")
	// ErrMalformedResponse reports invalid or non-canonical response JSON.
	ErrMalformedResponse = errors.New("protocol client: malformed response")
	// ErrIncompatibleProtocol reports a Runtime with a different Protocol major.
	ErrIncompatibleProtocol = errors.New("protocol client: incompatible Protocol version")
)
View Source
var (
	// ErrMalformedSSE reports invalid framing or a non-JSON data payload.
	ErrMalformedSSE = errors.New("protocol client: malformed SSE frame")
	// ErrSSELineTooLarge reports an SSE field line beyond its safety bound.
	ErrSSELineTooLarge = errors.New("protocol client: SSE line too large")
	// ErrSSEFrameTooLarge reports an SSE frame beyond its safety bound.
	ErrSSEFrameTooLarge = errors.New("protocol client: SSE frame too large")
	// ErrStreamClosed reports Recv on an explicitly closed stream.
	ErrStreamClosed = errors.New("protocol client: event stream closed")
)

Functions

This section is empty.

Types

type Client

Client is the supported immutable, concurrent-safe Protocol attachment.

func New

func New(conn Connection, opts ...Option) (Client, error)

New constructs a Protocol client. An explicit identity is copied at the boundary and must be complete; it may be omitted when the verified JWT is the sole identity carrier. TokenSource receives the selected scope for every REST and SSE request.

type Connection

type Connection struct {
	BaseURL  string
	Token    TokenSource
	Identity types.IdentityScope
}

Connection describes one authenticated Runtime attachment.

type EventStream

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

EventStream owns one HTTP response and reader goroutine. Close is idempotent, cancels the request, closes the body, and joins the reader.

func (*EventStream) Close

func (s *EventStream) Close() error

Close cancels and joins the stream reader. It is safe to call repeatedly.

func (*EventStream) Recv

func (s *EventStream) Recv(ctx context.Context) (SSEFrame, error)

Recv waits for the next frame. Cancelling this receive does not close the stream; cancelling the Subscribe context or calling Close does.

type Option

type Option func(*config)

Option configures a Client at construction.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient supplies the HTTP client used for REST and SSE requests. A nil value is ignored.

func WithResponseLimits

func WithResponseLimits(successBytes, errorBytes int64) Option

WithResponseLimits overrides the success and error body bounds. Non-positive values retain their defaults.

type ProtocolError

type ProtocolError struct {
	Status  int
	Code    protoerrors.Code
	Message string
	Cause   error
}

ProtocolError is a typed REST or pre-stream Protocol failure.

func (*ProtocolError) Error

func (e *ProtocolError) Error() string

Error implements error.

func (*ProtocolError) Unwrap

func (e *ProtocolError) Unwrap() error

Unwrap returns the response decoding cause, when present.

type RuntimeClient

RuntimeClient is the additive Runtime inspection/control client consumed by the native TUI. Narrow projection consumers continue to depend on Client.

type SSEFrame

type SSEFrame struct {
	Event   string
	ID      string
	Data    json.RawMessage
	Comment string
	Retry   time.Duration
}

SSEFrame is one decoded Server-Sent Events frame. Data is retained as strict JSON so reducers can select their own canonical event payload projection.

type StreamOptions

type StreamOptions struct {
	RunID       string
	EventTypes  []string
	LastEventID string
	Admin       bool
}

StreamOptions selects one identity-scoped event stream. Reconnect policy is caller-owned; LastEventID is the cursor supplied for this connection.

type TokenSource

type TokenSource interface {
	Token(context.Context, types.IdentityScope) (string, error)
}

TokenSource resolves a bearer token for each requested identity. The scope is an isolated copy and may include the complete impersonation chain. Sources must be safe for concurrent use and must reject identities they cannot authenticate rather than returning a token for a different session.

func StaticToken

func StaticToken(token string, principal types.IdentityScope) TokenSource

StaticToken returns a token source bound to principal. It rejects a regular session clone because one JWT cannot authenticate another session. For impersonation, principal is matched against Actor while the target may vary.

type TokenSourceFunc

type TokenSourceFunc func(context.Context, types.IdentityScope) (string, error)

TokenSourceFunc adapts a function to TokenSource.

func (TokenSourceFunc) Token

Token calls f with an isolated identity copy.

Jump to

Keyboard shortcuts

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