api

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package api serves the /api/v1 endpoints used by the web app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SourceLink(base, version, commit string) string

SourceLink returns the URL of the source of the given build below base.

Types

type About

type About struct {
	Version   string `json:"version"`
	Commit    string `json:"commit"`
	SourceURL string `json:"source_url"` // link to exactly this version
}

About describes the running build.

type AdminStats

type AdminStats struct {
	Users           []AdminUserStats `json:"users"`
	Totals          AdminTotals      `json:"totals"`
	RebuildingUsers int              `json:"rebuilding_users"`
}

AdminStats is the response of GET /api/v1/admin/stats.

type AdminTotals

type AdminTotals struct {
	Users       int64   `json:"users"`
	Devices     int64   `json:"devices"`
	Sessions    int64   `json:"sessions"`
	StoredBytes int64   `json:"stored_bytes"`
	CostUSD     float64 `json:"cost_usd"`
	Tokens      int64   `json:"tokens"`
}

AdminTotals sums AdminUserStats.

type AdminUser

type AdminUser struct {
	ID          string     `json:"id"`
	Email       string     `json:"email"`
	Name        string     `json:"name"`
	IsAdmin     bool       `json:"is_admin"`
	DisabledAt  *time.Time `json:"disabled_at"`
	LastLoginAt *time.Time `json:"last_login_at"`
	LastSyncAt  *time.Time `json:"last_sync_at"`
	Devices     int        `json:"devices"`
	StoredBytes int64      `json:"stored_bytes"`
}

AdminUser is a user as seen by an admin.

type AdminUserStats

type AdminUserStats struct {
	AdminUser
	Sessions       int64      `json:"sessions"`
	CostUSD        float64    `json:"cost_usd"`
	Tokens         int64      `json:"tokens"`
	LastActivityAt *time.Time `json:"last_activity_at"`
	DeriveErrors   int64      `json:"derive_errors"`
	Rebuilding     bool       `json:"rebuilding"`
}

AdminUserStats is AdminUser plus the aggregates of the user's derived data (numbers only).

type AuditEntry

type AuditEntry struct {
	ID            int64           `json:"id"`
	At            time.Time       `json:"at"`
	Action        string          `json:"action"`
	ActorUserID   *string         `json:"actor_user_id"`
	SubjectUserID *string         `json:"subject_user_id"`
	DeviceID      *string         `json:"device_id"`
	IP            *string         `json:"ip"`
	UserAgent     *string         `json:"user_agent"`
	Detail        json.RawMessage `json:"detail"`
}

AuditEntry is one audit log row.

type AuditPage

type AuditPage struct {
	Entries []AuditEntry `json:"entries"`
	Next    *int64       `json:"next"`
}

AuditPage is one page of audit entries; Next is the cursor for the following page.

type AvatarFetch

type AvatarFetch func(ctx context.Context, rawURL string) (body []byte, contentType string, err error)

AvatarFetch loads the image behind a stored picture URL: the body and its media type.

func IssuerAvatarFetch

func IssuerAvatarFetch(issuer string, rt http.RoundTripper) AvatarFetch

IssuerAvatarFetch fetches only https URLs on the issuer's origin (no SSRF to anything else), follows no redirects, and accepts at most 512 KiB of PNG, JPEG, WebP or GIF within 5 s. Errors never carry the URL, which may hold tokens.

type Device

type Device struct {
	ID            string     `json:"id"`
	Name          string     `json:"name"`
	Hostname      string     `json:"hostname"`
	OS            string     `json:"os"`
	Arch          string     `json:"arch"`
	OSUser        string     `json:"os_user"`
	DaemonVersion string     `json:"daemon_version"`
	CreatedAt     time.Time  `json:"created_at"`
	LastSeenAt    *time.Time `json:"last_seen_at"`
	LastSyncAt    *time.Time `json:"last_sync_at"`
	RevokedAt     *time.Time `json:"revoked_at"`
	Stale         bool       `json:"stale"`
}

Device is one registered device.

type Handler

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

Handler serves /api/v1.

func New

func New(cfg config.Config, d *db.DB) *Handler

New returns a Handler.

func (*Handler) Register

func (h *Handler) Register(mux *http.ServeMux, auth *webauth.Auth)

Register mounts the routes behind auth.

func (*Handler) WithAvatarFetch

func (h *Handler) WithAvatarFetch(f AvatarFetch) *Handler

WithAvatarFetch replaces how picture URLs are fetched (tests use a stub).

type Me

type Me struct {
	ID      string `json:"id"`
	Email   string `json:"email"`
	Name    string `json:"name"`
	IsAdmin bool   `json:"is_admin"`
	// TimeZone is the effective zone ("UTC" when unset); TimeZoneSet is false until the user sets it.
	TimeZone    string `json:"time_zone"`
	TimeZoneSet bool   `json:"time_zone_set"`
}

Me is the current user.

Jump to

Keyboard shortcuts

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