Documentation
¶
Index ¶
- Variables
- func HashAPIKey(key string) string
- func WriteDefaultConfig(path string) error
- type AuthConfig
- type CORSConfig
- type LoggingConfig
- type MCPConfig
- type PoolYAMLConfig
- type ServerConfig
- type ServiceYAML
- type Store
- func (s *Store) Close() error
- func (s *Store) CreateAPIKey(ctx context.Context, key *model.APIKey) error
- func (s *Store) CreateAdmin(ctx context.Context, admin *model.Admin) error
- func (s *Store) CreateRole(ctx context.Context, role *model.Role) error
- func (s *Store) CreateService(ctx context.Context, svc *model.ServiceConfig) error
- func (s *Store) DeleteContract(ctx context.Context, serviceName, tableName string) error
- func (s *Store) DeleteRole(ctx context.Context, id int64) error
- func (s *Store) DeleteService(ctx context.Context, id int64) error
- func (s *Store) DeleteServiceContracts(ctx context.Context, serviceName string) (int64, error)
- func (s *Store) DeleteSetting(ctx context.Context, key string) error
- func (s *Store) GetAPIKeyByHash(ctx context.Context, hash string) (*model.APIKey, error)
- func (s *Store) GetAdminByEmail(ctx context.Context, email string) (*model.Admin, error)
- func (s *Store) GetContract(ctx context.Context, serviceName, tableName string) (*contract.Contract, error)
- func (s *Store) GetRole(ctx context.Context, id int64) (*model.Role, error)
- func (s *Store) GetRoleAccess(ctx context.Context, roleID int64) ([]model.RoleAccess, error)
- func (s *Store) GetRoleByName(ctx context.Context, name string) (*model.Role, error)
- func (s *Store) GetService(ctx context.Context, id int64) (*model.ServiceConfig, error)
- func (s *Store) GetServiceByName(ctx context.Context, name string) (*model.ServiceConfig, error)
- func (s *Store) GetSetting(ctx context.Context, key string) (string, error)
- func (s *Store) HasAnyAdmin(ctx context.Context) (bool, error)
- func (s *Store) ListAPIKeys(ctx context.Context) ([]model.APIKey, error)
- func (s *Store) ListAdmins(ctx context.Context) ([]model.Admin, error)
- func (s *Store) ListContracts(ctx context.Context, serviceName string) ([]contract.Contract, error)
- func (s *Store) ListRoles(ctx context.Context) ([]model.Role, error)
- func (s *Store) ListServices(ctx context.Context) ([]model.ServiceConfig, error)
- func (s *Store) ListSettings(ctx context.Context) (map[string]string, error)
- func (s *Store) PromoteContract(ctx context.Context, serviceName, tableName string, schema model.TableSchema) error
- func (s *Store) RevokeAPIKey(ctx context.Context, id int64) error
- func (s *Store) RevokeAPIKeyByPrefix(ctx context.Context, prefix string) error
- func (s *Store) SaveContract(ctx context.Context, serviceName, tableName string, schema model.TableSchema) (*contract.Contract, error)
- func (s *Store) SetRoleAccess(ctx context.Context, roleID int64, access []model.RoleAccess) error
- func (s *Store) SetSetting(ctx context.Context, key, value string) error
- func (s *Store) UpdateAPIKeyLastUsed(ctx context.Context, id int64) error
- func (s *Store) UpdateAdminLastLogin(ctx context.Context, id int64) error
- func (s *Store) UpdateRole(ctx context.Context, role *model.Role) error
- func (s *Store) UpdateService(ctx context.Context, svc *model.ServiceConfig) error
- type TLSConfig
- type YAMLConfig
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when a requested resource does not exist in the store.
Functions ¶
func HashAPIKey ¶
HashAPIKey returns the hex-encoded SHA-256 hash of a raw API key string.
func WriteDefaultConfig ¶
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 ¶
CORSConfig controls cross-origin resource sharing settings.
type LoggingConfig ¶
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 (*Store) CreateAPIKey ¶
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 ¶
CreateAdmin inserts a new admin account. The ID, CreatedAt, and UpdatedAt fields are populated after a successful insert.
func (*Store) CreateRole ¶
CreateRole inserts a new role. The ID, CreatedAt, and UpdatedAt fields are populated after a successful insert.
func (*Store) CreateService ¶
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
DeleteContract removes a schema contract for a service/table pair.
func (*Store) DeleteRole ¶
DeleteRole removes a role by ID. Associated role_access rows are cascade deleted by the foreign key constraint.
func (*Store) DeleteService ¶
DeleteService removes a service configuration by ID.
func (*Store) DeleteServiceContracts ¶ added in v0.1.6
DeleteServiceContracts removes all schema contracts for a service.
func (*Store) DeleteSetting ¶ added in v0.1.3
DeleteSetting removes a setting by key.
func (*Store) GetAPIKeyByHash ¶
GetAPIKeyByHash looks up an API key by its SHA-256 hash.
func (*Store) GetAdminByEmail ¶
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) GetRoleAccess ¶
GetRoleAccess returns all access rules for a role.
func (*Store) GetRoleByName ¶
GetRoleByName returns a role by its unique name.
func (*Store) GetService ¶
GetService returns a service by ID.
func (*Store) GetServiceByName ¶
GetServiceByName returns a service by its unique name.
func (*Store) GetSetting ¶ added in v0.1.3
GetSetting returns the value for a settings key, or ErrNotFound.
func (*Store) HasAnyAdmin ¶
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 ¶
ListAPIKeys returns all API keys.
func (*Store) ListAdmins ¶
ListAdmins returns all admin accounts.
func (*Store) ListContracts ¶ added in v0.1.6
ListContracts returns all schema contracts for a service.
func (*Store) ListServices ¶
ListServices returns all configured service definitions.
func (*Store) ListSettings ¶ added in v0.1.3
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 ¶
RevokeAPIKey marks an API key as inactive by ID.
func (*Store) RevokeAPIKeyByPrefix ¶
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 ¶
SetRoleAccess replaces all access rules for a role within a transaction.
func (*Store) SetSetting ¶ added in v0.1.3
SetSetting upserts a key-value pair in the settings table.
func (*Store) UpdateAPIKeyLastUsed ¶
UpdateAPIKeyLastUsed sets the last_used timestamp for an API key.
func (*Store) UpdateAdminLastLogin ¶
UpdateAdminLastLogin sets the last_login_at timestamp for an admin.
func (*Store) UpdateRole ¶
UpdateRole updates an existing role. The UpdatedAt field is refreshed automatically.
func (*Store) UpdateService ¶
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.