Documentation
¶
Index ¶
- Constants
- Variables
- func AuthBaseURL() string
- func BaseURL() string
- func CheckResponse(resp *http.Response) error
- func DecodeJSON(resp *http.Response, dest any) error
- func IsHTTPErrorStatus(err error, status int) bool
- func NormalizeOriginURL(raw string) string
- func OriginOnly(raw string) string
- func RequireSecureURL(baseURL string) error
- func ResolveURL(path string) (string, error)
- func ResolveURLFromBase(baseURL, path string) (string, error)
- type Client
- func (c *Client) Delete(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)
- func (c *Client) GetStream(ctx context.Context, path string, headers http.Header) (*http.Response, error)
- func (c *Client) ListRepositories(ctx context.Context, sort RepositorySort) ([]Repository, error)
- func (c *Client) ListTokens(ctx context.Context) ([]Token, error)
- func (c *Client) Patch(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) Post(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) Put(ctx context.Context, path string, body any) (*http.Response, error)
- func (c *Client) RevokeCurrentToken(ctx context.Context) error
- func (c *Client) RevokeToken(ctx context.Context, id string) error
- func (c *Client) WithAuthTokensPath(path string) *Client
- type ErrorResponse
- type HTTPError
- type RepositoriesResponse
- type Repository
- type RepositorySort
- type Token
- type TokensResponse
- type TrailCreateRequest
- type TrailCreateResponse
- type TrailDetailResponse
- type TrailListResponse
- type TrailResource
- type TrailUpdateRequest
- type TrailUpdateResponse
Constants ¶
const ( // DefaultBaseURL is the production Entire API origin. DefaultBaseURL = "https://entire.io" // BaseURLEnvVar overrides the Entire API origin for local development. BaseURLEnvVar = "ENTIRE_API_BASE_URL" // AuthBaseURLEnvVar overrides only the auth/login origin (device flow, // auth-tokens management, keyring key). Falls back to BaseURLEnvVar when // unset, which is the right behavior for single-host deployments. Split // hosts (e.g. auth on us.console.partial.to, data on partial.to) set // both. AuthBaseURLEnvVar = "ENTIRE_AUTH_BASE_URL" )
Variables ¶
var ErrInsecureHTTP = errors.New("refusing to use insecure http:// base URL for authentication (use --insecure-http-auth to override)")
ErrInsecureHTTP is returned when the base URL uses HTTP without an explicit opt-in.
Functions ¶
func AuthBaseURL ¶ added in v0.6.3
func AuthBaseURL() string
AuthBaseURL returns the origin used for the device-flow login, auth-token management endpoints, and the keyring key under which the bearer token is stored. ENTIRE_AUTH_BASE_URL takes precedence; otherwise it falls back to BaseURL() so single-host deployments keep working unchanged.
The result is canonicalised — lowercased scheme/host, default port stripped, path/query/fragment dropped, trailing slash collapsed — so the value that flows into store.SaveToken keys matches what tokenmanager.New emits after its own NormalizeOriginURL pass. Without this, a user setting ENTIRE_AUTH_BASE_URL=https://AUTH.example.com:443/ would log in successfully (saved under the raw form) but every subsequent data-API command would resolve "not logged in" because the manager probes under the normalised "https://auth.example.com".
func BaseURL ¶
func BaseURL() string
BaseURL returns the effective Entire API base URL. ENTIRE_API_BASE_URL takes precedence over the production default.
func CheckResponse ¶ added in v0.5.2
CheckResponse returns an error if the response status code indicates failure. For non-2xx responses, it reads and parses the error message from the body and returns it as an *HTTPError. The caller is responsible for closing resp.Body.
func DecodeJSON ¶ added in v0.5.2
DecodeJSON reads the response body and decodes it into dest. It limits the body size to protect against unbounded reads. The caller is responsible for closing resp.Body.
func IsHTTPErrorStatus ¶ added in v0.6.0
IsHTTPErrorStatus reports whether err wraps an *HTTPError with the given HTTP status.
func NormalizeOriginURL ¶ added in v0.6.3
NormalizeOriginURL canonicalises an origin URL the same way auth-go's tokenmanager does internally: lowercase scheme/host, default port stripped (80 for http, 443 for https), path/query/fragment dropped, trailing slash collapsed. On parse failure, raw is returned unchanged so non-URL audience values still compare byte-for-byte.
Mirrors auth-go's internal/oauthhttp.NormalizeOriginURL so the value the CLI hands to the manager as Issuer survives the manager's own normalisation pass byte-for-byte — see AuthBaseURL.
func OriginOnly ¶ added in v0.6.3
OriginOnly is a backwards-compatible alias for NormalizeOriginURL. Callers reading raw URLs (e.g. ENTIRE_SEARCH_URL) and feeding them into tokenmanager.TokenRequest.Resource use this to strip path/query/fragment before the lib's stricter origin-only validator runs.
func RequireSecureURL ¶
RequireSecureURL returns ErrInsecureHTTP if the base URL uses the http scheme. Call this before making authenticated requests unless --insecure-http-auth is set.
func ResolveURL ¶
ResolveURL joins an API-relative path against the effective base URL.
func ResolveURLFromBase ¶
ResolveURLFromBase joins an API-relative path against an explicit base URL. Only http and https schemes are accepted.
Types ¶
type Client ¶ added in v0.5.2
type Client struct {
// contains filtered or unexported fields
}
Client is an authenticated HTTP client for the Entire API. It attaches the bearer token to all outgoing requests via the Authorization header.
func NewClient ¶ added in v0.5.2
NewClient creates a new authenticated API client with an explicit bearer token, targeting the data API base URL (BaseURL()).
func NewClientWithBaseURL ¶ added in v0.6.3
NewClientWithBaseURL creates a new authenticated API client targeting an explicit base URL. Use this for endpoints that live on the auth host (e.g. auth-token management) when ENTIRE_AUTH_BASE_URL splits the auth origin from the data API origin.
func (*Client) Delete ¶ added in v0.5.2
Delete sends an authenticated DELETE request to the given API-relative path.
func (*Client) Get ¶ added in v0.5.2
Get sends an authenticated GET request to the given API-relative path.
func (*Client) GetStream ¶ added in v0.6.2
func (c *Client) GetStream(ctx context.Context, path string, headers http.Header) (*http.Response, error)
GetStream sends an authenticated GET request with optional extra request headers (e.g. Accept: text/event-stream, Last-Event-ID) and returns the response with the body still open. Callers are responsible for reading and closing resp.Body. Intended for streaming endpoints such as Server-Sent Events; for normal JSON requests use Get.
func (*Client) ListRepositories ¶ added in v0.5.6
func (c *Client) ListRepositories(ctx context.Context, sort RepositorySort) ([]Repository, error)
ListRepositories lists the authenticated user's repositories. An empty sort uses the server default.
func (*Client) ListTokens ¶ added in v0.6.0
ListTokens returns the authenticated user's non-expired API tokens.
func (*Client) Patch ¶ added in v0.5.2
Patch sends an authenticated PATCH request with a JSON body to the given API-relative path.
func (*Client) Post ¶ added in v0.5.2
Post sends an authenticated POST request with a JSON body to the given API-relative path.
func (*Client) Put ¶ added in v0.5.2
Put sends an authenticated PUT request with a JSON body to the given API-relative path.
func (*Client) RevokeCurrentToken ¶ added in v0.6.0
RevokeCurrentToken revokes the bearer token used to authenticate this client.
func (*Client) RevokeToken ¶ added in v0.6.0
RevokeToken revokes the API token with the given id.
func (*Client) WithAuthTokensPath ¶ added in v0.6.3
WithAuthTokensPath sets the base path used by ListTokens, RevokeCurrentToken, and RevokeToken. The path is supplied by the auth shim from auth.CurrentProvider().AuthTokensPath, which is the single source of truth for provider-version routing — the api package no longer reads ENTIRE_AUTH_PROVIDER_VERSION itself.
Returns the receiver for chaining at construction:
c := api.NewClientWithBaseURL(token, base).WithAuthTokensPath(p)
type ErrorResponse ¶ added in v0.5.2
type ErrorResponse struct {
Error any `json:"error"`
}
ErrorResponse represents a standard API error response. Older endpoints return {"error":"message"}; newer endpoints return {"error":{"code":"...","message":"...",...}}.
func (ErrorResponse) Message ¶ added in v0.6.3
func (e ErrorResponse) Message() string
Message extracts the human-readable error message from either envelope shape.
type HTTPError ¶ added in v0.6.0
HTTPError is returned by CheckResponse for non-2xx responses. Callers can use errors.As to inspect the HTTP status, or IsHTTPErrorStatus for a quick check.
type RepositoriesResponse ¶ added in v0.5.6
type RepositoriesResponse struct {
Repositories []Repository `json:"repositories"`
}
RepositoriesResponse is the envelope returned by GET /api/v1/repositories.
type Repository ¶ added in v0.5.6
type Repository struct {
FullName string `json:"full_name"`
CheckpointCount int `json:"checkpoint_count"`
}
Repository is a single entry returned by GET /api/v1/repositories. Only fields currently consumed by callers are decoded; extras are ignored.
type RepositorySort ¶ added in v0.5.6
type RepositorySort string
const ( RepositorySortRecent RepositorySort = "recent" RepositorySortName RepositorySort = "name" )
type Token ¶ added in v0.6.0
type Token struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Name string `json:"name"`
Scope string `json:"scope"`
ExpiresAt string `json:"expires_at"`
LastUsedAt *string `json:"last_used_at"`
CreatedAt string `json:"created_at"`
}
Token is a single API token row returned by the auth-tokens endpoint. Plaintext token values are never returned by the server — only metadata.
type TokensResponse ¶ added in v0.6.0
type TokensResponse struct {
Tokens []Token `json:"tokens"`
}
TokensResponse is the envelope returned by the list endpoint.
type TrailCreateRequest ¶ added in v0.5.2
type TrailCreateRequest struct {
Title string `json:"title"`
Body string `json:"body,omitempty"`
BranchName string `json:"branch_name"`
Base string `json:"base,omitempty"`
Status string `json:"status,omitempty"`
Assignees []string `json:"assignees,omitempty"`
Labels []string `json:"labels,omitempty"`
Priority string `json:"priority,omitempty"`
Type string `json:"type,omitempty"`
}
TrailCreateRequest is the body for POST /api/v1/trails/:host/:owner/:repo.
type TrailCreateResponse ¶ added in v0.5.2
type TrailCreateResponse struct {
Trail TrailResource `json:"trail"`
BranchCreated bool `json:"branch_created"`
}
TrailCreateResponse is the response from POST /api/v1/trails/:org/:repo.
type TrailDetailResponse ¶ added in v0.5.2
type TrailDetailResponse struct {
Trail TrailResource `json:"trail"`
Discussion trail.Discussion `json:"discussion"`
Checkpoints trail.Checkpoints `json:"checkpoints"`
}
TrailDetailResponse is the response from GET /api/v1/trails/:org/:repo/:trailId.
type TrailListResponse ¶ added in v0.5.2
type TrailListResponse struct {
Trails []TrailResource `json:"trails"`
RepoFullName string `json:"repo_full_name"`
DefaultBranch string `json:"default_branch"`
UpdatedAt time.Time `json:"updated_at"`
}
TrailListResponse is the response from GET /api/v1/trails/:org/:repo.
type TrailResource ¶ added in v0.5.2
type TrailResource struct {
ID string `json:"id,omitempty"`
Number int `json:"number,omitempty"`
Branch string `json:"branch"`
Base string `json:"base"`
Title string `json:"title"`
Body string `json:"body"`
Status string `json:"status"`
Author *trail.Author `json:"author"`
Assignees []string `json:"assignees"`
Labels []string `json:"labels"`
Priority string `json:"priority,omitempty"`
Type string `json:"type,omitempty"`
Reviewers []trail.Reviewer `json:"reviewers,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
MergedAt *time.Time `json:"merged_at,omitempty"`
CommentCount int `json:"comment_count,omitempty"`
UnresolvedCount int `json:"unresolved_count,omitempty"`
CheckpointCount int `json:"checkpoint_count,omitempty"`
CommitsAhead int `json:"commits_ahead,omitempty"`
}
TrailResource represents a single trail from the API.
func (*TrailResource) ToMetadata ¶ added in v0.5.2
func (r *TrailResource) ToMetadata() *trail.Metadata
ToMetadata converts a TrailResource to a trail.Metadata for display.
type TrailUpdateRequest ¶ added in v0.5.2
type TrailUpdateRequest struct {
Branch *string `json:"branch,omitempty"`
Base *string `json:"base,omitempty"`
Status *string `json:"status,omitempty"`
Title *string `json:"title,omitempty"`
Body *string `json:"body,omitempty"`
Assignees *[]string `json:"assignees,omitempty"`
Labels *[]string `json:"labels,omitempty"`
Priority *string `json:"priority,omitempty"`
Type *string `json:"type,omitempty"`
}
TrailUpdateRequest is the body for PATCH /api/v1/trails/:host/:owner/:repo/:trailId. Pointer fields distinguish "not provided" (nil) from "set to value". For slices, *[]string is used so nil means "no change" while &[]string{} means "clear".
type TrailUpdateResponse ¶ added in v0.5.2
type TrailUpdateResponse struct {
Trail TrailResource `json:"trail"`
}
TrailUpdateResponse is the response from PATCH /api/v1/trails/:org/:repo/:trailId.