api

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APICallRequest

type APICallRequest struct {
	AuthIndex string            `json:"auth_index,omitempty"`
	Method    string            `json:"method"`
	URL       string            `json:"url"`
	Header    map[string]string `json:"header,omitempty"`
	Data      string            `json:"data,omitempty"`
}

APICallRequest is the request body accepted by POST /api-call.

type APICallResponse

type APICallResponse struct {
	StatusCode int         `json:"status_code"`
	Header     http.Header `json:"header"`
	Body       []byte      `json:"body"`
}

APICallResponse preserves the upstream status independently of the Management API HTTP status. Body contains decoded string bytes or raw nested JSON bytes, depending on the upstream response shape.

type APIError

type APIError struct {
	StatusCode int    `json:"status_code"`
	Code       string `json:"code"`
	Message    string `json:"message"`
}

APIError classifies a non-successful Management API response.

func (*APIError) Error

func (e *APIError) Error() string

Error deliberately excludes the upstream message so a reflected credential or Authorization header can never enter logs through error formatting.

type AuthFile

type AuthFile struct {
	ID            string `json:"id"`
	AuthIndex     string `json:"auth_index"`
	Name          string `json:"name"`
	Provider      string `json:"provider"`
	Type          string `json:"type"`
	Account       string `json:"account"`
	Email         string `json:"email"`
	Status        string `json:"status"`
	StatusMessage string `json:"status_message"`
	Disabled      bool   `json:"disabled"`
	Unavailable   bool   `json:"unavailable"`
	RuntimeOnly   bool   `json:"runtime_only"`
	UpdatedAt     string `json:"updated_at"`
	// Presence flags distinguish the auth-dir fallback response from an
	// explicit runtime state. A JSON null is not a known boolean state.
	DisabledPresent    bool                       `json:"-"`
	UnavailablePresent bool                       `json:"-"`
	RuntimeOnlyPresent bool                       `json:"-"`
	Raw                map[string]json.RawMessage `json:"-"`
}

AuthFile is the stable subset of GET /auth-files used by the CLI. Raw keeps upstream fields that are not yet modelled, including the distinction between an absent fallback field and its Go zero value.

func (*AuthFile) UnmarshalJSON

func (f *AuthFile) UnmarshalJSON(data []byte) error

UnmarshalJSON retains fields not represented by AuthFile without deriving values for fields omitted by the auth-dir fallback response.

type Client

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

Client calls one CLIProxyAPI Management API origin.

func New

func New(baseURL, managementKey string, httpClient *http.Client) (*Client, error)

New creates a client for a full Management API base URL, normally ending in /v0/management. Redirects are disabled on a copy of the supplied client so the bearer credential cannot cross origins.

func (*Client) APICall

func (c *Client) APICall(ctx context.Context, request APICallRequest) (APICallResponse, error)

APICall asks CLIProxyAPI to make an authenticated upstream request. A non-2xx StatusCode belongs to that upstream response and is returned normally when the Management API itself answered successfully.

func (*Client) ListAuthFiles

func (c *Client) ListAuthFiles(ctx context.Context) ([]AuthFile, error)

ListAuthFiles returns auth files in exactly the order supplied by the Management API.

func (*Client) Raw

func (c *Client) Raw(ctx context.Context, method, relativePath string, body []byte) (RawResponse, error)

Raw calls a path below the configured Management API base and preserves the successful Management HTTP status, headers, and body.

func (*Client) RawRequest

func (c *Client) RawRequest(ctx context.Context, method, relativePath string, body []byte) ([]byte, error)

RawRequest calls a path below the configured Management API base. It rejects URLs and traversal before constructing the request target.

func (*Client) SetAuthFileDisabled

func (c *Client) SetAuthFileDisabled(ctx context.Context, name, authIndex string, disabled bool) error

SetAuthFileDisabled changes one auth record. It performs one PATCH attempt; retry policy belongs to the caller and must account for ambiguous writes.

func (*Client) ValidateRelativePath added in v1.0.3

func (c *Client) ValidateRelativePath(relativePath string) error

ValidateRelativePath reports whether a raw request path resolves below the configured Management API base, using the same rules the execute path applies. Callers use it to reject a bad path while previewing, so a dry-run never hands back a confirm token for a request that cannot run.

type RawResponse

type RawResponse struct {
	StatusCode int         `json:"status_code"`
	Header     http.Header `json:"header"`
	Body       []byte      `json:"body"`
}

RawResponse preserves the successful Management API HTTP response metadata.

Jump to

Keyboard shortcuts

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