config

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: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when a requested resource does not exist in the store.

Functions

func HashAPIKey

func HashAPIKey(key string) string

HashAPIKey returns the hex-encoded SHA-256 hash of a raw API key string.

func WriteDefaultConfig

func WriteDefaultConfig(path string) error

WriteDefaultConfig writes the default configuration to a YAML file.

Types

type AuthConfig

type AuthConfig struct {
	JWTSecret    string `yaml:"jwt_secret"`
	JWTExpiry    string `yaml:"jwt_expiry"`
	APIKeyHeader string `yaml:"api_key_header"`
}

AuthConfig controls authentication settings.

type CORSConfig

type CORSConfig struct {
	Origins []string `yaml:"origins"`
	Methods []string `yaml:"methods"`
}

CORSConfig controls cross-origin resource sharing settings.

type LoggingConfig

type LoggingConfig struct {
	Level  string `yaml:"level"`
	Format string `yaml:"format"`
}

LoggingConfig controls log output.

type MCPConfig

type MCPConfig struct {
	Enabled       bool   `yaml:"enabled"`
	Transport     string `yaml:"transport"`
	RawSQLAllowed bool   `yaml:"raw_sql_allowed"`
	RawSQLTimeout string `yaml:"raw_sql_timeout"`
	RawSQLMaxRows int    `yaml:"raw_sql_max_rows"`
}

MCPConfig controls the MCP (Model Context Protocol) server.

type PoolYAMLConfig

type PoolYAMLConfig struct {
	MaxOpenConns    int    `yaml:"max_open_conns"`
	MaxIdleConns    int    `yaml:"max_idle_conns"`
	ConnMaxLifetime string `yaml:"conn_max_lifetime"`
}

PoolYAMLConfig controls the connection pool for a service in YAML config.

type ServerConfig

type ServerConfig struct {
	Host            string     `yaml:"host"`
	Port            int        `yaml:"port"`
	MaxBodySize     string     `yaml:"max_body_size"`
	MaxBatchSize    int        `yaml:"max_batch_size"`
	ShutdownTimeout string     `yaml:"shutdown_timeout"`
	CORS            CORSConfig `yaml:"cors"`
	TLS             TLSConfig  `yaml:"tls"`
}

ServerConfig controls the HTTP server behavior.

type ServiceYAML

type ServiceYAML struct {
	Name           string          `yaml:"name"`
	Driver         string          `yaml:"driver"`
	DSN            string          `yaml:"dsn"`
	PrivateKeyPath string          `yaml:"private_key_path,omitempty"` // PEM file for Snowflake JWT auth
	Schema         string          `yaml:"schema"`
	ReadOnly       bool            `yaml:"read_only"`
	RawSQL         bool            `yaml:"raw_sql_allowed"`
	Pool           *PoolYAMLConfig `yaml:"pool,omitempty"`
}

ServiceYAML defines a database service in the YAML configuration file.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store manages Faucet's internal configuration state backed by SQLite. It persists services, roles, API keys, and admin accounts.

func NewStore

func NewStore(dataDir string) (*Store, error)

NewStore creates a new config store. Pass empty string for in-memory.

func (*Store) Close

func (s *Store) Close() error

Close closes the underlying database connection.

func (*Store) CreateAPIKey

func (s *Store) CreateAPIKey(ctx context.Context, key *model.APIKey) error

CreateAPIKey inserts a new API key record. The key_hash must already be set (use HashAPIKey). The ID and CreatedAt fields are populated after insert.

func (*Store) CreateAdmin

func (s *Store) CreateAdmin(ctx context.Context, admin *model.Admin) error

CreateAdmin inserts a new admin account. The ID, CreatedAt, and UpdatedAt fields are populated after a successful insert.

func (*Store) CreateRole

func (s *Store) CreateRole(ctx context.Context, role *model.Role) error

CreateRole inserts a new role. The ID, CreatedAt, and UpdatedAt fields are populated after a successful insert.

func (*Store) CreateService

func (s *Store) CreateService(ctx context.Context, svc *model.ServiceConfig) error

CreateService inserts a new service configuration. The ID, CreatedAt, and UpdatedAt fields on svc are populated after a successful insert.

func (*Store) DeleteContract added in v0.1.6

func (s *Store) DeleteContract(ctx context.Context, serviceName, tableName string) error

DeleteContract removes a schema contract for a service/table pair.

func (*Store) DeleteRole

func (s *Store) DeleteRole(ctx context.Context, id int64) error

DeleteRole removes a role by ID. Associated role_access rows are cascade deleted by the foreign key constraint.

func (*Store) DeleteService

func (s *Store) DeleteService(ctx context.Context, id int64) error

DeleteService removes a service configuration by ID.

func (*Store) DeleteServiceContracts added in v0.1.6

func (s *Store) DeleteServiceContracts(ctx context.Context, serviceName string) (int64, error)

DeleteServiceContracts removes all schema contracts for a service.

func (*Store) DeleteSetting added in v0.1.3

func (s *Store) DeleteSetting(ctx context.Context, key string) error

DeleteSetting removes a setting by key.

func (*Store) GetAPIKeyByHash

func (s *Store) GetAPIKeyByHash(ctx context.Context, hash string) (*model.APIKey, error)

GetAPIKeyByHash looks up an API key by its SHA-256 hash.

func (*Store) GetAdminByEmail

func (s *Store) GetAdminByEmail(ctx context.Context, email string) (*model.Admin, error)

GetAdminByEmail returns an admin by email address.

func (*Store) GetContract added in v0.1.6

func (s *Store) GetContract(ctx context.Context, serviceName, tableName string) (*contract.Contract, error)

