Documentation
¶
Overview ¶
Package linkserver holds what a shared Prism link server stores and answers: per repository and commit, where that repository references symbols other repositories declare, and what it declares itself.
A bundle carries locations, one line of source per reference, and declaration signatures. It carries no source bodies: answering "who uses this" for repositories that are not on a machine needs no more, and a server that never holds bodies is a smaller thing to protect.
Index ¶
- Constants
- Variables
- func AcceptedFormats() []int
- func CleanLine(s, near string) string
- func CleanName(s string, max int) string
- func ClientToken() string
- func Copy(ctx context.Context, src, dst Blob) (int, error)
- func KeyLeaf(key string) string
- func Push(ctx context.Context, server string, b Bundle) error
- func RepoName(remote, root string) string
- func RevokeToken(p, id string) error
- func Serve(ctx context.Context, srv *Server, lc ListenConfig) error
- func VerifyConditionalWrites(ctx context.Context, b Blob) error
- type Allow
- type Authenticator
- type AzureBlob
- func (b *AzureBlob) Delete(ctx context.Context, key string) error
- func (b *AzureBlob) Describe() string
- func (b *AzureBlob) Get(ctx context.Context, key, ifNoneMatch string) ([]byte, string, error)
- func (b *AzureBlob) List(ctx context.Context, prefix string) ([]string, error)
- func (b *AzureBlob) Put(ctx context.Context, key string, data []byte) error
- func (b *AzureBlob) PutIf(ctx context.Context, key string, data []byte, ifMatch string) (string, error)
- type AzureConfig
- type Blob
- type Bundle
- type ConsumersRequest
- type ConsumersResponse
- type Def
- type DefineAnswer
- type FSBlob
- func (b *FSBlob) Delete(_ context.Context, key string) error
- func (b *FSBlob) Describe() string
- func (b *FSBlob) Get(_ context.Context, key, ifNoneMatch string) ([]byte, string, error)
- func (b *FSBlob) List(_ context.Context, prefix string) ([]string, error)
- func (b *FSBlob) Put(_ context.Context, key string, data []byte) error
- func (b *FSBlob) PutIf(ctx context.Context, key string, data []byte, ifMatch string) (string, error)
- type GCSBlob
- func (b *GCSBlob) Delete(ctx context.Context, key string) error
- func (b *GCSBlob) Describe() string
- func (b *GCSBlob) Get(ctx context.Context, key, ifNoneMatch string) ([]byte, string, error)
- func (b *GCSBlob) List(ctx context.Context, prefix string) ([]string, error)
- func (b *GCSBlob) Put(ctx context.Context, key string, data []byte) error
- func (b *GCSBlob) PutIf(ctx context.Context, key string, data []byte, ifMatch string) (string, error)
- type GCSConfig
- type ListenConfig
- type Metrics
- type OpenAuth
- type Options
- type Principal
- type Problem
- type ReopenFile
- type RepoDefs
- type RepoSites
- type RepoSummary
- type Require
- type S3Blob
- func (b *S3Blob) Delete(ctx context.Context, key string) error
- func (b *S3Blob) Describe() string
- func (b *S3Blob) Get(ctx context.Context, key, ifNoneMatch string) ([]byte, string, error)
- func (b *S3Blob) List(ctx context.Context, prefix string) ([]string, error)
- func (b *S3Blob) Put(ctx context.Context, key string, data []byte) error
- func (b *S3Blob) PutIf(ctx context.Context, key string, data []byte, ifMatch string) (string, error)
- type S3Config
- type Server
- type ServerOptions
- type SharedToken
- type Site
- type Stats
- type Store
- func (s *Store) Check(ctx context.Context) (repos, bundles int, problems []Problem, err error)
- func (s *Store) Consumers(req ConsumersRequest) ConsumersResponse
- func (s *Store) ConsumersFor(ctx context.Context, req ConsumersRequest, allow Allow) ConsumersResponse
- func (s *Store) Define(key string) []RepoDefs
- func (s *Store) DefineFor(ctx context.Context, key, name string, allow Allow) ([]RepoDefs, int)
- func (s *Store) DefineName(name string) []RepoDefs
- func (s *Store) DeleteCommit(ctx context.Context, repo, sha string) error
- func (s *Store) DeleteRepo(ctx context.Context, repo string) (int, error)
- func (s *Store) Describe() string
- func (s *Store) Handler(token string) http.Handler
- func (s *Store) Prune(ctx context.Context, repo string, keep int) ([]string, error)
- func (s *Store) Put(b Bundle) error
- func (s *Store) PutContext(ctx context.Context, b Bundle) error
- func (s *Store) Refresh(ctx context.Context) error
- func (s *Store) Repos() []RepoSummary
- func (s *Store) Run(ctx context.Context, every time.Duration, onErr func(error))
- func (s *Store) Stats() Stats
- func (s *Store) Warm(ctx context.Context)
- type Token
- type TokenFileAuth
- type TokenSpec
Constants ¶
const DefaultKeep = 20
DefaultKeep is the retention default: 20 commits per repository.
const FormatVersion = 1
FormatVersion is the bundle format this build writes and the newest one a server accepts. 0 is the v1.3.x format, which had no format field.
const MaxLineRunes = 300
MaxLineRunes caps a source line shown next to a site. Real code lines are shorter (the longest in prism, grove and mason is 216 characters; 0.05% of grafana's lines exceed 300); a minified file or a hostile upload is not, and one such line used to put 200 KB into an answer.
const MaxRefsPerKey = 20000
MaxRefsPerKey is how many references to one symbol a bundle may carry. A real repository has far fewer; a bundle with more is refused at upload rather than flooding every answer about that symbol.
Variables ¶
var ( ErrNotFound = errors.New("not found") ErrNotModified = errors.New("not modified") ErrConflict = errors.New("changed by another writer") )
var ErrNoConditionalWrites = errors.New("the store ignores conditional writes (If-Match / If-None-Match: *), " +
"so replicas sharing it would lose each other's branch updates")
ErrNoConditionalWrites is a store that ignores If-Match / If-None-Match.
var ErrUnauthenticated = errors.New("missing, unknown, revoked or expired token")
ErrUnauthenticated is a missing, unknown, revoked or expired credential.
Functions ¶
func AcceptedFormats ¶
func AcceptedFormats() []int
AcceptedFormats lists the bundle formats this server stores.
func CleanLine ¶
CleanLine makes text from another repository safe to print: control characters (terminal escape sequences among them) and bidirectional overrides are removed, tabs become spaces, and a line longer than MaxLineRunes is cut to a window around near (the referenced name) with "…" where it was cut.
func CleanName ¶
CleanName cleans a short identifier-like field (a file path, an enclosing symbol) and caps it at max runes.
func ClientToken ¶
func ClientToken() string
Token is the bearer token a client sends and a server requires: $PRISM_LINK_TOKEN. It is never read from a repository file, so it cannot be committed by accident.
func Copy ¶
Copy copies every object from src to dst: backup, restore, and moving a store between backends. It returns the number of objects copied.
func RepoName ¶
RepoName turns a git remote URL into host/org/repo, falling back to the directory name for a repository with no remote.
func Serve ¶
func Serve(ctx context.Context, srv *Server, lc ListenConfig) error
Serve runs the public listener (and the ops listener) until ctx ends, then shuts down gracefully, letting requests in flight finish.
func VerifyConditionalWrites ¶
VerifyConditionalWrites probes a store: a create-only write over an existing object and a write with a stale ETag must both be refused. Some S3 implementations accept the headers and ignore them (LocalStack 3.8, 2026-11-27); on such a store several replicas would overwrite each other's refs without an error.
Types ¶
type Authenticator ¶
type Authenticator interface {
Authenticate(r *http.Request) (*Principal, error)
Describe() string
}
Authenticator turns a request's credential into a Principal.
type AzureBlob ¶
type AzureBlob struct {
// contains filtered or unexported fields
}
AzureBlob is a Blob on an Azure Blob Storage container. PutIf uses If-Match / If-None-Match: *, so several replicas can share it.
func OpenAzure ¶
func OpenAzure(ctx context.Context, c AzureConfig) (*AzureBlob, error)
OpenAzure checks the container is reachable with the credentials.
type AzureConfig ¶
AzureConfig selects an Azure Blob Storage container (Azure, Azure Stack Hub, Azurite). URL is the container URL with an optional prefix: https://<account>.blob.core.windows.net/<container>[/<prefix>]. With PathStyle the account is the first path segment, as the Azurite emulator and some private endpoints use: http://host:10000/<account>/<container>.
Credentials, from the environment, first match wins:
- AZURE_STORAGE_KEY: the account key (Shared Key signing)
- AZURE_STORAGE_SAS_TOKEN: a SAS token for the container
- AZURE_FEDERATED_TOKEN_FILE + AZURE_CLIENT_ID + AZURE_TENANT_ID: AKS workload identity
- AZURE_CLIENT_SECRET + AZURE_CLIENT_ID + AZURE_TENANT_ID: a service principal
- AZURE_USE_MANAGED_IDENTITY=1 (AZURE_CLIENT_ID optional): the VM's or App Service's managed identity through the instance metadata service
type Blob ¶
type Blob interface {
// Get returns the object and its ETag. With ifNoneMatch equal to the
// current ETag it returns ErrNotModified; a missing object is ErrNotFound.
Get(ctx context.Context, key, ifNoneMatch string) ([]byte, string, error)
// Put writes an object unconditionally.
Put(ctx context.Context, key string, data []byte) error
// PutIf writes only if the object's ETag is still ifMatch; an empty
// ifMatch means the object must not exist yet. A lost race is ErrConflict.
PutIf(ctx context.Context, key string, data []byte, ifMatch string) (string, error)
// List returns every key under prefix, sorted.
List(ctx context.Context, prefix string) ([]string, error)
// Delete removes an object; a missing one is not an error.
Delete(ctx context.Context, key string) error
// Describe names the backend for logs ("dir /var/lib/prism-links").
Describe() string
}
Blob is the storage a Store runs on: named objects with an ETag, and a compare-and-swap write so several server replicas can move a repository's branches without losing each other's updates. Keys are slash-separated ("github.com~acme~app/refs.json").
type Bundle ¶
type Bundle struct {
Format int `json:"format"`
Repo string `json:"repo"` // stable name: host/org/repo, or the directory name
SHA string `json:"sha"`
Ref string `json:"ref,omitempty"` // branch it was exported from
Dirty bool `json:"dirty,omitempty"`
Created string `json:"created"`
Packages []groveeng.ManifestPackage `json:"packages"`
Requires []Require `json:"requires"`
Refs []Site `json:"refs"`
Defs []Def `json:"defs"`
}
Bundle is one repository's link data at one commit.
type ConsumersRequest ¶
type ConsumersRequest struct {
Keys []string `json:"keys"`
// ExcludePackages: "ecosystem:name" of packages the asker already
// covers locally (its own, and its linked checkouts'). A repository
// declaring one is skipped, so a site is not reported twice.
ExcludePackages []string `json:"excludePackages,omitempty"`
// Refs picks a branch per repository; others use their default.
Refs map[string]string `json:"refs,omitempty"`
// Packages are the asker's own packages ("ecosystem:name", as its
// manifests declare them). A consumer's requirement on one of them is
// its pin, also where the symbol key's package and the manifest's
// artifact are named differently (jvm:com.acme.lib vs maven:com.acme:lib).
Packages []string `json:"packages,omitempty"`
}
ConsumersRequest asks who references keys.
type ConsumersResponse ¶
type ConsumersResponse struct {
Repos []RepoSites `json:"repos"`
Searched int `json:"searched"`
Unreadable int `json:"unreadable,omitempty"`
}
ConsumersResponse lists the repositories that reference the keys, and how many repositories were searched, so "none found" is distinguishable from "none uploaded". Unreadable counts repositories the caller's credential may not read: they were not searched, and the answer is incomplete.
func AskConsumers ¶
func AskConsumers(ctx context.Context, server string, req ConsumersRequest) (ConsumersResponse, error)
AskConsumers asks a server who references keys.
type Def ¶
type Def struct {
Key string `json:"key"`
Kind string `json:"kind"`
Name string `json:"name"`
Signature string `json:"signature,omitempty"`
File string `json:"file"`
Line int `json:"line"`
}
Def is one symbol a repository declares that others can reference.
type DefineAnswer ¶
type DefineAnswer struct {
Repos []RepoDefs `json:"repos"`
Unreadable int `json:"unreadable,omitempty"`
}
DefineAnswer is a define reply: the declaring repositories, and how many uploaded repositories the caller's token may not read (not searched).
func AskDefine ¶
func AskDefine(ctx context.Context, server, key string) (DefineAnswer, error)
AskDefine asks a server where key is declared.
func AskDefineName ¶
func AskDefineName(ctx context.Context, server, name string) (DefineAnswer, error)
AskDefineName asks a server where a symbol with this name is declared.
type FSBlob ¶
type FSBlob struct {
// contains filtered or unexported fields
}
FSBlob stores objects as files under a directory. It serves one host: compare-and-swap holds a lock file per key, which is safe between the processes of one machine but not across machines sharing a network file system. Several replicas need the S3 backend.
type GCSBlob ¶
type GCSBlob struct {
// contains filtered or unexported fields
}
GCSBlob is a Blob on a GCS bucket through the JSON API. The ETag is the object generation; PutIf uses ifGenerationMatch (0: must not exist), so several replicas can share the bucket.
type GCSConfig ¶
type GCSConfig struct {
URL string
Endpoint string // default https://storage.googleapis.com, or STORAGE_EMULATOR_HOST
}
GCSConfig selects a Google Cloud Storage bucket: gs://bucket[/prefix]. Credentials, first match wins:
- STORAGE_EMULATOR_HOST: an emulator (fake-gcs-server), no credentials
- GOOGLE_APPLICATION_CREDENTIALS: a service-account key file
- otherwise the metadata server (GCE, GKE workload identity, Cloud Run)
type ListenConfig ¶
type ListenConfig struct {
Addr string // host:port
// TLSCert and TLSKey turn on HTTPS. The files are re-read when they
// change, so a certificate can be rotated without a restart.
TLSCert, TLSKey string
// ClientCA, with TLS, requires a client certificate signed by it (mTLS).
ClientCA string
// MaxConns caps concurrent connections; 0 means 512.
MaxConns int
// OpsAddr, when set, serves /health and /metrics over plain HTTP.
OpsAddr string
}
ListenConfig is how the server listens.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics counts requests for /metrics in the Prometheus text format.
type Options ¶
type Options struct {
// Keep is how many commits per repository retention keeps, newest
// first; commits a branch points at are always kept. 0 keeps all.
Keep int
}
Options tune a Store.
type Principal ¶
type Principal struct {
ID string // token id; "shared" for PRISM_LINK_TOKEN, "anonymous" with --no-auth
Name string
Upload []string // repository-name globs it may upload
Read []string // repository-name globs it may read
Admin bool // may delete repositories and commits, and run retention
}
Principal is the caller a credential stands for.
type Problem ¶
type Problem struct {
Repo, Key, Issue string
}
Problem is one integrity finding from Check.
type ReopenFile ¶
type ReopenFile struct {
// contains filtered or unexported fields
}
ReopenFile is an audit destination that reopens its file on Reopen (call it on SIGHUP after logrotate moves the file).
func OpenAuditFile ¶
func OpenAuditFile(path string) (*ReopenFile, error)
OpenAuditFile opens path for appending.
func (*ReopenFile) Reopen ¶
func (r *ReopenFile) Reopen() error
type RepoDefs ¶
type RepoDefs struct {
Repo string `json:"repo"`
SHA string `json:"sha"`
Ref string `json:"ref,omitempty"`
Defs []Def `json:"defs"`
}
RepoDefs is where one repository declares a key.
type RepoSites ¶
type RepoSites struct {
Repo string `json:"repo"`
SHA string `json:"sha"`
Ref string `json:"ref,omitempty"`
Created string `json:"created"`
Requires string `json:"requires,omitempty"` // the pin on the asked-about package, as written
Sites []Site `json:"sites"`
}
RepoSites is one repository's answer.
type RepoSummary ¶
type RepoSummary struct {
Repo string `json:"repo"`
Refs map[string]string `json:"refs"`
Latest string `json:"latest"`
Commits int `json:"commits"`
}
RepoSummary is one row of GET /link/repos.
type Require ¶
type Require struct {
Manifest string `json:"manifest"`
Ecosystem string `json:"ecosystem"`
Name string `json:"name"`
Version string `json:"version,omitempty"`
Local bool `json:"local,omitempty"`
}
Require is one dependency a repository declares, as uploaded. It is the manifest requirement without its machine-local parts: Grove's LocalPath is an absolute path on the machine that exported the bundle (a CI runner's workspace) and its Evidence line can quote one (a go.work use), so neither leaves the machine. Local says only that the dependency was built from a local directory, so the version is not what it was built against.
type S3Blob ¶
type S3Blob struct {
// contains filtered or unexported fields
}
S3Blob is a Blob on an S3-compatible bucket. PutIf uses conditional writes (If-Match, If-None-Match: *), so several server replicas can share one bucket.
type S3Config ¶
type S3Config struct {
URL string // s3://bucket[/prefix]
Endpoint string // default https://s3.<region>.amazonaws.com
Region string // default $AWS_REGION, else us-east-1
PathStyle bool // bucket in the path (MinIO), not the host name
}
S3Config selects an S3-compatible bucket (AWS S3, MinIO, Ceph, GCS interoperability). Credentials come from the environment: AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN, or web identity (AWS_ROLE_ARN + AWS_WEB_IDENTITY_TOKEN_FILE, as EKS IRSA sets).
type Server ¶
type Server struct {
Metrics *Metrics
// contains filtered or unexported fields
}
Server is the link server's HTTP layer.
func (*Server) OpsHandler ¶
OpsHandler serves /health and /metrics for probes and scraping, without credentials: bind it to a private address.
type ServerOptions ¶
type ServerOptions struct {
Auth Authenticator
// Audit receives one JSON line per request; nil discards.
Audit io.Writer
// Log receives server events; nil discards.
Log *slog.Logger
// Rate is requests per second per credential (burst 2x); 0 disables.
Rate float64
// MaxBundleBytes caps an upload; 0 means 64 MiB.
MaxBundleBytes int64
// TrustProxy takes the client address from X-Forwarded-For.
TrustProxy bool
}
ServerOptions configure the HTTP front of a Store.
type SharedToken ¶
type SharedToken string
SharedToken is the v1.3 model: one secret with every right.
func (SharedToken) Authenticate ¶
func (t SharedToken) Authenticate(r *http.Request) (*Principal, error)
func (SharedToken) Describe ¶
func (SharedToken) Describe() string
type Site ¶
type Site struct {
Key string `json:"key"`
File string `json:"file"`
From string `json:"from"`
Line int `json:"line"`
Col int `json:"col,omitempty"`
Text string `json:"text,omitempty"`
Test bool `json:"test,omitempty"`
}
Site is one place a repository references another's symbol.
type Stats ¶
type Stats struct {
Repositories, CachedBundles, CachedBytes int
}
Stats is what the metrics endpoint reports about the store.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps one bundle per repository and commit, and a small refs object per repository mapping each branch to the commit last uploaded from it. A commit's bundle never changes meaning; only refs move.
Queries are answered from memory: the catalog of every repository's refs is loaded at open and refreshed (Refresh, or Run in the background), and the bundles queries read are cached by commit. A replica sees its own uploads at once and other replicas' after the next refresh.
func Open ¶
Open returns a store on a filesystem directory, creating it, with the default retention.
func (*Store) Check ¶
Check reads every stored object and reports refs that point at missing or unreadable bundles, unreadable refs, and bundles stored under the wrong repository.
func (*Store) Consumers ¶
func (s *Store) Consumers(req ConsumersRequest) ConsumersResponse
Consumers answers a ConsumersRequest from every stored repository.
func (*Store) ConsumersFor ¶
func (s *Store) ConsumersFor(ctx context.Context, req ConsumersRequest, allow Allow) ConsumersResponse
ConsumersFor answers from the repositories allow permits.
func (*Store) DefineFor ¶
DefineFor answers Define (key) or DefineName (name) from the repositories allow permits, and counts those it hid.
func (*Store) DefineName ¶
DefineName returns the declarations whose qualified name, or last name segment, is name: for a caller that has a name but no package for it.
func (*Store) DeleteCommit ¶
DeleteCommit removes one commit's bundle. Branches that pointed at it are removed too, so answers fall back to the repository's other branches or its latest remaining upload.
func (*Store) DeleteRepo ¶
DeleteRepo removes everything stored for a repository.
func (*Store) Handler ¶
Handler serves the store over HTTP with one shared token (the v1.3 model); an empty token serves everyone. Server builds the full handler with per-token scopes, audit, limits and metrics.
func (*Store) Prune ¶
Prune deletes a repository's commits beyond the newest keep that no branch points at, and returns the commits it deleted. Bundles stored before history was recorded (v1.3.x) are listed from the backend and counted as oldest.
func (*Store) Put ¶
Put stores a bundle and moves its branch to it. The refs update is a compare-and-swap, retried when another writer moved them first.
func (*Store) PutContext ¶
PutContext is Put with a context.
func (*Store) Refresh ¶
Refresh re-reads every repository's refs from the backend. Unchanged refs cost a conditional read; cached bundles no ref points at any more are dropped.
type Token ¶
type Token struct {
ID string `json:"id"`
Name string `json:"name"`
Hash string `json:"hash"` // "sha256:<hex>" of the secret
Upload []string `json:"upload,omitempty"`
Read []string `json:"read,omitempty"`
Admin bool `json:"admin,omitempty"`
Created string `json:"created"`
Expires string `json:"expires,omitempty"` // RFC 3339; empty never expires
}
Token is one entry of a token file. The secret itself is never stored.
func CreateToken ¶
CreateToken adds a token to the file (creating it) and returns the secret, which is shown once and stored only as a hash.
func ListTokens ¶
ListTokens returns the file's tokens (no secrets: only hashes are stored).
type TokenFileAuth ¶
type TokenFileAuth struct {
// Fallback, when set, also accepts the shared PRISM_LINK_TOKEN.
Fallback Authenticator
// contains filtered or unexported fields
}
TokenFileAuth authenticates against a token file, re-reading it when it changes, so a created or revoked token takes effect without a restart.
func OpenTokenFile ¶
func OpenTokenFile(p string) (*TokenFileAuth, error)
OpenTokenFile reads a token file; it must exist and parse.
func (*TokenFileAuth) Authenticate ¶
func (a *TokenFileAuth) Authenticate(r *http.Request) (*Principal, error)
func (*TokenFileAuth) Describe ¶
func (a *TokenFileAuth) Describe() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Command loadtest drives a running Prism link server with synthetic repositories and concurrent queries, and reports latency percentiles.
|
Command loadtest drives a running Prism link server with synthetic repositories and concurrent queries, and reports latency percentiles. |