adapter

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package adapter provides adapters for the access control system

Package adapter provides adapters between database interfaces and domain models

Package adapter provides adapters between database interfaces and domain models

Package adapter provides adapters for the security access control system

Package adapter provides adapters between database interfaces and domain models

Package adapter provides adapters between database interfaces and domain models

Package adapter provides adapters between database interfaces and domain models

Package adapter provides adapters between database interfaces and domain models

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAuditStoreAdapter

func NewAuditStoreAdapter(store ModelsAuditStore) interfaces.AuditLogger

NewAuditStoreAdapter creates a new adapter for models.AuditEvent store

func NewIncidentStoreAdapter

func NewIncidentStoreAdapter(store IncidentStore) interfaces.IncidentStore

NewIncidentStoreAdapter creates a new incident store adapter

func NewVulnerabilityStoreAdapter

func NewVulnerabilityStoreAdapter(store interfaces.VulnerabilityStore) interfaces.VulnerabilityStore

NewVulnerabilityStoreAdapter creates a new vulnerability store adapter

Types

type AuditEvent

type AuditEvent struct {
	ID          string
	Timestamp   time.Time
	UserID      string
	Username    string
	Action      string
	Resource    string
	ResourceID  string
	Description string
	IPAddress   string
	UserAgent   string
	Severity    string
	Status      string
	SessionID   string
	Details     map[string]interface{}
	Changes     map[string]interface{}
	Metadata    map[string]interface{}
}

AuditEvent represents an entry in the audit log

type AuditEventFilter

type AuditEventFilter struct {
	UserID     string
	Username   string
	Action     string
	Resource   string
	ResourceID string
	IPAddress  string
	Severity   string
	Status     string
	SessionID  string
	StartTime  time.Time
	EndTime    time.Time
	Offset     int
	Limit      int
}

AuditEventFilter represents a filter for querying audit logs

type AuditStoreAdapter

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

AuditStoreAdapter adapts a models.AuditEvent store to the AuditStore interface

func (*AuditStoreAdapter) Close

func (a *AuditStoreAdapter) Close() error

Close closes the audit store

func (*AuditStoreAdapter) ExportEvents

func (a *AuditStoreAdapter) ExportEvents(ctx context.Context, filter map[string]interface{}, format string) (string, error)

ExportEvents exports audit events to a file

func (*AuditStoreAdapter) GetEventByID

func (a *AuditStoreAdapter) GetEventByID(ctx context.Context, id string) (*models.AuditLog, error)

GetEventByID retrieves an audit event by ID

func (*AuditStoreAdapter) LogEvent

func (a *AuditStoreAdapter) LogEvent(ctx context.Context, event *models.AuditLog) error

LogEvent logs an audit event

func (*AuditStoreAdapter) QueryEvents

func (a *AuditStoreAdapter) QueryEvents(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*models.AuditLog, int, error)

QueryEvents queries audit events with filtering

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 DBVulnerability

type DBVulnerability struct {
	ID              string
	Title           string
	Description     string
	CVE             string
	Severity        string
	Status          string
	AffectedSystems []string
	ReportedBy      string
	AssignedTo      string
	ReportedAt      string
	MitigatedAt     string
	MitigatedBy     string
	ResolvedAt      string
	ResolvedBy      string
	Metadata        map[string]interface{}
}

DBVulnerability represents a security vulnerability in the database

type DBVulnerabilityStore

type DBVulnerabilityStore interface {
	// CreateVulnerability creates a new vulnerability
	CreateVulnerability(ctx context.Context, vulnerability *interfaces.Vulnerability) error

	// GetVulnerabilityByID retrieves a vulnerability by ID
	GetVulnerabilityByID(ctx context.Context, id string) (*interfaces.Vulnerability, error)

	// GetVulnerabilityByCVE retrieves a vulnerability by CVE ID
	GetVulnerabilityByCVE(ctx context.Context, cve string) (*interfaces.Vulnerability, error)

	// UpdateVulnerability updates an existing vulnerability
	UpdateVulnerability(ctx context.Context, vulnerability *interfaces.Vulnerability) error

	// DeleteVulnerability deletes a vulnerability
	DeleteVulnerability(ctx context.Context, id string) error

	// ListVulnerabilities lists vulnerabilities with optional filtering
	ListVulnerabilities(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*interfaces.Vulnerability, int, error)

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

DBVulnerabilityStore defines the interface for vulnerability storage operations in the database

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) CreateSessionStoreAdapter

func (f *Factory) CreateSessionStoreAdapter() (*SessionStoreAdapter, error)

CreateSessionStoreAdapter creates a new session store adapter

func (*Factory) CreateUserStoreAdapter

func (f *Factory) CreateUserStoreAdapter() (*UserStoreAdapter, error)