GetContract returns a single schema contract by service and table name.

func (*Store) GetRole

func (s *Store) GetRole(ctx context.Context, id int64) (*model.Role, error)

GetRole returns a role by ID, including its access rules.

func (*Store) GetRoleAccess

func (s *Store) GetRoleAccess(ctx context.Context, roleID int64) ([]model.RoleAccess, error)

GetRoleAccess returns all access rules for a role.

func (*Store) GetRoleByName

func (s *Store) GetRoleByName(ctx context.Context, name string) (*model.Role, error)

GetRoleByName returns a role by its unique name.

func (*Store) GetService

func (s *Store) GetService(ctx context.Context, id int64) (*model.ServiceConfig, error)

GetService returns a service by ID.

func (*Store) GetServiceByName

func (s *Store) GetServiceByName(ctx context.Context, name string) (*model.ServiceConfig, error)

GetServiceByName returns a service by its unique name.

func (*Store) GetSetting added in v0.1.3

func (s *Store) GetSetting(ctx context.Context, key string) (string, error)

GetSetting returns the value for a settings key, or ErrNotFound.

func (*Store) HasAnyAdmin

func (s *Store) HasAnyAdmin(ctx context.Context) (bool, error)

HasAnyAdmin reports whether at least one admin account exists. This is used for first-run detection to trigger the initial setup flow.

func (*Store) ListAPIKeys

func (s *Store) ListAPIKeys(ctx context.Context) ([]model.APIKey, error)

ListAPIKeys returns all API keys.

func (*Store) ListAdmins

func (s *Store) ListAdmins(ctx context.Context) ([]model.Admin, error)

ListAdmins returns all admin accounts.

func (*Store) ListContracts added in v0.1.6

func (s *Store) ListContracts(ctx context.Context, serviceName string) ([]contract.Contract, error)

ListContracts returns all schema contracts for a service.

func (*Store) ListRoles

func (s *Store) ListRoles(ctx context.Context) ([]model.Role, error)

ListRoles returns all configured roles with their access rules.

func (*Store) ListServices

func (s *Store) ListServices(ctx context.Context) ([]model.ServiceConfig, error)

ListServices returns all configured service definitions.

func (*Store) ListSettings added in v0.1.3

func (s *Store) ListSettings(ctx context.Context) (map[string]string, error)

ListSettings returns all key-value pairs from the settings table.

func (*Store) PromoteContract added in v0.1.6

func (s *Store) PromoteContract(ctx context.Context, serviceName, tableName string, schema model.TableSchema) error

PromoteContract updates a contract's schema to the latest live schema snapshot.

func (*Store) RevokeAPIKey

func (s *Store) RevokeAPIKey(ctx context.Context, id int64) error

RevokeAPIKey marks an API key as inactive by ID.

func (*Store) RevokeAPIKeyByPrefix

func (s *Store) RevokeAPIKeyByPrefix(ctx context.Context, prefix string) error

RevokeAPIKeyByPrefix marks an API key as inactive by its prefix.

func (*Store) SaveContract added in v0.1.6

func (s *Store) SaveContract(ctx context.Context, serviceName, tableName string, schema model.TableSchema) (*contract.Contract, error)

SaveContract creates or replaces a schema contract for a service/table pair.

func (*Store) SetRoleAccess

func (s *Store) SetRoleAccess(ctx context.Context, roleID int64, access []model.RoleAccess) error

SetRoleAccess replaces all access rules for a role within a transaction.

func (*Store) SetSetting added in v0.1.3

func (s *Store) SetSetting(ctx context.Context, key, value string) error

SetSetting upserts a key-value pair in the settings table.

func (*Store) UpdateAPIKeyLastUsed

func (s *Store) UpdateAPIKeyLastUsed(ctx context.Context, id int64) error

UpdateAPIKeyLastUsed sets the last_used timestamp for an API key.

func (*Store) UpdateAdminLastLogin

func (s *Store) UpdateAdminLastLogin(ctx context.Context, id int64) error

UpdateAdminLastLogin sets the last_login_at timestamp for an admin.

func (*Store) UpdateRole

func (s *Store) UpdateRole(ctx context.Context, role *model.Role) error

UpdateRole updates an existing role. The UpdatedAt field is refreshed automatically.

func (*Store) UpdateService

func (s *Store) UpdateService(ctx context.Context, svc *model.ServiceConfig) error

UpdateService updates an existing service configuration. The UpdatedAt field on svc is refreshed automatically.

type TLSConfig

type TLSConfig struct {
	Enabled  bool   `yaml:"enabled"`
	CertFile string `yaml:"cert_file"`
	KeyFile  string `yaml:"key_file"`
}

TLSConfig controls TLS termination at the server level.

type YAMLConfig

type YAMLConfig struct {
	Server   ServerConfig  `yaml:"server"`
	Auth     AuthConfig    `yaml:"auth"`
	Services []ServiceYAML `yaml:"services"`
	MCP      MCPConfig     `yaml:"mcp"`
	Logging  LoggingConfig `yaml:"logging"`
}

YAMLConfig represents the top-level faucet configuration file.

func DefaultYAMLConfig

func DefaultYAMLConfig() *YAMLConfig

DefaultYAMLConfig returns a YAMLConfig pre-filled with sensible defaults.

func LoadYAMLConfig

func LoadYAMLConfig(path string) (*YAMLConfig, error)

LoadYAMLConfig reads and parses a YAML configuration file. Environment variables referenced as ${VAR_NAME} in the file are expanded before parsing.

Jump to

Keyboard shortcuts

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