httpapi

package
v2.107.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package httpapi exposes the pkg/cortexdb facade over HTTP/JSON.

It is the same shape as pkg/rpcserver and for the same reason: a request is decoded into the facade's own Request struct, handed to *cortexdb.DB, and the facade's Response is written back. No retrieval, fusion, ranking or graph logic lives here. Two surfaces over one database that each carried a little of their own logic would answer the same question differently, and the difference would only show up to whoever used both.

The same goes for who may ask. This package enforces pkg/authz's key policy — scoped keys, clearances and row confinement — against an explicit table of route classifications, so a key that is confined over gRPC is confined here in the same words. A REST port that ignored the key file would be a door that ignores the lock beside it.

The facade types already carry json tags — they are the same structs the MCP tools are defined in terms of — so the conversion this package performs is mostly the routing, the auth and the error mapping, and very little else.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(db *cortexdb.DB, opts Options) http.Handler

New returns an http.Handler serving the REST API over db.

A key file that cannot be loaded yields a handler that refuses every request and says why, rather than one that serves them unprotected. New is kept error-free because it is the signature every existing caller uses; callers that want the load failure in their hands call NewWithPolicy.

func NewWithPolicy

func NewWithPolicy(db *cortexdb.DB, opts Options) (http.Handler, error)

NewWithPolicy is New, reporting a key-file load failure to the caller.

Types

type Options

type Options struct {
	// Token enables bearer-token auth when non-empty. It grants unconfined
	// read/write, which is what it has always meant; KeyFile is how a
	// deployment gets anything narrower.
	Token string
	// KeyFile is the path to a JSON file of scoped API keys. When set it is
	// the entire policy and Token is ignored — see authz.Resolve for why
	// honouring both would leave the environment variable as a master key
	// outranking every scope in the file.
	KeyFile string
	// Keys is a pre-loaded policy, for callers that build one in process.
	// It takes precedence over Token and KeyFile.
	Keys *authz.KeySet
	// DBPath is reported by GET /v1/info. It is a label, not a handle: nothing
	// here opens it, and leaving it empty only makes /v1/info quieter.
	DBPath string
}

Options configures the HTTP server wrapper. The three policy fields are rpcserver.Options' three, with the same precedence, because one deployment must not be securable to two different degrees depending on the port.

Jump to

Keyboard shortcuts

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