model

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VerbGet    = 1
	VerbPost   = 2
	VerbPut    = 4
	VerbPatch  = 8
	VerbDelete = 16
	VerbAll    = VerbGet | VerbPost | VerbPut | VerbPatch | VerbDelete
)

Verb mask constants define which HTTP methods are allowed.

View Source
const (
	RequestorAPI    = 1
	RequestorScript = 2
	RequestorAdmin  = 4
)

Requestor mask constants define the source of the request.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKey

type APIKey struct {
	ID        int64      `json:"id" db:"id"`
	KeyHash   string     `json:"-" db:"key_hash"`            // SHA-256 hash, never expose
	KeyPrefix string     `json:"key_prefix" db:"key_prefix"` // First 8 chars for identification
	Label     string     `json:"label" db:"label"`
	RoleID    int64      `json:"role_id" db:"role_id"`
	IsActive  bool       `json:"is_active" db:"is_active"`
	ExpiresAt *time.Time `json:"expires_at,omitempty" db:"expires_at"`
	CreatedAt time.Time  `json:"created_at" db:"created_at"`
	LastUsed  *time.Time `json:"last_used,omitempty" db:"last_used"`
}

APIKey represents an API key used to authenticate requests against a role. The raw key is never stored; only a SHA-256 hash and a short prefix for identification are persisted.

type Admin

type Admin struct {
	ID           int64      `json:"id" db:"id"`
	Email        string     `json:"email" db:"email"`
	PasswordHash string     `json:"-" db:"password_hash"` // bcrypt hash, never expose
	Name         string     `json:"name" db:"name"`
	IsActive     bool       `json:"is_active" db:"is_active"`
	IsSuperAdmin bool       `json:"is_super_admin" db:"is_super_admin"`
	LastLoginAt  *time.Time `json:"last_login_at,omitempty" db:"last_login_at"`
	CreatedAt    time.Time  `json:"created_at" db:"created_at"`
	UpdatedAt    time.Time  `json:"updated_at" db:"updated_at"`
}

Admin represents an administrative user who can manage Faucet configuration through the admin API. Passwords are stored as bcrypt hashes.

type BatchResponse added in v0.1.5

type BatchResponse struct {
	Resource []interface{}      `json:"resource"`
	Meta     *BatchResponseMeta `json:"meta,omitempty"`
}

BatchResponse is the envelope for batch operations that may have mixed results. Used when ?continue=true produces partial successes.

type BatchResponseMeta added in v0.1.5

type BatchResponseMeta struct {
	Count     int     `json:"count"`
	Succeeded int     `json:"succeeded"`
	Failed    int     `json:"failed"`
	Errors    []int   `json:"errors,omitempty"` // indices of failed operations
	TookMs    float64 `json:"took_ms"`
}

BatchResponseMeta extends ResponseMeta with batch operation tracking fields.

type Column

type Column struct {
	Name            string  `json:"name"`
	Position        int     `json:"position"`
	Type            string  `json:"db_type"`
	GoType          string  `json:"go_type"`
	JsonType        string  `json:"json_type"`
	Nullable        bool    `json:"nullable"`
	Default         *string `json:"default,omitempty"`
	MaxLength       *int64  `json:"max_length,omitempty"`
	IsPrimaryKey    bool    `json:"is_primary_key"`
	IsAutoIncrement bool    `json:"is_auto_increment"`
	IsUnique        bool    `json:"is_unique"`
	Comment         string  `json:"comment,omitempty"`
}

Column describes a single column within a table or view.

type ErrorDetail

type ErrorDetail struct {
	Code    int                    `json:"code"`
	Message string                 `json:"message"`
	Context map[string]interface{} `json:"context,omitempty"`
}

ErrorDetail contains the structured error information returned by the API.

type ErrorResponse

type ErrorResponse struct {
	Error ErrorDetail `json:"error"`
}

ErrorResponse is the standard envelope for error responses.

type Filter

type Filter struct {
	Name     string `json:"name"`
	Operator string `json:"operator"`
	Value    string `json:"value"`
}

Filter defines a row-level filter applied to a role access rule.

type ForeignKey

type ForeignKey struct {
	Name             string `json:"name"`
	ColumnName       string `json:"column_name"`
	ReferencedTable  string `json:"referenced_table"`
	ReferencedColumn string `json:"referenced_column"`
	OnDelete         string `json:"on_delete"`
	OnUpdate         string `json:"on_update"`
}

ForeignKey describes a foreign key constraint between two tables.

type Index

type Index struct {
	Name     string   `json:"name"`
	Columns  []string `json:"columns"`
	IsUnique bool     `json:"is_unique"`
}

Index describes a database index on one or more columns.

type ListResponse

type ListResponse struct {
	Resource []map[string]interface{} `json:"resource"`
	Meta     *ResponseMeta            `json:"meta,omitempty"`
}

ListResponse is the standard envelope for list endpoints, wrapping results in a "resource" array with optional pagination metadata.

