db

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package db provides database implementations for the access control system

Package db provides database implementations of the access control interfaces

Package db provides database implementations of the access control interfaces

Package db provides database implementations of the access control interfaces

Package db provides database implementations of the access control interfaces

Package db provides database implementations of the security access control interfaces

Package db provides database implementations of the access control interfaces

Package db provides database implementations of the access control interfaces

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotFound is returned when a user is not found
	ErrUserNotFound = errors.New("user not found")
)

Error definitions

Functions

func NewSQLAuditStore

func NewSQLAuditStore(db *sql.DB) (adapter.ModelsAuditStore, error)

NewSQLAuditStore creates a new SQL-based audit store

func NewSQLIncidentStore

func NewSQLIncidentStore(db *sql.DB) (adapter.IncidentStore, error)

NewSQLIncidentStore creates a new SQL-based incident store

func NewSQLSessionStore

func NewSQLSessionStore(db *sql.DB) (adapter.SessionStore, error)

NewSQLSessionStore creates a new SQL-based session store

func NewSQLUserStore

func NewSQLUserStore(db *sql.DB) (interfaces.UserStore, error)

NewSQLUserStore creates a new SQL-based user store

func NewSQLVulnerabilityStore

func NewSQLVulnerabilityStore(db *sql.DB) (interfaces.VulnerabilityStore, error)

NewSQLVulnerabilityStore creates a new SQL-based vulnerability store

Types

type DBConfig

type DBConfig struct {
	// Driver is the database driver to use (e.g., "sqlite3", "postgres")
	Driver string

	// DSN is the data source name for the database connection
	DSN string

	// MaxOpenConns is the maximum number of open connections to the database
	MaxOpenConns int

	// MaxIdleConns is the maximum number of idle connections in the connection pool
	MaxIdleConns int
}

DBConfig contains configuration for database connections

func DefaultSQLiteConfig

func DefaultSQLiteConfig(dbPath string) *DBConfig

DefaultSQLiteConfig returns a default SQLite configuration

type Factory

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

Factory is a factory for creating database-backed access control components

func NewFactory

func NewFactory(config *DBConfig) (*Factory, error)

NewFactory creates a new database factory

func (*Factory) Close

func (f *Factory) Close() error

Close closes the database connection

func (*Factory) CreateAllStores

func (f *Factory) CreateAllStores() (map[string]interface{}, error)

CreateAllStores creates all stores and returns them in a map

func (*Factory) CreateAuditStore

func (f *Factory) CreateAuditStore() (interfaces.AuditLogger, error)

CreateAuditStore creates a new SQL-based audit store

func (*Factory) CreateIncidentStore

func (f *Factory) CreateIncidentStore() (interfaces.IncidentStore, error)

CreateIncidentStore creates a new SQL-based incident store

func (*Factory) CreateSessionStore

func (f *Factory) CreateSessionStore() (interfaces.SessionStore, error)

CreateSessionStore creates a new SQL-based session store

func (*Factory) CreateUserStore

func (f *Factory) CreateUserStore() (interfaces.UserStore, error)

CreateUserStore creates a new SQL-based user store

func (*Factory) CreateVulnerabilityStore

func (f *Factory) CreateVulnerabilityStore() (interfaces.VulnerabilityStore, error)

CreateVulnerabilityStore creates a new SQL-based vulnerability store

type ModelsUserStore

type ModelsUserStore interface {
	CreateUser(ctx context.Context, user *models.User) error
	GetUserByID(ctx context.Context, id string) (*models.User, error)
	GetUserByUsername(ctx context.Context, username string) (*models.User, error)
	GetUserByEmail(ctx context.Context, email string) (*models.User, error)
	UpdateUser(ctx context.Context, user *models.User) error
	DeleteUser(ctx context.Context, id string) error
	ListUsers(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*models.User, int, error)
	Close() error
}

ModelsUserStore defines the interface for user storage operations using models.User

type SQLAuditStore

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

SQLAuditStore is a SQL implementation of ModelsAuditStore

func (*SQLAuditStore) Close

func (s *SQLAuditStore) Close() error

Close closes the SQL connection

func (*SQLAuditStore) CountEvents

func (s *SQLAuditStore) CountEvents(ctx context.Context, filter *adapter.AuditEventFilter) (int64, error)

CountEvents counts audit events based on filters

func (*SQLAuditStore) ExportEvents

func (s *SQLAuditStore) ExportEvents(ctx context.Context, filter *adapter.AuditEventFilter, format string) (string, error)

ExportEvents exports audit events to a file

func (*SQLAuditStore) GetEventByID

func (s *SQLAuditStore) GetEventByID(ctx context.Context, id string) (*adapter.AuditEvent, error)

GetEventByID retrieves an audit event by ID

