Documentation
¶
Overview ¶
Package compliance implements the application service for the compliance bounded context — orchestrates pkg/domain/compliance entities and cross-cutting concerns (audit, notifications, RBAC).
Index ¶
- func WithCachedCampaignRole(ctx context.Context, tenantID, campaignID, userID string, ...) context.Context
- type CampaignAddMemberInput
- type CampaignRemoveMemberInput
- type CampaignTeamChangeResult
- type CampaignUpdateMemberRoleInput
- type ComplianceService
- func (s *ComplianceService) AutoMapFinding(ctx context.Context, tenantID, findingID string) ([]*compliancedom.FindingControlMapping, error)
- func (s *ComplianceService) GetComplianceStats(ctx context.Context, tenantID string) (*ComplianceStatsResponse, error)
- func (s *ComplianceService) GetControl(ctx context.Context, tenantID, id string) (*compliancedom.Control, error)
- func (s *ComplianceService) GetControlFindings(ctx context.Context, tenantID, controlID string) ([]*compliancedom.FindingControlMapping, error)
- func (s *ComplianceService) GetFindingControls(ctx context.Context, tenantID, findingID string) ([]*compliancedom.FindingControlMapping, error)
- func (s *ComplianceService) GetFramework(ctx context.Context, tenantID, id string) (*compliancedom.Framework, error)
- func (s *ComplianceService) GetFrameworkBySlug(ctx context.Context, slug string) (*compliancedom.Framework, error)
- func (s *ComplianceService) GetFrameworkStats(ctx context.Context, tenantID, frameworkID string) (*compliancedom.FrameworkStats, error)
- func (s *ComplianceService) ListAssessments(ctx context.Context, tenantID, frameworkID string, page pagination.Pagination) (pagination.Result[*compliancedom.Assessment], error)
- func (s *ComplianceService) ListControls(ctx context.Context, tenantID, frameworkID string, page pagination.Pagination) (pagination.Result[*compliancedom.Control], error)
- func (s *ComplianceService) ListFrameworks(ctx context.Context, tenantID string, page pagination.Pagination) (pagination.Result[*compliancedom.Framework], error)
- func (s *ComplianceService) MapFindingToControl(ctx context.Context, tenantID, findingID, controlID, actorID string, ...) (*compliancedom.FindingControlMapping, error)
- func (s *ComplianceService) SetFindingRepository(repo vulnerability.FindingRepository)
- func (s *ComplianceService) UnmapFindingFromControl(ctx context.Context, tenantID, mappingID string) error
- func (s *ComplianceService) UpdateAssessment(ctx context.Context, input UpdateAssessmentInput) (*compliancedom.Assessment, error)
- type ComplianceStatsResponse
- type CreateCampaignInput
- type CreateControlTestInput
- type CreateReportInput
- type CreateRetestInput
- type CreateSimulationInput
- type CreateTemplateInput
- type PentestFindingInput
- type PentestService
- func (s *PentestService) AddCampaignMember(ctx context.Context, input CampaignAddMemberInput) (*pentest.CampaignMember, error)
- func (s *PentestService) BatchListCampaignMembers(ctx context.Context, tenantID string, campaignIDs []string) (map[string][]*pentest.CampaignMember, error)
- func (s *PentestService) CheckCampaignAccess(ctx context.Context, tenantID, campaignID, userID string, isAdmin bool) error
- func (s *PentestService) CheckFindingAccess(ctx context.Context, tenantID, findingID, userID string, isAdmin bool) error
- func (s *PentestService) CreateCampaign(ctx context.Context, input CreateCampaignInput) (*pentest.Campaign, error)
- func (s *PentestService) CreateFinding(ctx context.Context, input PentestFindingInput) (*pentest.Finding, error)
- func (s *PentestService) CreateReport(ctx context.Context, input CreateReportInput) (*pentest.Report, error)
- func (s *PentestService) CreateRetest(ctx context.Context, input CreateRetestInput) (*pentest.Retest, error)
- func (s *PentestService) CreateTemplate(ctx context.Context, tenantID string, input CreateTemplateInput) (*pentest.Template, error)
- func (s *PentestService) CreateUnifiedFinding(ctx context.Context, input PentestFindingInput) (*vulnerability.Finding, error)
- func (s *PentestService) DeleteCampaign(ctx context.Context, tenantID, campaignID string) error
- func (s *PentestService) DeleteFinding(ctx context.Context, tenantID, findingID string) error
- func (s *PentestService) DeleteReport(ctx context.Context, tenantID, reportID string) error
- func (s *PentestService) DeleteTemplate(ctx context.Context, tenantID, id string) error
- func (s *PentestService) GenerateReportHTML(ctx context.Context, tenantID, campaignID string, ...) (string, error)
- func (s *PentestService) GenerateReportPDF(ctx context.Context, tenantID, campaignID string, ...) ([]byte, error)
- func (s *PentestService) GetBatchCampaignStats(ctx context.Context, tenantID string, campaignIDs []string) (map[string]*pentest.CampaignStats, error)
- func (s *PentestService) GetCampaign(ctx context.Context, tenantID, campaignID string) (*pentest.Campaign, error)
- func (s *PentestService) GetCampaignStats(ctx context.Context, tenantID, campaignID string) (*pentest.CampaignStats, error)
- func (s *PentestService) GetFinding(ctx context.Context, tenantID, findingID string) (*pentest.Finding, error)
- func (s *PentestService) GetReport(ctx context.Context, tenantID, reportID string) (*pentest.Report, error)
- func (s *PentestService) GetTemplate(ctx context.Context, tenantID, id string) (*pentest.Template, error)
- func (s *PentestService) GetUnifiedFinding(ctx context.Context, tenantID, findingID string) (*vulnerability.Finding, error)
- func (s *PentestService) GetUserCampaignRole(ctx context.Context, tenantID, campaignID, userID string) (pentest.CampaignRole, error)
- func (s *PentestService) ListAllPentestFindings(ctx context.Context, tenantID, campaignID, viewerUserID, search string, ...) (pagination.Result[*vulnerability.Finding], error)
- func (s *PentestService) ListCampaignMembers(ctx context.Context, tenantID, campaignID string) ([]*pentest.CampaignMember, error)
- func (s *PentestService) ListCampaignRetests(ctx context.Context, tenantID, campaignID string) ([]*pentest.Retest, error)
- func (s *PentestService) ListCampaigns(ctx context.Context, tenantID string, filter pentest.CampaignFilter, ...) (pagination.Result[*pentest.Campaign], error)
- func (s *PentestService) ListFindings(ctx context.Context, tenantID string, filter pentest.FindingFilter, ...) (pagination.Result[*pentest.Finding], error)
- func (s *PentestService) ListReports(ctx context.Context, tenantID string, filter pentest.ReportFilter, ...) (pagination.Result[*pentest.Report], error)
- func (s *PentestService) ListRetests(ctx context.Context, tenantID, findingID string) ([]*pentest.Retest, error)
- func (s *PentestService) ListTemplates(ctx context.Context, tenantID string, filter pentest.TemplateFilter, ...) (pagination.Result[*pentest.Template], error)
- func (s *PentestService) ListUnifiedCampaignFindings(ctx context.Context, tenantID, campaignID string, page pagination.Pagination) (pagination.Result[*vulnerability.Finding], error)
- func (s *PentestService) RemoveCampaignMember(ctx context.Context, input CampaignRemoveMemberInput) (string, error)
- func (s *PentestService) RenderReport(ctx context.Context, tenantID, campaignID string, ...) ([]byte, string, error)
- func (s *PentestService) RequireCampaignWritableForFinding(ctx context.Context, tenantID string, finding *vulnerability.Finding, ...) error
- func (s *PentestService) ResolveCampaignRoleForFinding(ctx context.Context, tenantID, findingID, userID string, isAdmin bool) (pentest.CampaignRole, *vulnerability.Finding, error)
- func (s *PentestService) SetAuditService(svc *auditapp.AuditService)
- func (s *PentestService) SetCampaignMemberRepository(repo pentest.CampaignMemberRepository)
- func (s *PentestService) SetFindingActivityService(svc *activity.FindingActivityService)
- func (s *PentestService) SetTenantMemberChecker(checker TenantMemberChecker)
- func (s *PentestService) SetUnifiedFindingRepository(repo vulnerability.FindingRepository)
- func (s *PentestService) SetUserNotificationService(svc *integration.NotificationService)
- func (s *PentestService) UpdateCampaign(ctx context.Context, input UpdateCampaignInput) (*pentest.Campaign, error)
- func (s *PentestService) UpdateCampaignMemberRole(ctx context.Context, input CampaignUpdateMemberRoleInput) error
- func (s *PentestService) UpdateCampaignStatus(ctx context.Context, tenantID, campaignID, newStatus string) (*StatusChangeResult, error)
- func (s *PentestService) UpdateFinding(ctx context.Context, tenantID, findingID string, input PentestFindingInput) (*pentest.Finding, error)
- func (s *PentestService) UpdateFindingStatus(ctx context.Context, tenantID, findingID, newStatus, actorID string) (*pentest.Finding, error)
- func (s *PentestService) UpdatePentestFindingStatus(ctx context.Context, tenantID, findingID, newStatus, actorID string) (*vulnerability.Finding, error)
- func (s *PentestService) UpdateTemplate(ctx context.Context, tenantID, id string, input CreateTemplateInput) (*pentest.Template, error)
- func (s *PentestService) UpdateUnifiedFinding(ctx context.Context, tenantID, findingID string, input PentestFindingInput) (*vulnerability.Finding, error)
- type PentestSourceMetadata
- type RecordControlTestResultInput
- type SafeCheckDispatcher
- type SimulationService
- func (s *SimulationService) CreateControlTest(ctx context.Context, input CreateControlTestInput) (*simulation.ControlTest, error)
- func (s *SimulationService) CreateSimulation(ctx context.Context, input CreateSimulationInput) (*simulation.Simulation, error)
- func (s *SimulationService) DeleteControlTest(ctx context.Context, tenantID, ctID string) error
- func (s *SimulationService) DeleteSimulation(ctx context.Context, tenantID, simID string) error
- func (s *SimulationService) FinalizeRun(ctx context.Context, tenantID, runID shared.ID, outcome, summary string) error
- func (s *SimulationService) GetControlTest(ctx context.Context, tenantID, ctID string) (*simulation.ControlTest, error)
- func (s *SimulationService) GetControlTestStats(ctx context.Context, tenantID string) ([]simulation.FrameworkStats, error)
- func (s *SimulationService) GetSimulation(ctx context.Context, tenantID, simID string) (*simulation.Simulation, error)
- func (s *SimulationService) ListControlTests(ctx context.Context, tenantID string, filter simulation.ControlTestFilter, ...) (pagination.Result[*simulation.ControlTest], error)
- func (s *SimulationService) ListSimulationRuns(ctx context.Context, tenantID, simID string, page pagination.Pagination) (pagination.Result[*simulation.SimulationRun], error)
- func (s *SimulationService) ListSimulations(ctx context.Context, tenantID string, filter simulation.SimulationFilter, ...) (pagination.Result[*simulation.Simulation], error)
- func (s *SimulationService) RecordControlTestResult(ctx context.Context, input RecordControlTestResultInput) (*simulation.ControlTest, error)
- func (s *SimulationService) RunSimulation(ctx context.Context, tenantID, simID, actorID string) (*simulation.SimulationRun, error)
- func (s *SimulationService) SetRunRepo(repo simulation.RunRepository)
- func (s *SimulationService) SetSafeCheckDispatcher(d SafeCheckDispatcher)
- func (s *SimulationService) UpdateSimulation(ctx context.Context, input UpdateSimulationInput) (*simulation.Simulation, error)
- type StatusChangeResult
- type TenantMemberChecker
- type UpdateAssessmentInput
- type UpdateCampaignInput
- type UpdateSimulationInput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithCachedCampaignRole ¶
func WithCachedCampaignRole(ctx context.Context, tenantID, campaignID, userID string, role pentest.CampaignRole) context.Context
WithCachedCampaignRole returns a new context with the given role memoized for the duration of the request.
Types ¶
type CampaignAddMemberInput ¶
type CampaignAddMemberInput struct {
TenantID string
CampaignID string
UserID string
Role string
ActorID string
}
CampaignAddMemberInput contains input for adding a campaign member.
type CampaignRemoveMemberInput ¶
type CampaignRemoveMemberInput struct {
TenantID string
CampaignID string
UserID string
ActorID string // the user performing the removal (for self-remove check)
}
CampaignRemoveMemberInput contains input for removing a campaign member.
type CampaignTeamChangeResult ¶
type CampaignTeamChangeResult struct {
Member *pentest.CampaignMember
Warning string // optional soft warning (e.g., last reviewer removed with in_review findings)
}
CampaignTeamChangeResult captures the outcome of team membership changes that may carry soft warnings the caller should show the user.
type CampaignUpdateMemberRoleInput ¶
type CampaignUpdateMemberRoleInput struct {
TenantID string
CampaignID string
UserID string
NewRole string
ActorID string // the user performing the update, for audit trail
}
CampaignUpdateMemberRoleInput contains input for changing a member's role.
type ComplianceService ¶
type ComplianceService struct {
// contains filtered or unexported fields
}
ComplianceService handles compliance framework business operations.
func NewComplianceService ¶
func NewComplianceService( frameworkRepo compliancedom.FrameworkRepository, controlRepo compliancedom.ControlRepository, assessmentRepo compliancedom.AssessmentRepository, mappingRepo compliancedom.MappingRepository, log *logger.Logger, ) *ComplianceService
NewComplianceService creates a new ComplianceService.
func (*ComplianceService) AutoMapFinding ¶ added in v0.3.0
func (s *ComplianceService) AutoMapFinding(ctx context.Context, tenantID, findingID string) ([]*compliancedom.FindingControlMapping, error)
AutoMapFinding deterministically maps a finding to the OWASP Top 10 (2021) controls implied by its OWASP ids / CWEs, creating the finding→control mappings that were previously only possible by hand. Idempotent: existing mappings are left untouched and only newly-derived ones are returned.
func (*ComplianceService) GetComplianceStats ¶
func (s *ComplianceService) GetComplianceStats(ctx context.Context, tenantID string) (*ComplianceStatsResponse, error)
GetComplianceStats returns overall compliance statistics.
func (*ComplianceService) GetControl ¶
func (s *ComplianceService) GetControl(ctx context.Context, tenantID, id string) (*compliancedom.Control, error)
GetControl retrieves a control by ID and verifies its framework is accessible to the tenant.
func (*ComplianceService) GetControlFindings ¶
func (s *ComplianceService) GetControlFindings(ctx context.Context, tenantID, controlID string) ([]*compliancedom.FindingControlMapping, error)
GetControlFindings lists findings mapped to a control.
func (*ComplianceService) GetFindingControls ¶
func (s *ComplianceService) GetFindingControls(ctx context.Context, tenantID, findingID string) ([]*compliancedom.FindingControlMapping, error)
GetFindingControls lists controls mapped to a finding.
func (*ComplianceService) GetFramework ¶
func (s *ComplianceService) GetFramework(ctx context.Context, tenantID, id string) (*compliancedom.Framework, error)
GetFramework retrieves a framework by ID with tenant isolation.
func (*ComplianceService) GetFrameworkBySlug ¶
func (s *ComplianceService) GetFrameworkBySlug(ctx context.Context, slug string) (*compliancedom.Framework, error)
GetFrameworkBySlug retrieves a system framework by slug.
func (*ComplianceService) GetFrameworkStats ¶
func (s *ComplianceService) GetFrameworkStats(ctx context.Context, tenantID, frameworkID string) (*compliancedom.FrameworkStats, error)
GetFrameworkStats returns compliance statistics for a framework.
func (*ComplianceService) ListAssessments ¶
func (s *ComplianceService) ListAssessments(ctx context.Context, tenantID, frameworkID string, page pagination.Pagination) (pagination.Result[*compliancedom.Assessment], error)
ListAssessments lists assessments for a framework.
func (*ComplianceService) ListControls ¶
func (s *ComplianceService) ListControls(ctx context.Context, tenantID, frameworkID string, page pagination.Pagination) (pagination.Result[*compliancedom.Control], error)
ListControls lists controls for a framework with tenant verification.
func (*ComplianceService) ListFrameworks ¶
func (s *ComplianceService) ListFrameworks(ctx context.Context, tenantID string, page pagination.Pagination) (pagination.Result[*compliancedom.Framework], error)
ListFrameworks lists compliance frameworks.
func (*ComplianceService) MapFindingToControl ¶
func (s *ComplianceService) MapFindingToControl(ctx context.Context, tenantID, findingID, controlID, actorID string, impact string) (*compliancedom.FindingControlMapping, error)
MapFindingToControl maps a finding to a compliance control.
func (*ComplianceService) SetFindingRepository ¶
func (s *ComplianceService) SetFindingRepository(repo vulnerability.FindingRepository)
SetFindingRepository sets the finding repository for draft guard on compliance mapping.
func (*ComplianceService) UnmapFindingFromControl ¶
func (s *ComplianceService) UnmapFindingFromControl(ctx context.Context, tenantID, mappingID string) error
UnmapFindingFromControl removes a mapping.
func (*ComplianceService) UpdateAssessment ¶
func (s *ComplianceService) UpdateAssessment(ctx context.Context, input UpdateAssessmentInput) (*compliancedom.Assessment, error)
UpdateAssessment creates or updates a control assessment.
type ComplianceStatsResponse ¶
type ComplianceStatsResponse struct {
TotalFrameworks int `json:"total_frameworks"`
TotalControls int `json:"total_controls"`
OverdueControls int `json:"overdue_controls"`
}
ComplianceStatsResponse contains overall compliance stats.
type CreateCampaignInput ¶
type CreateCampaignInput struct {
TenantID string
Name string
Description string
CampaignType string
Priority string
Methodology string
ClientName string
ClientContact string
StartDate *string
EndDate *string
Objectives []string
ScopeItems []map[string]any
RulesOfEngagement map[string]any
LeadUserID *string
TeamUserIDs []string
AssetIDs []string
AssetGroupIDs []string
Tags []string
Metadata map[string]any
ActorID string
}
CreateCampaignInput contains the input for creating a campaign.
type CreateControlTestInput ¶
type CreateControlTestInput struct {
TenantID string
Name string
Description string
Framework string
ControlID string
ControlName string
Category string
TestProcedure string
ExpectedResult string
RiskLevel string
Tags []string
}
CreateControlTestInput holds input for creating a control test.
type CreateReportInput ¶
type CreateReportInput struct {
TenantID string
CampaignID string
Name string
ReportType string
Format string
Options map[string]any
ActorID string
}
CreateReportInput contains input for creating a report.
type CreateRetestInput ¶
type CreateRetestInput struct {
TenantID string
FindingID string
Status string
Notes string
Evidence []map[string]any
ActorID string
ActorCampaignRole pentest.CampaignRole // role of the actor in the campaign (for auto-status logic)
}
CreateRetestInput contains input for creating a retest.
type CreateSimulationInput ¶
type CreateSimulationInput struct {
TenantID string
Name string
Description string
SimulationType string
MitreTactic string
MitreTechniqueID string
MitreTechniqueName string
TargetAssets []string
Config map[string]any
Tags []string
ActorID string
}
CreateSimulationInput holds input for creating a simulation.
type CreateTemplateInput ¶
type CreateTemplateInput struct {
Name string `json:"name"`
Category string `json:"category"`
Severity string `json:"severity"`
OWASPCategory string `json:"owasp_category"`
CWEID string `json:"cwe_id"`
Description string `json:"description"`
StepsToReproduce []string `json:"steps_to_reproduce"`
BusinessImpact string `json:"business_impact"`
TechnicalImpact string `json:"technical_impact"`
Remediation string `json:"remediation"`
ReferenceURLs []string `json:"reference_urls"`
Tags []string `json:"tags"`
}
CreateTemplateInput contains input for creating a template.
type PentestFindingInput ¶
type PentestFindingInput struct {
TenantID string
CampaignID string
AssetID string // Required for unified findings (CTEM asset linkage)
Title string
Description string
Severity string
Status string
CVSSScore *float64
CVSSVector string
CVSSVersion string
CWEID string
CVEID string
OWASPCategory string
MitreTechniqueID string
MitreTactic string
AffectedAssets []string // Legacy: for pentest_findings table
AffectedAssetsText []string // For unified: free-text asset references
StepsToReproduce []string
PoCCode string
Evidence []map[string]any
RequestResponses []map[string]any
BusinessImpact string
TechnicalImpact string
RemediationGuidance string
RemediationDeadline *string
ReferenceURLs []string
AssignedTo *string
ReviewedBy *string
Tags []string
ActorID string
TemplateID *string
}
type PentestService ¶
type PentestService struct {
// contains filtered or unexported fields
}
PentestService handles pentest campaign business operations.
func NewPentestService ¶
func NewPentestService( campaignRepo pentest.CampaignRepository, findingRepo pentest.FindingRepository, retestRepo pentest.RetestRepository, templateRepo pentest.TemplateRepository, reportRepo pentest.ReportRepository, log *logger.Logger, ) *PentestService
NewPentestService creates a new PentestService.
func (*PentestService) AddCampaignMember ¶
func (s *PentestService) AddCampaignMember(ctx context.Context, input CampaignAddMemberInput) (*pentest.CampaignMember, error)
AddCampaignMember adds a user to a campaign with a specific role. Logs an audit event on success.
func (*PentestService) BatchListCampaignMembers ¶
func (s *PentestService) BatchListCampaignMembers(ctx context.Context, tenantID string, campaignIDs []string) (map[string][]*pentest.CampaignMember, error)
BatchListCampaignMembers returns members grouped by campaign ID for batch enrichment.
func (*PentestService) CheckCampaignAccess ¶ added in v0.3.0
func (s *PentestService) CheckCampaignAccess(ctx context.Context, tenantID, campaignID, userID string, isAdmin bool) error
CheckCampaignAccess verifies the user is a member of (or admin over) the campaign. Used to gate campaign-context attachments so evidence is not reachable by every tenant user. Returns ErrNotCampaignMember (→ 404) for non-members.
func (*PentestService) CheckFindingAccess ¶
func (s *PentestService) CheckFindingAccess(ctx context.Context, tenantID, findingID, userID string, isAdmin bool) error
CheckFindingAccess verifies that a user has campaign membership for a pentest finding. Implements FindingCampaignAccessChecker interface used by attachment handler.
func (*PentestService) CreateCampaign ¶
func (s *PentestService) CreateCampaign(ctx context.Context, input CreateCampaignInput) (*pentest.Campaign, error)
CreateCampaign creates a new pentest campaign.
func (*PentestService) CreateFinding ¶
func (s *PentestService) CreateFinding(ctx context.Context, input PentestFindingInput) (*pentest.Finding, error)
CreateFinding creates a new pentest finding.
func (*PentestService) CreateReport ¶
func (s *PentestService) CreateReport(ctx context.Context, input CreateReportInput) (*pentest.Report, error)
CreateReport creates a report and generates its artifact synchronously, driving the report row to a terminal state (completed/failed).
Lifecycle model: generate-on-create. There is no async worker or blob store, so the artifact is produced deterministically from live campaign data at create time — this validates generation, records a real file size, stamps generated_at, and reaches status=completed immediately. The download route regenerates the same artifact on demand (the bytes are not persisted). On generation failure the row is marked failed and the error is surfaced.
func (*PentestService) CreateRetest ¶
func (s *PentestService) CreateRetest(ctx context.Context, input CreateRetestInput) (*pentest.Retest, error)
CreateRetest creates a retest and auto-updates finding status.
func (*PentestService) CreateTemplate ¶
func (s *PentestService) CreateTemplate(ctx context.Context, tenantID string, input CreateTemplateInput) (*pentest.Template, error)
CreateTemplate creates a new finding template.
func (*PentestService) CreateUnifiedFinding ¶
func (s *PentestService) CreateUnifiedFinding(ctx context.Context, input PentestFindingInput) (*vulnerability.Finding, error)
CreateUnifiedFinding creates a pentest finding in the unified findings table. This is the CTEM-integrated version: finding goes directly into `findings` table with source='pentest', enabling dashboard, SLA, compliance, and risk scoring.
func (*PentestService) DeleteCampaign ¶
func (s *PentestService) DeleteCampaign(ctx context.Context, tenantID, campaignID string) error
DeleteCampaign deletes a campaign. The DB cascades to its pentest findings (findings.pentest_campaign_id ON DELETE CASCADE, migration 000170) and from there to their retests, comments, and activities; pentest_reports cascade directly. Linked attachments (no FK) are not yet cleaned up — see the orphan-cleanup follow-up.
func (*PentestService) DeleteFinding ¶
func (s *PentestService) DeleteFinding(ctx context.Context, tenantID, findingID string) error
DeleteFinding deletes a pentest finding. Uses the unified finding repo when available to delete from the correct table.
func (*PentestService) DeleteReport ¶
func (s *PentestService) DeleteReport(ctx context.Context, tenantID, reportID string) error
DeleteReport deletes a report.
func (*PentestService) DeleteTemplate ¶
func (s *PentestService) DeleteTemplate(ctx context.Context, tenantID, id string) error
DeleteTemplate deletes a template. System templates cannot be deleted.
func (*PentestService) GenerateReportHTML ¶
func (s *PentestService) GenerateReportHTML(ctx context.Context, tenantID, campaignID string, reportType pentest.ReportType, options map[string]any) (string, error)
GenerateReportHTML generates an HTML report for a campaign of the given type.
func (*PentestService) GenerateReportPDF ¶ added in v0.3.0
func (s *PentestService) GenerateReportPDF(ctx context.Context, tenantID, campaignID string, reportType pentest.ReportType, options map[string]any) ([]byte, error)
GenerateReportPDF generates a PDF report for a campaign, rendered directly from the structured report data (pure Go, no headless browser).
func (*PentestService) GetBatchCampaignStats ¶
func (s *PentestService) GetBatchCampaignStats(ctx context.Context, tenantID string, campaignIDs []string) (map[string]*pentest.CampaignStats, error)
GetBatchCampaignStats returns finding statistics for multiple campaigns in one query.
func (*PentestService) GetCampaign ¶
func (s *PentestService) GetCampaign(ctx context.Context, tenantID, campaignID string) (*pentest.Campaign, error)
GetCampaign retrieves a campaign by ID.
func (*PentestService) GetCampaignStats ¶
func (s *PentestService) GetCampaignStats(ctx context.Context, tenantID, campaignID string) (*pentest.CampaignStats, error)
GetCampaignStats returns finding statistics for a campaign.
func (*PentestService) GetFinding ¶
func (s *PentestService) GetFinding(ctx context.Context, tenantID, findingID string) (*pentest.Finding, error)
GetFinding retrieves a pentest finding by ID.
func (*PentestService) GetReport ¶
func (s *PentestService) GetReport(ctx context.Context, tenantID, reportID string) (*pentest.Report, error)
GetReport retrieves a report by ID.
func (*PentestService) GetTemplate ¶
func (s *PentestService) GetTemplate(ctx context.Context, tenantID, id string) (*pentest.Template, error)
GetTemplate retrieves a template by ID with tenant isolation.
func (*PentestService) GetUnifiedFinding ¶
func (s *PentestService) GetUnifiedFinding(ctx context.Context, tenantID, findingID string) (*vulnerability.Finding, error)
GetUnifiedFinding retrieves a pentest finding from the unified findings table. Returns ErrNotFound if the finding exists but is not a pentest finding.
func (*PentestService) GetUserCampaignRole ¶
func (s *PentestService) GetUserCampaignRole(ctx context.Context, tenantID, campaignID, userID string) (pentest.CampaignRole, error)
GetUserCampaignRole returns the user's role in a campaign.
func (*PentestService) ListAllPentestFindings ¶
func (s *PentestService) ListAllPentestFindings(ctx context.Context, tenantID, campaignID, viewerUserID, search string, isAdmin bool, page pagination.Pagination) (pagination.Result[*vulnerability.Finding], error)
ListAllPentestFindings lists all pentest findings across all campaigns. If campaignID is provided, filters by that campaign.
Visibility: when viewerUserID is non-empty AND isAdmin=false, findings are restricted to campaigns the viewer is a member of (pentest_campaign_members). Admin callers see everything.
func (*PentestService) ListCampaignMembers ¶
func (s *PentestService) ListCampaignMembers(ctx context.Context, tenantID, campaignID string) ([]*pentest.CampaignMember, error)
ListCampaignMembers returns all members of a campaign.
func (*PentestService) ListCampaignRetests ¶ added in v0.4.0
func (s *PentestService) ListCampaignRetests(ctx context.Context, tenantID, campaignID string) ([]*pentest.Retest, error)
ListCampaignRetests returns every retest for findings in a campaign, tenant-scoped. Thin wrapper over RetestRepository.ListByCampaign (also used by buildReportInput); callers that expose this to non-admins MUST first gate campaign membership (e.g. CheckCampaignAccess), as this method itself performs no membership check.
func (*PentestService) ListCampaigns ¶
func (s *PentestService) ListCampaigns(ctx context.Context, tenantID string, filter pentest.CampaignFilter, page pagination.Pagination) (pagination.Result[*pentest.Campaign], error)
ListCampaigns lists campaigns with filtering and pagination.
func (*PentestService) ListFindings ¶
func (s *PentestService) ListFindings(ctx context.Context, tenantID string, filter pentest.FindingFilter, page pagination.Pagination) (pagination.Result[*pentest.Finding], error)
ListFindings lists findings with filtering and pagination.
func (*PentestService) ListReports ¶
func (s *PentestService) ListReports(ctx context.Context, tenantID string, filter pentest.ReportFilter, page pagination.Pagination) (pagination.Result[*pentest.Report], error)
ListReports lists reports with filtering.
func (*PentestService) ListRetests ¶
func (s *PentestService) ListRetests(ctx context.Context, tenantID, findingID string) ([]*pentest.Retest, error)
ListRetests lists retests for a finding.
func (*PentestService) ListTemplates ¶
func (s *PentestService) ListTemplates(ctx context.Context, tenantID string, filter pentest.TemplateFilter, page pagination.Pagination) (pagination.Result[*pentest.Template], error)
ListTemplates lists templates with filtering.
func (*PentestService) ListUnifiedCampaignFindings ¶
func (s *PentestService) ListUnifiedCampaignFindings(ctx context.Context, tenantID, campaignID string, page pagination.Pagination) (pagination.Result[*vulnerability.Finding], error)
ListUnifiedCampaignFindings lists pentest findings from the unified findings table filtered by campaign.
func (*PentestService) RemoveCampaignMember ¶
func (s *PentestService) RemoveCampaignMember(ctx context.Context, input CampaignRemoveMemberInput) (string, error)
RemoveCampaignMember removes a user from a campaign. Validates: not removing last lead, not self-removing if lead. Returns a soft warning string if removing the last reviewer while in_review findings exist. Lead integrity check + delete are serialized via a transaction with SELECT FOR UPDATE.
func (*PentestService) RenderReport ¶ added in v0.4.0
func (s *PentestService) RenderReport( ctx context.Context, tenantID, campaignID string, reportType pentest.ReportType, format pentest.ReportFormat, options map[string]any, ) ([]byte, string, error)
RenderReport builds the campaign report input for the given report type and renders it in the requested format. It returns the artifact bytes and the HTTP content type. Unsupported formats yield pentest.ErrReportFormatUnsupported.
func (*PentestService) RequireCampaignWritableForFinding ¶
func (s *PentestService) RequireCampaignWritableForFinding(ctx context.Context, tenantID string, finding *vulnerability.Finding, allowExistingUpdates bool) error
RequireCampaignWritableForFinding looks up the finding's campaign and applies the writability lock check. Used by finding-direct routes that don't go through campaign-scoped middleware. allowExistingUpdates: if true, on_hold campaigns allow updating existing items (block only new creation).
func (*PentestService) ResolveCampaignRoleForFinding ¶
func (s *PentestService) ResolveCampaignRoleForFinding(ctx context.Context, tenantID, findingID, userID string, isAdmin bool) (pentest.CampaignRole, *vulnerability.Finding, error)
ResolveCampaignRoleForFinding resolves the caller's campaign role from a unified finding. Used by finding-direct routes where campaign ID is not in the URL. Returns role and the finding. Admin callers get empty role (bypass enforced elsewhere).
Performance: honours a role already resolved by CampaignRoleResolver middleware (if the request path goes through /campaigns/{id}/...) to avoid redundant queries. For pure finding-direct routes the middleware isn't wired, so we hit the DB once.
func (*PentestService) SetAuditService ¶
func (s *PentestService) SetAuditService(svc *auditapp.AuditService)
func (*PentestService) SetCampaignMemberRepository ¶
func (s *PentestService) SetCampaignMemberRepository(repo pentest.CampaignMemberRepository)
SetCampaignMemberRepository sets the campaign member repository.
func (*PentestService) SetFindingActivityService ¶
func (s *PentestService) SetFindingActivityService(svc *activity.FindingActivityService)
SetAuditService wires an audit service for team change logging (fire-and-forget). SetFindingActivityService sets the finding activity service for audit trail.
func (*PentestService) SetTenantMemberChecker ¶
func (s *PentestService) SetTenantMemberChecker(checker TenantMemberChecker)
SetTenantMemberChecker sets the tenant membership validator.
func (*PentestService) SetUnifiedFindingRepository ¶
func (s *PentestService) SetUnifiedFindingRepository(repo vulnerability.FindingRepository)
SetUnifiedFindingRepository sets the unified finding repository for CTEM integration. When set, pentest findings are created in the findings table (source='pentest').
func (*PentestService) SetUserNotificationService ¶
func (s *PentestService) SetUserNotificationService(svc *integration.NotificationService)
SetUserNotificationService sets the in-app notification service.
func (*PentestService) UpdateCampaign ¶
func (s *PentestService) UpdateCampaign(ctx context.Context, input UpdateCampaignInput) (*pentest.Campaign, error)
UpdateCampaign updates an existing campaign.
func (*PentestService) UpdateCampaignMemberRole ¶
func (s *PentestService) UpdateCampaignMemberRole(ctx context.Context, input CampaignUpdateMemberRoleInput) error
UpdateCampaignMemberRole changes a member's role. Validates: not demoting the last lead.
func (*PentestService) UpdateCampaignStatus ¶
func (s *PentestService) UpdateCampaignStatus(ctx context.Context, tenantID, campaignID, newStatus string) (*StatusChangeResult, error)
UpdateCampaignStatus transitions the campaign status. Returns a warning if completing with open findings (does not block).
func (*PentestService) UpdateFinding ¶
func (s *PentestService) UpdateFinding(ctx context.Context, tenantID, findingID string, input PentestFindingInput) (*pentest.Finding, error)
UpdateFinding updates a pentest finding.
func (*PentestService) UpdateFindingStatus ¶
func (s *PentestService) UpdateFindingStatus(ctx context.Context, tenantID, findingID, newStatus, actorID string) (*pentest.Finding, error)
UpdateFindingStatus transitions the finding status.
func (*PentestService) UpdatePentestFindingStatus ¶
func (s *PentestService) UpdatePentestFindingStatus(ctx context.Context, tenantID, findingID, newStatus, actorID string) (*vulnerability.Finding, error)
UpdatePentestFindingStatus transitions a pentest finding's status with validation.
func (*PentestService) UpdateTemplate ¶
func (s *PentestService) UpdateTemplate(ctx context.Context, tenantID, id string, input CreateTemplateInput) (*pentest.Template, error)
UpdateTemplate updates a template. Returns error if system template.
func (*PentestService) UpdateUnifiedFinding ¶
func (s *PentestService) UpdateUnifiedFinding(ctx context.Context, tenantID, findingID string, input PentestFindingInput) (*vulnerability.Finding, error)
UpdateUnifiedFinding updates a pentest finding in the unified findings table.
type PentestSourceMetadata ¶
type PentestSourceMetadata struct {
StepsToReproduce []string `json:"steps_to_reproduce,omitempty"`
PoCCode string `json:"poc_code,omitempty"`
Evidence []map[string]any `json:"evidence,omitempty"`
RequestResponses []map[string]any `json:"request_responses,omitempty"`
BusinessImpact string `json:"business_impact,omitempty"`
TechnicalImpact string `json:"technical_impact,omitempty"`
RemediationGuidance string `json:"remediation_guidance,omitempty"`
ReviewedBy string `json:"reviewed_by,omitempty"`
OWASPCategory string `json:"owasp_category,omitempty"`
CWEID string `json:"cwe_id,omitempty"`
AffectedAssets []string `json:"affected_assets,omitempty"`
ReferenceURLs []string `json:"reference_urls,omitempty"`
MitreTechniqueID string `json:"mitre_technique_id,omitempty"`
MitreTactic string `json:"mitre_tactic,omitempty"`
CVSSVersion string `json:"cvss_version,omitempty"`
}
PentestSourceMetadata holds pentest-specific data stored in findings.source_metadata JSONB.
type RecordControlTestResultInput ¶
type RecordControlTestResultInput struct {
TenantID string
ControlID string
Status string
Evidence string
Notes string
TestedByID string
}
RecordControlTestResult records a test result.
type SafeCheckDispatcher ¶ added in v0.4.0
type SafeCheckDispatcher interface {
DispatchSimulationCheck(ctx context.Context, tenantID, simRunID, assetID shared.ID, technique string) (shared.ID, error)
}
SafeCheckDispatcher dispatches a real, non-intrusive safe-check probe for a simulation run against a target asset (RFC-012 Phase 1b). Implemented by *validation.RunService. When wired, a network-addressable, safe-checkable simulation runs for real on an agent; the completion hook finalizes the run.
type SimulationService ¶
type SimulationService struct {
// contains filtered or unexported fields
}
SimulationService manages attack simulations and control tests.
func NewSimulationService ¶
func NewSimulationService(simRepo simulation.SimulationRepository, controlRepo simulation.ControlTestRepository, log *logger.Logger) *SimulationService
NewSimulationService creates a new simulation service.
func (*SimulationService) CreateControlTest ¶
func (s *SimulationService) CreateControlTest(ctx context.Context, input CreateControlTestInput) (*simulation.ControlTest, error)
CreateControlTest creates a new control test.
func (*SimulationService) CreateSimulation ¶
func (s *SimulationService) CreateSimulation(ctx context.Context, input CreateSimulationInput) (*simulation.Simulation, error)
CreateSimulation creates a new attack simulation.
func (*SimulationService) DeleteControlTest ¶
func (s *SimulationService) DeleteControlTest(ctx context.Context, tenantID, ctID string) error
DeleteControlTest deletes a control test.
func (*SimulationService) DeleteSimulation ¶
func (s *SimulationService) DeleteSimulation(ctx context.Context, tenantID, simID string) error
DeleteSimulation deletes a simulation.
func (*SimulationService) FinalizeRun ¶ added in v0.4.0
func (s *SimulationService) FinalizeRun(ctx context.Context, tenantID, runID shared.ID, outcome, summary string) error
FinalizeRun completes a running simulation run from a real agent safe-check outcome (RFC-012 Phase 1b — called by the command-completion hook). It maps the reachability outcome to a run result, updates the run + the simulation's rolling stats. Idempotent-friendly: a run that is no longer running is left untouched.
func (*SimulationService) GetControlTest ¶
func (s *SimulationService) GetControlTest(ctx context.Context, tenantID, ctID string) (*simulation.ControlTest, error)
GetControlTest retrieves a control test by ID.
func (*SimulationService) GetControlTestStats ¶
func (s *SimulationService) GetControlTestStats(ctx context.Context, tenantID string) ([]simulation.FrameworkStats, error)
GetControlTestStats returns aggregated stats per framework.
func (*SimulationService) GetSimulation ¶
func (s *SimulationService) GetSimulation(ctx context.Context, tenantID, simID string) (*simulation.Simulation, error)
GetSimulation retrieves a simulation by ID.
func (*SimulationService) ListControlTests ¶
func (s *SimulationService) ListControlTests(ctx context.Context, tenantID string, filter simulation.ControlTestFilter, page pagination.Pagination) (pagination.Result[*simulation.ControlTest], error)
ListControlTests lists control tests with filtering.
func (*SimulationService) ListSimulationRuns ¶
func (s *SimulationService) ListSimulationRuns(ctx context.Context, tenantID, simID string, page pagination.Pagination) (pagination.Result[*simulation.SimulationRun], error)
ListSimulationRuns lists runs for a specific simulation.
func (*SimulationService) ListSimulations ¶
func (s *SimulationService) ListSimulations(ctx context.Context, tenantID string, filter simulation.SimulationFilter, page pagination.Pagination) (pagination.Result[*simulation.Simulation], error)
ListSimulations lists simulations with filtering.
func (*SimulationService) RecordControlTestResult ¶
func (s *SimulationService) RecordControlTestResult(ctx context.Context, input RecordControlTestResultInput) (*simulation.ControlTest, error)
RecordControlTestResult records a test result.
func (*SimulationService) RunSimulation ¶
func (s *SimulationService) RunSimulation(ctx context.Context, tenantID, simID, actorID string) (*simulation.SimulationRun, error)
RunSimulation creates a new run for a simulation and executes it. For atomic simulations, execution is inline (technique check + detection validation). For campaign simulations, this starts the first step and tracks progress.
func (*SimulationService) SetRunRepo ¶
func (s *SimulationService) SetRunRepo(repo simulation.RunRepository)
SetRunRepo sets the run repository (optional — nil disables run persistence).
func (*SimulationService) SetSafeCheckDispatcher ¶ added in v0.4.0
func (s *SimulationService) SetSafeCheckDispatcher(d SafeCheckDispatcher)
SetSafeCheckDispatcher wires the real safe-check dispatcher. When set, an eligible simulation (network-addressable target + safe-checkable technique) runs for real and returns a "running" run finalized asynchronously; otherwise it falls back to the clearly-labeled synthetic path.
A typed-nil is rejected. Storing a nil *validation.RunService in this interface makes the interface itself non-nil, so the `s.safeCheck == nil` guard in tryDispatchLive passes and the call panics on the nil receiver instead of falling back. That is exactly what happened: the composition root called this setter 14 lines before assigning the service, and every simulation carrying a target asset 500'd. Refusing nil here means a mis-ordered wiring degrades to the synthetic path — the documented fallback — rather than crashing.
func (*SimulationService) UpdateSimulation ¶
func (s *SimulationService) UpdateSimulation(ctx context.Context, input UpdateSimulationInput) (*simulation.Simulation, error)
UpdateSimulation updates a simulation.
type StatusChangeResult ¶
StatusChangeResult wraps campaign + optional warning for status transitions.
type TenantMemberChecker ¶
type TenantMemberChecker interface {
IsTenantMember(ctx context.Context, tenantID, userID string) bool
}
TenantMemberChecker verifies if a user belongs to a tenant.
type UpdateAssessmentInput ¶
type UpdateAssessmentInput struct {
TenantID string
FrameworkID string
ControlID string
Status string
Priority string
Owner string
Notes string
DueDate *string
ActorID string
}
UpdateAssessmentInput contains input for updating an assessment.
type UpdateCampaignInput ¶
type UpdateCampaignInput struct {
TenantID string
CampaignID string
Name string
Description string
CampaignType string
Priority string
Methodology string
ClientName string
ClientContact string
StartDate *string
EndDate *string
Objectives []string
ScopeItems []map[string]any
RulesOfEngagement map[string]any
LeadUserID *string
TeamUserIDs []string
AssetIDs []string
AssetGroupIDs []string
Tags []string
Metadata map[string]any
}
UpdateCampaignInput contains the input for updating a campaign.
type UpdateSimulationInput ¶
type UpdateSimulationInput struct {
TenantID string
SimulationID string
Name string
Description string
MitreTactic string
MitreTechniqueID string
MitreTechniqueName string
TargetAssets []string
Config map[string]any
Tags []string
}
UpdateSimulationInput holds input for updating a simulation.