Documentation
¶
Overview ¶
Package services provides business logic services for Scanorama. This file implements host management functionality including CRUD operations and host scan history retrieval.
Package services provides business logic services for Scanorama. This file implements network management functionality including config-based network seeding, exclusion management, and integration with the discovery engine.
Package services provides business logic services for Scanorama. This file implements scan profile management functionality including CRUD operations and profile cloning.
Package services provides business logic for Scanorama operations. This file implements scan management, including input validation, profile verification, and enriched state-transition methods.
Package services provides business logic for Scanorama operations. This file implements schedule management, including cron-expression validation and a NextRun helper.
Index ¶
- Constants
- func ParsePortSpec(ports string) error
- func ValidateCronExpression(cronExpr string) error
- type HostService
- func (s *HostService) CreateHost(ctx context.Context, input db.CreateHostInput) (*db.Host, error)
- func (s *HostService) DeleteHost(ctx context.Context, id uuid.UUID) error
- func (s *HostService) GetHost(ctx context.Context, id uuid.UUID) (*db.Host, error)
- func (s *HostService) GetHostScans(ctx context.Context, hostID uuid.UUID, offset, limit int) ([]*db.Scan, int64, error)
- func (s *HostService) ListHosts(ctx context.Context, filters *db.HostFilters, offset, limit int) ([]*db.Host, int64, error)
- func (s *HostService) UpdateHost(ctx context.Context, id uuid.UUID, input db.UpdateHostInput) (*db.Host, error)
- type NetworkService
- func (s *NetworkService) AddExclusion(ctx context.Context, networkID *uuid.UUID, cidr, reason string) (*db.NetworkExclusion, error)
- func (s *NetworkService) CreateNetwork(ctx context.Context, name, cidr, description, method string, ...) (*db.Network, error)
- func (s *NetworkService) DeleteNetwork(ctx context.Context, id uuid.UUID) error
- func (s *NetworkService) GenerateTargetsForNetwork(ctx context.Context, networkID uuid.UUID, maxHosts int) ([]string, error)
- func (s *NetworkService) GetActiveNetworks(ctx context.Context) ([]*NetworkWithExclusions, error)
- func (s *NetworkService) GetGlobalExclusions(ctx context.Context) ([]*db.NetworkExclusion, error)
- func (s *NetworkService) GetNetworkByID(ctx context.Context, id uuid.UUID) (*NetworkWithExclusions, error)
- func (s *NetworkService) GetNetworkByName(ctx context.Context, name string) (*NetworkWithExclusions, error)
- func (s *NetworkService) GetNetworkExclusions(ctx context.Context, networkID uuid.UUID) ([]*db.NetworkExclusion, error)
- func (s *NetworkService) GetNetworkStats(ctx context.Context) (map[string]interface{}, error)
- func (s *NetworkService) ListNetworks(ctx context.Context, activeOnly bool) ([]*db.Network, error)
- func (s *NetworkService) RemoveExclusion(ctx context.Context, exclusionID uuid.UUID) error
- func (s *NetworkService) SeedNetworksFromConfig(ctx context.Context, cfg *config.Config) error
- func (s *NetworkService) UpdateNetwork(ctx context.Context, id uuid.UUID, name, cidr, description, method string, ...) (*db.Network, error)
- func (s *NetworkService) UpdateNetworkDiscoveryTime(ctx context.Context, networkID uuid.UUID, discoveredHosts, activeHosts int) error
- type NetworkWithExclusions
- type ProfileService
- func (s *ProfileService) CloneProfile(ctx context.Context, fromID, newName string) (*db.ScanProfile, error)
- func (s *ProfileService) CreateProfile(ctx context.Context, input db.CreateProfileInput) (*db.ScanProfile, error)
- func (s *ProfileService) DeleteProfile(ctx context.Context, id string) error
- func (s *ProfileService) GetProfile(ctx context.Context, id string) (*db.ScanProfile, error)
- func (s *ProfileService) ListProfiles(ctx context.Context, filters db.ProfileFilters, offset, limit int) ([]*db.ScanProfile, int64, error)
- func (s *ProfileService) UpdateProfile(ctx context.Context, id string, input db.UpdateProfileInput) (*db.ScanProfile, error)
- type ScanService
- func (s *ScanService) CompleteScan(ctx context.Context, id uuid.UUID) error
- func (s *ScanService) CreateScan(ctx context.Context, input db.CreateScanInput) (*db.Scan, error)
- func (s *ScanService) DB() *db.DB
- func (s *ScanService) DeleteScan(ctx context.Context, id uuid.UUID) error
- func (s *ScanService) GetProfile(ctx context.Context, id string) (*db.ScanProfile, error)
- func (s *ScanService) GetScan(ctx context.Context, id uuid.UUID) (*db.Scan, error)
- func (s *ScanService) GetScanResults(ctx context.Context, scanID uuid.UUID, offset, limit int) ([]*db.ScanResult, int64, error)
- func (s *ScanService) GetScanSummary(ctx context.Context, scanID uuid.UUID) (*db.ScanSummary, error)
- func (s *ScanService) ListScans(ctx context.Context, filters db.ScanFilters, offset, limit int) ([]*db.Scan, int64, error)
- func (s *ScanService) StartScan(ctx context.Context, id uuid.UUID) (*db.Scan, error)
- func (s *ScanService) StopScan(ctx context.Context, id uuid.UUID, errMsg ...string) error
- func (s *ScanService) UpdateScan(ctx context.Context, id uuid.UUID, input db.UpdateScanInput) (*db.Scan, error)
- type ScheduleService
- func (s *ScheduleService) CreateSchedule(ctx context.Context, input db.CreateScheduleInput) (*db.Schedule, error)
- func (s *ScheduleService) DeleteSchedule(ctx context.Context, id uuid.UUID) error
- func (s *ScheduleService) DisableSchedule(ctx context.Context, id uuid.UUID) error
- func (s *ScheduleService) EnableSchedule(ctx context.Context, id uuid.UUID) error
- func (s *ScheduleService) GetSchedule(ctx context.Context, id uuid.UUID) (*db.Schedule, error)
- func (s *ScheduleService) ListSchedules(ctx context.Context, filters db.ScheduleFilters, offset, limit int) ([]*db.Schedule, int64, error)
- func (s *ScheduleService) NextRun(ctx context.Context, id uuid.UUID) (time.Time, error)
- func (s *ScheduleService) UpdateSchedule(ctx context.Context, id uuid.UUID, input db.UpdateScheduleInput) (*db.Schedule, error)
Constants ¶
const MaxScanNameLength = 100
MaxScanNameLength is the maximum allowed length for a scan name.
const MaxTargetCount = 100
MaxTargetCount is the maximum number of targets allowed per scan.
const MaxTargetLength = 200
MaxTargetLength is the maximum allowed length for a single target string.
Variables ¶
This section is empty.
Functions ¶
func ParsePortSpec ¶ added in v0.19.1
ParsePortSpec validates a port specification string. The spec is comma-separated with optional T:/U: protocol prefixes and optional hyphenated ranges (e.g. "T:80,U:53,1024-9999"). Every individual port value must be in the range 1-65535.
func ValidateCronExpression ¶ added in v0.19.1
ValidateCronExpression checks that cronExpr is a non-empty, syntactically valid standard 5-field cron expression.
Types ¶
type HostService ¶ added in v0.19.1
type HostService struct {
// contains filtered or unexported fields
}
HostService handles business logic for host management.
func NewHostService ¶ added in v0.19.1
func NewHostService(repo hostRepository, logger *slog.Logger) *HostService
NewHostService creates a new HostService with the provided repository and logger.
func (*HostService) CreateHost ¶ added in v0.19.1
func (s *HostService) CreateHost(ctx context.Context, input db.CreateHostInput) (*db.Host, error)
CreateHost validates the input and creates a new host record. It returns a validation error if the IP address is empty.
func (*HostService) DeleteHost ¶ added in v0.19.1
DeleteHost removes a host record by its UUID.
func (*HostService) GetHostScans ¶ added in v0.19.1
func (s *HostService) GetHostScans( ctx context.Context, hostID uuid.UUID, offset, limit int, ) ([]*db.Scan, int64, error)
GetHostScans returns a paginated list of scans associated with the given host.
func (*HostService) ListHosts ¶ added in v0.19.1
func (s *HostService) ListHosts( ctx context.Context, filters *db.HostFilters, offset, limit int, ) ([]*db.Host, int64, error)
ListHosts returns a paginated list of hosts matching the given filters.
func (*HostService) UpdateHost ¶ added in v0.19.1
func (s *HostService) UpdateHost(ctx context.Context, id uuid.UUID, input db.UpdateHostInput) (*db.Host, error)
UpdateHost applies the provided changes to an existing host record.
type NetworkService ¶
type NetworkService struct {
// contains filtered or unexported fields
}
NetworkService manages network configuration and exclusions.
func NewNetworkService ¶
func NewNetworkService(database *db.DB) *NetworkService
NewNetworkService creates a new network service.
func (*NetworkService) AddExclusion ¶
func (s *NetworkService) AddExclusion( ctx context.Context, networkID *uuid.UUID, cidr, reason string, ) (*db.NetworkExclusion, error)
AddExclusion adds a new exclusion rule.
func (*NetworkService) CreateNetwork ¶
func (s *NetworkService) CreateNetwork( ctx context.Context, name, cidr, description, method string, isActive, scanEnabled bool, ) (*db.Network, error)
CreateNetwork creates a new network.
func (*NetworkService) DeleteNetwork ¶
DeleteNetwork deletes a network and all its exclusions.
func (*NetworkService) GenerateTargetsForNetwork ¶
func (s *NetworkService) GenerateTargetsForNetwork( ctx context.Context, networkID uuid.UUID, maxHosts int, ) ([]string, error)
GenerateTargetsForNetwork generates valid scan targets for a network, applying all exclusions.
func (*NetworkService) GetActiveNetworks ¶
func (s *NetworkService) GetActiveNetworks(ctx context.Context) ([]*NetworkWithExclusions, error)
GetActiveNetworks returns all active networks with their exclusions.
func (*NetworkService) GetGlobalExclusions ¶
func (s *NetworkService) GetGlobalExclusions(ctx context.Context) ([]*db.NetworkExclusion, error)
GetGlobalExclusions returns all global exclusions.
func (*NetworkService) GetNetworkByID ¶
func (s *NetworkService) GetNetworkByID(ctx context.Context, id uuid.UUID) (*NetworkWithExclusions, error)
GetNetworkByID retrieves a network by ID with its exclusions.
func (*NetworkService) GetNetworkByName ¶
func (s *NetworkService) GetNetworkByName(ctx context.Context, name string) (*NetworkWithExclusions, error)
GetNetworkByName retrieves a network by name with its exclusions.
func (*NetworkService) GetNetworkExclusions ¶ added in v0.13.0
func (s *NetworkService) GetNetworkExclusions( ctx context.Context, networkID uuid.UUID, ) ([]*db.NetworkExclusion, error)
GetNetworkExclusions returns all exclusions for a specific network.
func (*NetworkService) GetNetworkStats ¶
func (s *NetworkService) GetNetworkStats(ctx context.Context) (map[string]interface{}, error)
GetNetworkStats returns statistics about networks and exclusions.
func (*NetworkService) ListNetworks ¶
ListNetworks returns all networks with optional filtering.
func (*NetworkService) RemoveExclusion ¶
RemoveExclusion removes an exclusion rule.
func (*NetworkService) SeedNetworksFromConfig ¶
SeedNetworksFromConfig creates or updates networks based on config.
func (*NetworkService) UpdateNetwork ¶
func (s *NetworkService) UpdateNetwork( ctx context.Context, id uuid.UUID, name, cidr, description, method string, enabled bool, ) (*db.Network, error)
UpdateNetwork updates an existing network.
func (*NetworkService) UpdateNetworkDiscoveryTime ¶
func (s *NetworkService) UpdateNetworkDiscoveryTime( ctx context.Context, networkID uuid.UUID, discoveredHosts, activeHosts int, ) error
UpdateNetworkDiscoveryTime updates the last discovery timestamp for a network.
type NetworkWithExclusions ¶
type NetworkWithExclusions struct {
Network *db.Network
Exclusions []*db.NetworkExclusion
}
NetworkWithExclusions represents a network with its exclusions.
type ProfileService ¶ added in v0.19.1
type ProfileService struct {
// contains filtered or unexported fields
}
ProfileService handles business logic for scan profile management.
func NewProfileService ¶ added in v0.19.1
func NewProfileService(repo profileRepository, logger *slog.Logger) *ProfileService
NewProfileService creates a new ProfileService with the provided repository and logger.
func (*ProfileService) CloneProfile ¶ added in v0.19.1
func (s *ProfileService) CloneProfile(ctx context.Context, fromID, newName string) (*db.ScanProfile, error)
CloneProfile creates a new scan profile based on an existing one, using newName as the name of the clone. Scripts are not copied to the clone.
func (*ProfileService) CreateProfile ¶ added in v0.19.1
func (s *ProfileService) CreateProfile(ctx context.Context, input db.CreateProfileInput) (*db.ScanProfile, error)
CreateProfile creates a new scan profile record.
func (*ProfileService) DeleteProfile ¶ added in v0.19.1
func (s *ProfileService) DeleteProfile(ctx context.Context, id string) error
DeleteProfile removes a scan profile by its ID.
func (*ProfileService) GetProfile ¶ added in v0.19.1
func (s *ProfileService) GetProfile(ctx context.Context, id string) (*db.ScanProfile, error)
GetProfile retrieves a single scan profile by its ID.
func (*ProfileService) ListProfiles ¶ added in v0.19.1
func (s *ProfileService) ListProfiles( ctx context.Context, filters db.ProfileFilters, offset, limit int, ) ([]*db.ScanProfile, int64, error)
ListProfiles returns a paginated list of profiles matching the given filters.
func (*ProfileService) UpdateProfile ¶ added in v0.19.1
func (s *ProfileService) UpdateProfile( ctx context.Context, id string, input db.UpdateProfileInput, ) (*db.ScanProfile, error)
UpdateProfile applies the provided changes to an existing scan profile.
type ScanService ¶ added in v0.19.1
type ScanService struct {
// contains filtered or unexported fields
}
ScanService provides business logic for scan lifecycle operations.
func NewScanService ¶ added in v0.19.1
func NewScanService(repo scanRepository, logger *slog.Logger) *ScanService
NewScanService creates a new ScanService backed by the given repository.
func (*ScanService) CompleteScan ¶ added in v0.19.1
CompleteScan marks a scan as successfully completed.
func (*ScanService) CreateScan ¶ added in v0.19.1
func (s *ScanService) CreateScan(ctx context.Context, input db.CreateScanInput) (*db.Scan, error)
CreateScan validates the input, optionally verifies the referenced profile, and delegates creation to the repository.
func (*ScanService) DB ¶ added in v0.19.1
func (s *ScanService) DB() *db.DB
DB returns the underlying raw *db.DB connection, or nil when the repository is not a concrete *db.ScanRepository (e.g. a mock in tests). This is used exclusively by the scan execution pipeline which needs direct database access to persist discovered hosts and port-scan results.
func (*ScanService) DeleteScan ¶ added in v0.19.1
DeleteScan removes a scan record by ID.
func (*ScanService) GetProfile ¶ added in v0.19.1
func (s *ScanService) GetProfile(ctx context.Context, id string) (*db.ScanProfile, error)
GetProfile retrieves a scan profile by its string ID.
func (*ScanService) GetScanResults ¶ added in v0.19.1
func (s *ScanService) GetScanResults( ctx context.Context, scanID uuid.UUID, offset, limit int, ) ([]*db.ScanResult, int64, error)
GetScanResults retrieves paginated port-scan results for a given scan.
func (*ScanService) GetScanSummary ¶ added in v0.19.1
func (s *ScanService) GetScanSummary(ctx context.Context, scanID uuid.UUID) (*db.ScanSummary, error)
GetScanSummary retrieves aggregated statistics for a given scan.
func (*ScanService) ListScans ¶ added in v0.19.1
func (s *ScanService) ListScans( ctx context.Context, filters db.ScanFilters, offset, limit int, ) ([]*db.Scan, int64, error)
ListScans retrieves scans with optional filtering and pagination.
func (*ScanService) StartScan ¶ added in v0.19.1
StartScan transitions a scan to the running state. It fetches the current scan to guard against invalid state transitions, calls repo.StartScan, then returns the refreshed scan record.
func (*ScanService) StopScan ¶ added in v0.19.1
StopScan halts a running scan, optionally recording an error message.
func (*ScanService) UpdateScan ¶ added in v0.19.1
func (s *ScanService) UpdateScan( ctx context.Context, id uuid.UUID, input db.UpdateScanInput, ) (*db.Scan, error)
UpdateScan applies the given mutations to an existing scan.
type ScheduleService ¶ added in v0.19.1
type ScheduleService struct {
// contains filtered or unexported fields
}
ScheduleService provides business logic for scheduled-job operations.
func NewScheduleService ¶ added in v0.19.1
func NewScheduleService(repo scheduleRepository, logger *slog.Logger) *ScheduleService
NewScheduleService creates a new ScheduleService backed by the given repository.
func (*ScheduleService) CreateSchedule ¶ added in v0.19.1
func (s *ScheduleService) CreateSchedule( ctx context.Context, input db.CreateScheduleInput, ) (*db.Schedule, error)
CreateSchedule validates the cron expression and delegates creation to the repository.
func (*ScheduleService) DeleteSchedule ¶ added in v0.19.1
DeleteSchedule removes a schedule by ID.
func (*ScheduleService) DisableSchedule ¶ added in v0.19.1
DisableSchedule prevents a schedule from being run by the scheduler.
func (*ScheduleService) EnableSchedule ¶ added in v0.19.1
EnableSchedule enables a schedule so it will be picked up by the scheduler.
func (*ScheduleService) GetSchedule ¶ added in v0.19.1
GetSchedule retrieves a single schedule by its ID.
func (*ScheduleService) ListSchedules ¶ added in v0.19.1
func (s *ScheduleService) ListSchedules( ctx context.Context, filters db.ScheduleFilters, offset, limit int, ) ([]*db.Schedule, int64, error)
ListSchedules retrieves schedules with optional filtering and pagination.
func (*ScheduleService) NextRun ¶ added in v0.19.1
NextRun fetches the schedule, parses its cron expression, and returns the next time the job would fire after the current UTC instant.
func (*ScheduleService) UpdateSchedule ¶ added in v0.19.1
func (s *ScheduleService) UpdateSchedule( ctx context.Context, id uuid.UUID, input db.UpdateScheduleInput, ) (*db.Schedule, error)
UpdateSchedule validates the cron expression if it is being changed, then delegates the update to the repository.