func (*SQLAuditStore) LogEvent

func (s *SQLAuditStore) LogEvent(ctx context.Context, event *adapter.AuditEvent) error

LogEvent logs an audit event

func (*SQLAuditStore) QueryEvents

func (s *SQLAuditStore) QueryEvents(ctx context.Context, filter *adapter.AuditEventFilter, offset, limit int) ([]*adapter.AuditEvent, int, error)

QueryEvents queries audit events based on filters

type SQLIncidentStore

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

SQLIncidentStore is a SQL implementation of IncidentStore

func (*SQLIncidentStore) Close

func (s *SQLIncidentStore) Close() error

Close closes the SQL connection

func (*SQLIncidentStore) CreateIncident

func (s *SQLIncidentStore) CreateIncident(ctx context.Context, incident *adapter.IncidentEvent) error

CreateIncident creates a new security incident

func (*SQLIncidentStore) DeleteIncident

func (s *SQLIncidentStore) DeleteIncident(ctx context.Context, id string) error

DeleteIncident deletes a security incident

func (*SQLIncidentStore) GetIncidentByID

func (s *SQLIncidentStore) GetIncidentByID(ctx context.Context, id string) (*adapter.IncidentEvent, error)

GetIncidentByID retrieves a security incident by ID

func (*SQLIncidentStore) ListIncidents

func (s *SQLIncidentStore) ListIncidents(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*adapter.IncidentEvent, int, error)

ListIncidents lists security incidents with optional filtering

func (*SQLIncidentStore) UpdateIncident

func (s *SQLIncidentStore) UpdateIncident(ctx context.Context, incident *adapter.IncidentEvent) error

UpdateIncident updates an existing security incident

type SQLSessionStore

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

SQLSessionStore is a SQL implementation of SessionStore

func (*SQLSessionStore) CleanExpiredSessions

func (s *SQLSessionStore) CleanExpiredSessions(ctx context.Context) (int, error)

CleanExpiredSessions removes expired sessions

func (*SQLSessionStore) Close

func (s *SQLSessionStore) Close() error

Close closes the SQL connection

func (*SQLSessionStore) CreateSession

func (s *SQLSessionStore) CreateSession(ctx context.Context, session *adapter.Session) error

CreateSession creates a new session

func (*SQLSessionStore) DeleteSession

func (s *SQLSessionStore) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session

func (*SQLSessionStore) DeleteSessionsByUserID

func (s *SQLSessionStore) DeleteSessionsByUserID(ctx context.Context, userID string) error

DeleteSessionsByUserID deletes all sessions for a user

func (*SQLSessionStore) GetSessionByID

func (s *SQLSessionStore) GetSessionByID(ctx context.Context, id string) (*adapter.Session, error)

GetSessionByID retrieves a session by ID

func (*SQLSessionStore) GetSessionByRefreshToken

func (s *SQLSessionStore) GetSessionByRefreshToken(ctx context.Context, refreshToken string) (*adapter.Session, error)

GetSessionByRefreshToken retrieves a session by refresh token

func (*SQLSessionStore) GetSessionByToken

func (s *SQLSessionStore) GetSessionByToken(ctx context.Context, token string) (*adapter.Session, error)

GetSessionByToken retrieves a session by token

func (*SQLSessionStore) ListSessionsByUserID

func (s *SQLSessionStore) ListSessionsByUserID(ctx context.Context, userID string) ([]*adapter.Session, error)

ListSessionsByUserID lists sessions for a user

func (*SQLSessionStore) UpdateSession

func (s *SQLSessionStore) UpdateSession(ctx context.Context, session *adapter.Session) error

UpdateSession updates an existing session

type SQLUserStore

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

SQLUserStore is a SQL implementation of UserStore

func (*SQLUserStore) Close

func (s *SQLUserStore) Close() error

Close closes the user store

func (*SQLUserStore) CreateUser

func (s *SQLUserStore) CreateUser(ctx context.Context, user *interfaces.User) error

CreateUser creates a new user

func (*SQLUserStore) DeleteUser

func (s *SQLUserStore) DeleteUser(ctx context.Context, id string) error

DeleteUser deletes a user by ID

func (*SQLUserStore) GetUserByEmail

func (s *SQLUserStore) GetUserByEmail(ctx context.Context, email string) (*interfaces.User, error)

GetUserByEmail retrieves a user by email

func (*SQLUserStore) GetUserByID

func (s *SQLUserStore) GetUserByID(ctx context.Context, id string) (*interfaces.User, error)

GetUserByID retrieves a user by ID

func (*SQLUserStore) GetUserByUsername

func (s *SQLUserStore) GetUserByUsername(ctx context.Context, username string) (*interfaces.User, error)

GetUserByUsername retrieves a user by username

