Documentation
¶
Overview ¶
Package store provides database initialization and multi-tenant support.
Index ¶
- func DefaultPostgresDSN(host string, port int, user, password, dbname string) string
- func DefaultSQLiteDSN(path string) string
- func OrgFromContext(ctx context.Context) (int, bool)
- type Config
- type RLSHelper
- func (r *RLSHelper) ClearTenantContext(ctx context.Context) error
- func (r *RLSHelper) CreateBypassRole(ctx context.Context, roleName string) error
- func (r *RLSHelper) SetTenantContext(ctx context.Context, orgID int) error
- func (r *RLSHelper) SetTenantContextTx(ctx context.Context, tx *sql.Tx, orgID int) error
- func (r *RLSHelper) SetupRLS(ctx context.Context) error
- type Store
- type TrafficHandler
- type TrafficQuery
- func (q *TrafficQuery) ByHost(ctx context.Context, host string, limit int) ([]*ent.Traffic, error)
- func (q *TrafficQuery) ByTimeRange(ctx context.Context, start, end time.Time, limit int) ([]*ent.Traffic, error)
- func (q *TrafficQuery) GetStats(ctx context.Context) (*TrafficStats, error)
- func (q *TrafficQuery) Recent(ctx context.Context, limit int) ([]*ent.Traffic, error)
- type TrafficStats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultPostgresDSN ¶
DefaultPostgresDSN returns a default PostgreSQL connection string.
func DefaultSQLiteDSN ¶
DefaultSQLiteDSN returns a default SQLite connection string.
Types ¶
type Config ¶
type Config struct {
// Driver is the database driver: "sqlite3" or "postgres"
Driver string
// DSN is the data source name (connection string)
// SQLite: "file:omniproxy.db?cache=shared&_fk=1"
// PostgreSQL: "postgres://user:pass@host:5432/dbname?sslmode=disable"
DSN string
// EnableRLS enables PostgreSQL Row-Level Security for multi-tenancy
// Only applies when Driver is "postgres"
EnableRLS bool
// Debug enables Ent debug logging
Debug bool
}
Config holds database configuration.
type RLSHelper ¶
type RLSHelper struct {
// contains filtered or unexported fields
}
RLSHelper manages PostgreSQL Row-Level Security for multi-tenancy.
func (*RLSHelper) ClearTenantContext ¶
ClearTenantContext clears the tenant context.
func (*RLSHelper) CreateBypassRole ¶
CreateBypassRole creates a role that bypasses RLS (for admin/system operations).
func (*RLSHelper) SetTenantContext ¶
SetTenantContext sets the current tenant for RLS policies. This must be called at the start of each request/transaction.
func (*RLSHelper) SetTenantContextTx ¶
SetTenantContextTx sets the current tenant within a transaction.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store wraps the Ent client with multi-tenant support.
type TrafficHandler ¶
type TrafficHandler struct {
// contains filtered or unexported fields
}
TrafficHandler handles storing captured traffic in the database.
func NewTrafficHandler ¶
func NewTrafficHandler(client *ent.Client, proxyID int) *TrafficHandler
NewTrafficHandler creates a new traffic handler for a specific proxy.
func (*TrafficHandler) BatchStore ¶
BatchStore saves multiple records in a single transaction.
func (*TrafficHandler) Handle ¶
func (h *TrafficHandler) Handle(rec *capture.Record)
Handle stores a captured traffic record in the database. This implements the capture.Handler interface.
type TrafficQuery ¶
type TrafficQuery struct {
// contains filtered or unexported fields
}
TrafficQuery provides query helpers for traffic data.
func NewTrafficQuery ¶
func NewTrafficQuery(client *ent.Client, proxyID int) *TrafficQuery
NewTrafficQuery creates a new traffic query helper.
func (*TrafficQuery) ByTimeRange ¶
func (q *TrafficQuery) ByTimeRange(ctx context.Context, start, end time.Time, limit int) ([]*ent.Traffic, error)
ByTimeRange returns traffic records within a time range.
func (*TrafficQuery) GetStats ¶
func (q *TrafficQuery) GetStats(ctx context.Context) (*TrafficStats, error)
GetStats returns traffic statistics for the proxy.