Documentation
¶
Index ¶
- Constants
- Variables
- func AgentInfo(w http.ResponseWriter, r *http.Request)
- func ConfigureServedUIOrigins(uiHost string, port int)
- func ExecuteCloudWatchCheck(ctx context.Context, localProject, operationID string, claim watch.Claim, ...) (core.CheckRun, string, error)
- func ExecuteWatchCheck(ctx context.Context, ...) (detective.CheckRun, string, error)
- func IsSupportedOrigin(origin string) bool
- func Ping(w http.ResponseWriter, _ *http.Request)
- func PrepareLocalVisibilityItems(ctx context.Context, scope datatug.ProjectLifecycleScope) (projectvisibility.Runtime, error)
- func RegisterDatatugHandlers(pathPrefix string, router *httprouter.Router, mode RegisterMode, wrap wrapper, ...)
- func RegisterDatatugHandlersWithCapabilities(pathPrefix string, router *httprouter.Router, mode RegisterMode, wrap wrapper, ...)
- func SetFederatedLabelGuard(guardFor func(projectDir string) secureread.FederatedColumnGuard)
- type Capabilities
- type ErrorResponse
- type Handler
- type ProjectAgentEndpoints
- type ProjectEndpoints
- type RegisterMode
- type RequestGuard
- type VerifyRequest
Constants ¶
const DevUIHost = "datatug.localhost"
DevUIHost is the one host, besides https://datatug.app, whose pages may call the agent: the local web UI development host (http or https, with or without a port).
Variables ¶
var ErrInvalidQueriesRoot = errors.New("invalid queries root")
ErrInvalidQueriesRoot is handleError's INVALID_REQUEST trigger (field "root") for an unrecognized ?root= value — the same {code,field} shape api.ErrUnknownStoreID/ErrAmbiguousStore already give ?storage=.
Functions ¶
func AgentInfo ¶
func AgentInfo(w http.ResponseWriter, r *http.Request)
AgentInfo is GET agent-info's exact contract envelope (api-contract.md "Endpoint table"): principal with explicit roles/groups, securityContextId, the projects this process serves, and its capabilities. It replaces the old ad-hoc {version, uptimeMinutes, principal} shape (pkg/api.GetAgentInfo/AgentInfo) — Task 12 item 3.
version reports buildinfo.Get("datatug").Version — see buildInfoFunc. The contract (api-contract.md "Endpoint table", `agent-info` row) defines only `version` on this envelope; commit and build date are deliberately not added here, even though buildinfo.Info carries them, to avoid introducing fields the contract doesn't define.
func ConfigureServedUIOrigins ¶ added in v0.146.0
ConfigureServedUIOrigins lists the exact origins of the web UI pages this process serves itself; nil clears the list. Each is http://<host>:<port> for uiHost and the loopback names.
func ExecuteCloudWatchCheck ¶ added in v0.117.0
func ExecuteCloudWatchCheck(ctx context.Context, localProject, operationID string, claim watch.Claim, bundle watchdaemon.CloudExecutionBundle, bindings map[string]string) (core.CheckRun, string, error)
ExecuteCloudWatchCheck evaluates an immutable hosted graph using the existing Core evaluator and accepted-query runner. Local source bindings are explicit operator grants and remain subject to the ordinary secured execution path.
func ExecuteWatchCheck ¶ added in v0.114.0
func ExecuteWatchCheck(ctx context.Context, project, environment, checkID, checkVersion, fingerprint, operationID string, inputs map[string]detective.InputValue) (detective.CheckRun, string, error)
ExecuteWatchCheck is a trusted local daemon boundary. It preserves Detective's project asset admission, revision pinning and secured saved-query path. This function is never registered as an unauthenticated HTTP route.
func IsSupportedOrigin ¶
IsSupportedOrigin reports whether origin is one the agent answers: exactly https://datatug.app (no port), or the exact host datatug.localhost with the scheme http or https and no port or a numeric one. Nothing else is on the list: not localhost or 127.0.0.1, not a subdomain of datatug.app, not another product's UI (founder decision 2026-10-15). The match is exact on scheme, host and port, never a prefix or a suffix test, and no flag or environment variable adds an origin.
It is the one list of origins: the OPTIONS handler, the request guard in front of every route and the answers' Access-Control-Allow-Origin all use it. An origin is a scheme, a host and maybe a port, and nothing else (the Origin of a browser never has a path, a query, a fragment or a user), so a text that has more is not on the list whatever it starts or ends with.
One exception, by founder direction of 2026-11-07 (spec: datatug/backstage local-frontend-distribution REQ:ui-host): when this server itself serves the web UI (`datatug serve --web-ui`), the exact origins of its own pages are listed too — http://<ui-host>:<port>, http://localhost:<port>, http://127.0.0.1:<port> and http://[::1]:<port> for its own port only (ConfigureServedUIOrigins).
func PrepareLocalVisibilityItems ¶ added in v0.133.0
func PrepareLocalVisibilityItems(ctx context.Context, scope datatug.ProjectLifecycleScope) (projectvisibility.Runtime, error)
PrepareLocalVisibilityItems uses the same owning services as their normal list endpoints. A registered project or private history record alone never grants access to another actor's working context.
func RegisterDatatugHandlers ¶
func RegisterDatatugHandlers( pathPrefix string, router *httprouter.Router, mode RegisterMode, wrap wrapper, contextProvider func(r *http.Request) (context.Context, error), handler Handler, )
RegisterDatatugHandlers registers datatug HTTP handlers with every write route closed (Capabilities{}) — kept for callers (this package's own tests) that do not need write access. Real `datatug serve` startup uses RegisterDatatugHandlersWithCapabilities.
func RegisterDatatugHandlersWithCapabilities ¶ added in v0.20.0
func RegisterDatatugHandlersWithCapabilities( pathPrefix string, router *httprouter.Router, mode RegisterMode, wrap wrapper, contextProvider func(r *http.Request) (context.Context, error), handler Handler, caps Capabilities, )
RegisterDatatugHandlersWithCapabilities is RegisterDatatugHandlers plus an explicit Capabilities gate for this process's mutation routes.
func SetFederatedLabelGuard ¶ added in v0.149.0
func SetFederatedLabelGuard(guardFor func(projectDir string) secureread.FederatedColumnGuard)
SetFederatedLabelGuard installs the label guard every federated saved query checks each leaf with, against the labels of the source its alias is bound to.
Types ¶
type Capabilities ¶ added in v0.20.0
type Capabilities struct {
AllowWrites bool
// AllowLiveConnections opens the routes that connect to a database server that the served
// project records, under the identity of the person who runs the server (today
// dbserver-databases, which lists the databases of a SQL Server server). It defaults false:
// without it such a route answers 403 before anything is connected to (see
// requireLiveConnections, and `datatug serve --allow-live-connections`).
AllowLiveConnections bool
// ServedHost and ServedPort are the host and the port that the server listens on. The Host
// of a request must be a loopback name or address, or ServedHost, on ServedPort (see
// RequestGuard). A ServedPort of 0 accepts any port.
ServedHost string
ServedPort int
// Access, when set, is the agent's shared-token access (pkg/agentaccess): every route but a
// preflight and the exchange of a one-time code requires its session token.
Access *agentaccess.Access
}
Capabilities gates whether this process's mutation routes register at all (api-contract.md "Security and errors": "this read journey must not expose an unauthenticated mutation endpoint as a side effect" — REQ:principal-selection: "Unneeded write endpoints MUST fail closed"). AllowWrites defaults false: a `datatug serve` process serving the Phase 1 read journey registers every mutation route behind requireWriteCapability (write_capability.go), which refuses with ACCESS_DENIED before any project file is touched, unless the caller explicitly opted in (see cmd_serve.go's --allow-writes flag).
func (Capabilities) RequestGuard ¶ added in v0.57.0
func (c Capabilities) RequestGuard() RequestGuard
RequestGuard is the guard of a server started with these capabilities: the host and port it serves on are the ones of Capabilities.
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Code string `json:"code,omitempty"`
Field string `json:"field,omitempty"`
}
ErrorResponse defines format of error response body. Code is set for a structured refusal (currently only "ACCESS_DENIED"); Field is reserved for a future per-field validation error and is not populated yet.
type Handler ¶
type Handler = func( w http.ResponseWriter, r *http.Request, requestDTO apicore.RequestDTO, verifyOptions verify.RequestOptions, successStatusCode int, getContext apicore.ContextProvider, handler apicore.Worker, )
Handler is responsible for creating context and call `handler()` func that should use provided context along with `requestDTO` that was populated from request body Its is exposed publicly so it can be replaced with custom implementation
type ProjectAgentEndpoints ¶
type ProjectAgentEndpoints struct {
}
ProjectAgentEndpoints defines project endpoints
type ProjectEndpoints ¶
type ProjectEndpoints interface {
CreateProject(w http.ResponseWriter, r *http.Request)
DeleteProject(w http.ResponseWriter, r *http.Request)
}
ProjectEndpoints defines project endpoints
type RegisterMode ¶
type RegisterMode = int
const ( RegisterWriteOnlyHandlers RegisterMode = iota RegisterAllHandlers )
type RequestGuard ¶ added in v0.57.0
type RequestGuard struct {
// contains filtered or unexported fields
}
RequestGuard is the one check that stands in front of every route of the server. A route answers a request only when it comes from one of the server's own pages or from a tool on the same machine:
- its Host is one that the server was started for: a loopback name or address (localhost, 127.0.0.1, ::1) or the host the person configured, with the port the server listens on. A page of another site that makes the browser reach this server by a name of its own (DNS rebinding) carries that name in Host;
- its Origin, when the request has one, is on the list that the OPTIONS handler uses (IsSupportedOrigin);
- its Sec-Fetch-Site, when the request has one, is same-origin, same-site or none, or its Origin is on the list. A request that carries neither header (the CLI, curl, a script) is answered when its Host passes.
When the server has an access secret, a request that is not a preflight or a code exchange must also carry the session token (`Authorization: Bearer`), or it is a 401.
A refusal is a 403 with a fixed sentence: no echo of what the request said, and no Access-Control-Allow-Origin. Every other answer to a request whose Origin is on the list, an error as much as a success, carries Access-Control-Allow-Origin for that Origin and Vary: Origin (writeCORSOrigin).
func NewRequestGuard ¶ added in v0.57.0
func NewRequestGuard(servedHost string, servedPort int) RequestGuard
NewRequestGuard builds the guard of a server that listens on servedHost and servedPort. The loopback names and addresses are always accepted, whatever servedHost is. A servedPort of 0 says that the port is not known and any port is accepted.
func (RequestGuard) Wrap ¶ added in v0.57.0
func (g RequestGuard) Wrap(next http.HandlerFunc) http.HandlerFunc
Wrap returns next behind the guard: the request is refused (see RequestGuard) or answered by next.
func (RequestGuard) WrapStatic ¶ added in v0.146.0
func (g RequestGuard) WrapStatic(next http.Handler) http.HandlerFunc
WrapStatic is the guard of the web UI's own static files (`serve --web-ui`): only the Host check. The files are the public archive, so they need no token (the page loads before it has one) and no Origin or Fetch-Metadata check (a link from another site must open the app); the Host check is what stops a DNS-rebinding page from reading them through a name of its own.
type VerifyRequest ¶
VerifyRequest implements VerifyRequestOptions
func (VerifyRequest) AuthenticationRequired ¶
func (v VerifyRequest) AuthenticationRequired() bool
AuthenticationRequired specifies if authentication is mandatory
func (VerifyRequest) MaximumContentLength ¶
func (v VerifyRequest) MaximumContentLength() int64
MaximumContentLength defines max content length, if < 0 no limit
func (VerifyRequest) MinimumContentLength ¶
func (v VerifyRequest) MinimumContentLength() int64
MinimumContentLength defines min content length
Source Files
¶
- 0_interface.go
- agent_info_endpoint.go
- board_endpoints.go
- card_endpoints.go
- catalog_tables_endpoint.go
- chat_interpret.go
- common.go
- compare.go
- compare_facts.go
- compare_incident.go
- compare_key.go
- compare_rows.go
- compare_sides.go
- constants.go
- contract_decode.go
- contract_error.go
- contract_errors.go
- contract_result.go
- contract_scope.go
- dbserver_databases.go
- dbservers_endpoints.go
- detective.go
- detective_ai.go
- detective_ai_snapshot.go
- detective_incidents.go
- detective_knowledge.go
- detective_transient_rows.go
- entity_endpoints.go
- environment_endpoints.go
- environment_state.go
- exec_run_query.go
- exec_run_query_federated.go
- execute_endpoints.go
- execution_recording.go
- executions.go
- folder_endpoints.go
- incidents.go
- legacy_query_write_response.go
- live_connections_capability.go
- local_project_registry.go
- meanings_labels.go
- meanings_saved_sql.go
- ping_pong.go
- project_discovery.go
- project_endpoints.go
- project_full.go
- project_item_tags.go
- project_lifecycle.go
- project_lifecycle_gate.go
- project_meanings.go
- project_query_mutation.go
- project_visibility.go
- projects.go
- public_ovdb_connection.go
- query_capture.go
- query_capture_store.go
- query_capture_store_revisioned.go
- query_capture_validate.go
- query_endpoints.go
- records_lookup.go
- recordsets_endpoints.go
- register.go
- request_guard.go
- results.go
- routes.go
- run_query_labels.go
- semantic_applicable.go
- semantic_columns.go
- semantic_project.go
- semantic_related.go
- semantic_schema.go
- session_context.go
- session_context_detective.go
- session_context_detective_errors.go
- session_context_detective_ports.go
- session_context_query.go
- session_exchange.go
- source_binding_guard.go
- typed_value_convert.go
- util_error_handling.go
- util_json.go
- validators.go
- watch_cloud.go
- watch_executor.go
- write_capability.go