func (*SQLUserStore) ListUsers

func (s *SQLUserStore) ListUsers(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*interfaces.User, int, error)

ListUsers lists all users

func (*SQLUserStore) UpdateUser

func (s *SQLUserStore) UpdateUser(ctx context.Context, user *interfaces.User) error

UpdateUser updates an existing user

type SQLVulnerabilityStore

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

SQLVulnerabilityStore is a SQL implementation of VulnerabilityStore

func (*SQLVulnerabilityStore) Close

func (s *SQLVulnerabilityStore) Close() error

Close closes the SQL connection

func (*SQLVulnerabilityStore) CreateVulnerability

func (s *SQLVulnerabilityStore) CreateVulnerability(ctx context.Context, vulnerability *interfaces.Vulnerability) error

CreateVulnerability creates a new vulnerability

func (*SQLVulnerabilityStore) DeleteVulnerability

func (s *SQLVulnerabilityStore) DeleteVulnerability(ctx context.Context, id string) error

DeleteVulnerability deletes a vulnerability

func (*SQLVulnerabilityStore) GetVulnerabilityByCVE

func (s *SQLVulnerabilityStore) GetVulnerabilityByCVE(ctx context.Context, cve string) (*interfaces.Vulnerability, error)

GetVulnerabilityByCVE retrieves a vulnerability by CVE ID

func (*SQLVulnerabilityStore) GetVulnerabilityByID

func (s *SQLVulnerabilityStore) GetVulnerabilityByID(ctx context.Context, id string) (*interfaces.Vulnerability, error)

GetVulnerabilityByID retrieves a vulnerability by ID

func (*SQLVulnerabilityStore) ListVulnerabilities

func (s *SQLVulnerabilityStore) ListVulnerabilities(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*interfaces.Vulnerability, int, error)

ListVulnerabilities lists vulnerabilities with optional filtering

func (*SQLVulnerabilityStore) UpdateVulnerability

func (s *SQLVulnerabilityStore) UpdateVulnerability(ctx context.Context, vulnerability *interfaces.Vulnerability) error

UpdateVulnerability updates an existing vulnerability

type UserStore

type UserStore interface {
	// CreateUser creates a new user
	CreateUser(ctx context.Context, user *common.User) error

	// GetUserByID retrieves a user by ID
	GetUserByID(ctx context.Context, id string) (*common.User, error)

	// GetUserByUsername retrieves a user by username
	GetUserByUsername(ctx context.Context, username string) (*common.User, error)

	// GetUserByEmail retrieves a user by email
	GetUserByEmail(ctx context.Context, email string) (*common.User, error)

	// UpdateUser updates an existing user
	UpdateUser(ctx context.Context, user *common.User) error

	// DeleteUser deletes a user
	DeleteUser(ctx context.Context, id string) error

	// ListUsers lists users with optional filtering
	ListUsers(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*common.User, int, error)

	// Close closes the user store
	Close() error
}

UserStore defines the interface for user storage operations using common.User

func NewUserStoreAdapter

func NewUserStoreAdapter(store ModelsUserStore) UserStore

NewUserStoreAdapter creates a new adapter for models.User store

type UserStoreAdapter

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

UserStoreAdapter adapts a models.User store to the UserStore interface

func (*UserStoreAdapter) Close

func (a *UserStoreAdapter) Close() error

Close closes the user store

func (*UserStoreAdapter) CreateUser

func (a *UserStoreAdapter) CreateUser(ctx context.Context, user *common.User) error

CreateUser creates a new user

func (*UserStoreAdapter) DeleteUser

func (a *UserStoreAdapter) DeleteUser(ctx context.Context, id string) error

DeleteUser deletes a user

func (*UserStoreAdapter) GetUserByEmail

func (a *UserStoreAdapter) GetUserByEmail(ctx context.Context, email string) (*common.User, error)

GetUserByEmail retrieves a user by email

func (*UserStoreAdapter) GetUserByID

func (a *UserStoreAdapter) GetUserByID(ctx context.Context, id string) (*common.User, error)

GetUserByID retrieves a user by ID

func (*UserStoreAdapter) GetUserByUsername

func (a *UserStoreAdapter) GetUserByUsername(ctx context.Context, username string) (*common.User, error)

GetUserByUsername retrieves a user by username

func (*UserStoreAdapter) ListUsers

func (a *UserStoreAdapter) ListUsers(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*common.User, int, error)

ListUsers lists users with optional filtering

func (*UserStoreAdapter) UpdateUser

func (a *UserStoreAdapter) UpdateUser(ctx context.Context, user *common.User) error

UpdateUser updates an existing user

Directories

Path Synopsis
Package adapter provides adapters for the access control system
Package adapter provides adapters for the access control system

Jump to

Keyboard shortcuts

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