querywrite

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package querywrite holds the guards every saved-query write path of this agent shares - the legacy queries/create_query, update_query and delete_query routes and queries/capture - so each check has one definition, whichever route a write takes.

Index

Constants

View Source
const MaxSegmentBytes = 200

MaxSegmentBytes bounds one folder or query-id segment, well under every common file system's 255-byte name limit, leaving room for the "<id>.query.<type>" suffix the store appends.

View Source
const Timeout = 5 * time.Second

Timeout bounds one query write's wait on the project's query store: the revisioned store serializes writers with a cross-process lock, and a lock another process holds must end the request with 504 TIMEOUT, having written nothing, rather than hang it until the client gives up. It is shorter than `datatug serve`'s 10-second http.Server WriteTimeout, so the 504 still reaches the client.

Variables

This section is empty.

Functions

func CredentialReason

func CredentialReason(value string) (reason string, found bool)

CredentialReason reports why value appears to embed a secret - a URL or DSN password, a secret key/value pair or JSON member, an HTTP credential header - or ("", false) when it does not. It is the one credential screen every query write path applies to the text a query persists.

func LocationMessage

func LocationMessage(folderPath, id, reason string) string

LocationMessage turns a query store's refusal of a location - the folder path, id and reason of a datatug.InvalidQueryLocationError - into the message a 400 may carry. It names the offending segment and nothing else of the server: the store builds some reasons from OS error text ("lstat /srv/project/queries/locked/sub: permission denied"), and neither that absolute path nor the OS text may reach a client. A reason the store states in its own fixed words (knownLocationReasons) is kept, so "folder path segment \"linked\": resolves through a symlink" still says what to fix; anything else becomes "cannot be accessed".

func QueryCredentialReason

func QueryCredentialReason(q *datatug.QueryDef) (field, reason string, found bool)

QueryCredentialReason applies CredentialReason to every field of q that a query write persists as free text into git-tracked project files: its title, purpose and text (the SQL, DTQL, GraphQL or HTTP body - on these write paths code is screened too, unlike datatug-core's own QueryDef.Validate, which screens HTTP text only), each parameter's title and default (defaultValueCredentialReason) and each target's connection-string-like fields. It returns the first offending field, named the way the request names it ("parameters[0].defaultValue").

func SegmentReason

func SegmentReason(segment string) (reason string, ok bool)

SegmentReason reports why segment cannot be one folder segment or the id of a saved query's location, or ("", true) when it can. It is the one segment validator every query write path calls.

Its rules are datatug-core's revisioned filestore's (validateQuerySegmentReason in pkg/storage/filestore/query_location.go on the Phase 2 task 2 storage branch), applied here because the store the default build pins applies none of them: non-empty; not "." or ".."; no NUL, invalid UTF-8, control or bidirectional-text control character; none of windowsIllegalChars (so never a path separator); not the store's reserved ".dt-query-txn"; no leading "."; no trailing "." or space; at most MaxSegmentBytes; not a Windows device name. On top of them, "~" (datatug.RootSharedFolderName) is the legacy API's name for the queries root, so it is never a folder or an id of its own.

Three more rules are this package's own, and are stricter than the store's, so a name this accepts is always one the store accepts. Each refuses a spelling that could be a file other than the one it names, and refusing is better than accepting a name authorization and the store might read differently (core's own validator should grow them too; until it does, every write path reaches the store through this function):

  • no default-ignorable code point (isIgnorableRune), which HFS+ drops when it compares names;
  • no unassigned, private-use or line-separator code point (isNameableRune), whose case mapping a newer file system may know and this build's Unicode tables may not;
  • nothing shaped like a Windows 8.3 short name (windowsShortNamePattern), which on NTFS can open another name's file.

Types

This section is empty.

Jump to

Keyboard shortcuts

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