type PoolConfig

type PoolConfig struct {
	MaxOpenConns    int           `yaml:"max_open_conns" json:"max_open_conns"`
	MaxIdleConns    int           `yaml:"max_idle_conns" json:"max_idle_conns"`
	ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" json:"conn_max_lifetime"`
	ConnMaxIdleTime time.Duration `yaml:"conn_max_idle_time" json:"conn_max_idle_time"`
	PingInterval    time.Duration `yaml:"ping_interval" json:"ping_interval"`
}

PoolConfig controls the database connection pool behavior for a service.

func DefaultPoolConfig

func DefaultPoolConfig() PoolConfig

DefaultPoolConfig returns sensible defaults for a database connection pool.

type ProcedureParam

type ProcedureParam struct {
	Name      string `json:"name"`
	Type      string `json:"type"`
	Direction string `json:"direction"` // "in", "out", "inout"
}

ProcedureParam describes a single parameter of a stored procedure or function.

type ResponseMeta

type ResponseMeta struct {
	Count      int     `json:"count"`
	Total      *int64  `json:"total,omitempty"`
	Limit      int     `json:"limit"`
	Offset     int     `json:"offset"`
	NextCursor string  `json:"next_cursor,omitempty"`
	TookMs     float64 `json:"took_ms"`
}

ResponseMeta contains pagination and timing information for list responses.

type Role

type Role struct {
	ID          int64        `json:"id" db:"id"`
	Name        string       `json:"name" db:"name"`
	Description string       `json:"description" db:"description"`
	IsActive    bool         `json:"is_active" db:"is_active"`
	Access      []RoleAccess `json:"access"`
	CreatedAt   time.Time    `json:"created_at" db:"created_at"`
	UpdatedAt   time.Time    `json:"updated_at" db:"updated_at"`
}

Role defines an RBAC role that groups a set of access rules together. API keys are bound to roles to determine what operations they can perform.

type RoleAccess

type RoleAccess struct {
	ID            int64    `json:"id" db:"id"`
	RoleID        int64    `json:"role_id" db:"role_id"`
	ServiceName   string   `json:"service_name" db:"service_name"`
	Component     string   `json:"component" db:"component"`
	VerbMask      int      `json:"verb_mask" db:"verb_mask"`
	RequestorMask int      `json:"requestor_mask" db:"requestor_mask"`
	Filters       []Filter `json:"filters"`
	FilterOp      string   `json:"filter_op" db:"filter_op"`
}

RoleAccess defines a single access rule within a role, controlling which HTTP verbs are allowed on a specific service component.

type Schema

type Schema struct {
	Tables     []TableSchema     `json:"tables"`
	Views      []TableSchema     `json:"views"`
	Procedures []StoredProcedure `json:"procedures"`
	Functions  []StoredProcedure `json:"functions"`
}

Schema represents the full introspection result for a database service, including tables, views, stored procedures, and functions.

type ServiceConfig

type ServiceConfig struct {
	ID             int64      `json:"id" db:"id"`
	Name           string     `json:"name" db:"name"`
	Label          string     `json:"label" db:"label"`
	Driver         string     `json:"driver" db:"driver"`     // postgres, mysql, mssql, snowflake, sqlite
	DSN            string     `json:"dsn,omitempty" db:"dsn"` // Accepted on input; omitted in list responses via serviceToMap
	PrivateKeyPath string     `json:"private_key_path,omitempty" db:"private_key_path"`
	Schema         string     `json:"schema" db:"schema_name"`
	ReadOnly       bool       `json:"read_only" db:"read_only"`
	RawSQL         bool       `json:"raw_sql_allowed" db:"raw_sql_allowed"`
	IsActive       bool       `json:"is_active" db:"is_active"`
	SchemaLock     string     `json:"schema_lock" db:"schema_lock"`
	Pool           PoolConfig `json:"pool"`
	CreatedAt      time.Time  `json:"created_at" db:"created_at"`
	UpdatedAt      time.Time  `json:"updated_at" db:"updated_at"`
}

ServiceConfig holds the configuration for a database service connection. Each service maps to one database and is exposed as an API namespace.

type StoredProcedure

type StoredProcedure struct {
	Name       string           `json:"name"`
	Type       string           `json:"type"` // "procedure" or "function"
	ReturnType string           `json:"return_type,omitempty"`
	Parameters []ProcedureParam `json:"parameters,omitempty"`
}

StoredProcedure describes a stored procedure or function in the database.

type TableSchema

type TableSchema struct {
	Name        string       `json:"name"`
	Type        string       `json:"type"` // "table" or "view"
	Columns     []Column     `json:"columns"`
	PrimaryKey  []string     `json:"primary_key"`
	ForeignKeys []ForeignKey `json:"foreign_keys"`
	Indexes     []Index      `json:"indexes"`
	RowCount    *int64       `json:"row_count,omitempty"`
}

TableSchema describes the structure of a single table or view.

Jump to

Keyboard shortcuts

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