CreateUserStoreAdapter creates a new user store adapter

type IncidentEvent

type IncidentEvent struct {
	ID          string
	Title       string
	Description string
	Severity    string
	Status      string
	ReportedBy  string
	AssignedTo  string
	CreatedAt   string
	UpdatedAt   string
	ResolvedAt  string
	Metadata    map[string]interface{}
}

IncidentEvent represents a security incident

type IncidentStore

type IncidentStore interface {
	// CreateIncident creates a new security incident
	CreateIncident(ctx context.Context, incident *IncidentEvent) error

	// GetIncidentByID retrieves a security incident by ID
	GetIncidentByID(ctx context.Context, id string) (*IncidentEvent, error)

	// UpdateIncident updates an existing security incident
	UpdateIncident(ctx context.Context, incident *IncidentEvent) error

	// DeleteIncident deletes a security incident
	DeleteIncident(ctx context.Context, id string) error

	// ListIncidents lists security incidents with optional filtering
	ListIncidents(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*IncidentEvent, int, error)

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

IncidentStore defines the interface for security incident storage operations

type IncidentStoreAdapter

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

IncidentStoreAdapter adapts between the IncidentStore and domain types

func (*IncidentStoreAdapter) Close

func (a *IncidentStoreAdapter) Close() error

Close closes the incident store

func (*IncidentStoreAdapter) CreateIncident

func (a *IncidentStoreAdapter) CreateIncident(ctx context.Context, incident *interfaces.SecurityIncident) error

CreateIncident creates a new security incident

func (*IncidentStoreAdapter) DeleteIncident

func (a *IncidentStoreAdapter) DeleteIncident(ctx context.Context, id string) error

DeleteIncident deletes a security incident

func (*IncidentStoreAdapter) GetIncidentByID

GetIncidentByID retrieves a security incident by ID

func (*IncidentStoreAdapter) ListIncidents

func (a *IncidentStoreAdapter) ListIncidents(ctx context.Context, filter map[string]interface{}, offset, limit int) ([]*interfaces.SecurityIncident, int, error)

ListIncidents lists security incidents with optional filtering

func (*IncidentStoreAdapter) UpdateIncident

func (a *IncidentStoreAdapter) UpdateIncident(ctx context.Context, incident *interfaces.SecurityIncident) error

UpdateIncident updates an existing security incident

type ModelsAuditStore

type ModelsAuditStore interface {
	LogEvent(ctx context.Context, event *AuditEvent) error
	GetEventByID(ctx context.Context, id string) (*AuditEvent, error)
	QueryEvents(ctx context.Context, filter *AuditEventFilter, offset, limit int) ([]*AuditEvent, int, error)
	ExportEvents(ctx context.Context, filter *AuditEventFilter, format string) (string, error)
	Close() error
}

ModelsAuditStore defines the interface for audit storage operations using models.AuditEvent

type Session

type Session struct {
	ID             string
	UserID         string
	Token          string
	RefreshToken   string
	ExpiresAt      time.Time
	CreatedAt      time.Time
	LastActivityAt time.Time
	IPAddress      string
	UserAgent      string
	Metadata       string
}

Session represents a user session

type SessionStore

type SessionStore interface {
	// CreateSession creates a new session
	CreateSession(ctx context.Context, session *Session) error

	// GetSessionByID retrieves a session by ID
	GetSessionByID(ctx context.Context, id string) (*Session, error)

	// GetSessionByToken retrieves a session by token
	GetSessionByToken(ctx context.Context, token string) (*Session, error)

	// GetSessionByRefreshToken retrieves a session by refresh token
	GetSessionByRefreshToken(ctx context.Context, refreshToken string) (*Session, error)

	// UpdateSession updates an existing session
	UpdateSession(ctx context.Context, session *Session) error

	// DeleteSession deletes a session
	DeleteSession(ctx context.Context, id string) error

	// DeleteSessionsByUserID deletes all sessions for a user
	DeleteSessionsByUserID(ctx context.Context, userID string) error

	// ListSessionsByUserID lists sessions for a user
	ListSessionsByUserID(ctx context.Context, userID string) ([]*Session, error)

	// CleanExpiredSessions removes expired sessions
	CleanExpiredSessions(ctx context.Context) (int, error)

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

SessionStore defines the interface for session storage operations

type SessionStoreAdapter

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

SessionStoreAdapter adapts between the adapter.SessionStore and interfaces.SessionStore

func NewSessionStoreAdapter

func NewSessionStoreAdapter(store SessionStore) *SessionStoreAdapter

NewSessionStoreAdapter creates a new session store adapter

func (*SessionStoreAdapter) CleanExpiredSessions

func (a *SessionStoreAdapter) CleanExpiredSessions(ctx context.Context) (int, error)

CleanExpiredSessions removes all expired sessions

func (*SessionStoreAdapter) Close

func (a *SessionStoreAdapter) Close() error

Close closes the session store

func (*SessionStoreAdapter) CreateSession

func (a *SessionStoreAdapter) CreateSession(ctx context.Context, session *interfaces.Session) error

CreateSession creates a new session

func (*SessionStoreAdapter) DeleteSession

func (a *SessionStoreAdapter) DeleteSession(ctx context.Context, id string) error

DeleteSession deletes a session by ID

func (*SessionStoreAdapter) DeleteSessionsByUserID

func (a *SessionStoreAdapter) DeleteSessionsByUserID(ctx context.Context, userID string) error

DeleteSessionsByUserID deletes all sessions for a user

func (*SessionStoreAdapter) GetSessionByID

func (a *SessionStoreAdapter) GetSessionByID(ctx context.Context, id string) (*interfaces.Session, error)

GetSessionByID retrieves a session by ID

func (*SessionStoreAdapter) GetSessionByRefreshToken

func (a *SessionStoreAdapter) GetSessionByRefreshToken(ctx context.Context, refreshToken string) (*interfaces.Session, error)

GetSessionByRefreshToken retrieves a session by refresh token

func (*SessionStoreAdapter) GetSessionByToken

func (a *SessionStoreAdapter) GetSessionByToken(ctx context.Context, token string) (*interfaces.Session, error)

GetSessionByToken retrieves a session by token

func (*SessionStoreAdapter) ListSessionsByUserID

func (a *SessionStoreAdapter) ListSessionsByUserID(ctx context.Context, userID string) ([]*interfaces.Session, error)

ListSessionsByUserID lists sessions for a user

func (*SessionStoreAdapter) UpdateSession

func (a *SessionStoreAdapter) UpdateSession(ctx context.Context, session *interfaces.Session) error

UpdateSession updates an existing session

type UserStoreAdapter

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

UserStoreAdapter adapts between the interfaces.UserStore and domain types

func NewUserStoreAdapter

func NewUserStoreAdapter(store interfaces.UserStore) *UserStoreAdapter

NewUserStoreAdapter creates a new user store adapter

func (*UserStoreAdapter) Close

func (a *UserStoreAdapter) Close() error

Close closes the user store

func (*UserStoreAdapter) CreateUser

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

CreateUser creates a new user

func (*UserStoreAdapter) DeleteUser

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

DeleteUser deletes a user by ID

func (*UserStoreAdapter) GetUserByEmail

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

GetUserByEmail retrieves a user by email

func (*UserStoreAdapter) GetUserByID

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

GetUserByID retrieves a user by ID

func (*UserStoreAdapter) GetUserByUsername

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

GetUserByUsername retrieves a user by username

func (*UserStoreAdapter) ListUsers

func (a *UserStoreAdapter) ListUsers(ctx context.Context) ([]*models.User, error)

ListUsers lists all users

func (*UserStoreAdapter) UpdateUser

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

UpdateUser updates an existing user

type VulnerabilityStoreAdapter

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

VulnerabilityStoreAdapter adapts between the database and interfaces.VulnerabilityStore

func (*VulnerabilityStoreAdapter) Close

func (a *VulnerabilityStoreAdapter) Close() error

Close closes the vulnerability store

func (*VulnerabilityStoreAdapter) CreateVulnerability

func (a *VulnerabilityStoreAdapter) CreateVulnerability(ctx context.Context, vulnerability *interfaces.Vulnerability) error

CreateVulnerability creates a new vulnerability

func (*VulnerabilityStoreAdapter) DeleteVulnerability

func (a *VulnerabilityStoreAdapter) DeleteVulnerability(ctx context.Context, id string) error

DeleteVulnerability deletes a vulnerability

func (*VulnerabilityStoreAdapter) GetVulnerabilityByCVE

func (a *VulnerabilityStoreAdapter) GetVulnerabilityByCVE(ctx context.Context, cve string) (*interfaces.Vulnerability, error)

GetVulnerabilityByCVE retrieves a vulnerability by CVE ID

func (*VulnerabilityStoreAdapter) GetVulnerabilityByID

func (a *VulnerabilityStoreAdapter) GetVulnerabilityByID(ctx context.Context, id string) (*interfaces.Vulnerability, error)

GetVulnerabilityByID retrieves a vulnerability by ID

func (*VulnerabilityStoreAdapter) ListVulnerabilities

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

ListVulnerabilities lists vulnerabilities with optional filtering

func (*VulnerabilityStoreAdapter) UpdateVulnerability

func (a *VulnerabilityStoreAdapter) UpdateVulnerability(ctx context.Context, vulnerability *interfaces.Vulnerability) error

UpdateVulnerability updates an existing vulnerability

Jump to

Keyboard shortcuts

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