Documentation
¶
Overview ¶
Package template_source defines the TemplateSource domain entity for managing external template sources.
Index ¶
- type GitSourceConfig
- type HTTPSourceConfig
- type ListInput
- type ListOutput
- type Repository
- type S3SourceConfig
- type SourceType
- type SyncStatus
- type TemplateSource
- func (s *TemplateSource) BelongsToTenant(tenantID shared.ID) bool
- func (s *TemplateSource) CanManage(tenantID shared.ID) error
- func (s *TemplateSource) ClearCredential()
- func (s *TemplateSource) CompleteSyncFailure(err string)
- func (s *TemplateSource) CompleteSyncSuccess(hash string, templateCount int)
- func (s *TemplateSource) Disable()
- func (s *TemplateSource) Enable()
- func (s *TemplateSource) GetSourceConfig() any
- func (s *TemplateSource) NeedsSync() bool
- func (s *TemplateSource) SetCredential(credentialID shared.ID)
- func (s *TemplateSource) SetGitConfig(config *GitSourceConfig) error
- func (s *TemplateSource) SetHTTPConfig(config *HTTPSourceConfig) error
- func (s *TemplateSource) SetS3Config(config *S3SourceConfig) error
- func (s *TemplateSource) StartSync()
- func (s *TemplateSource) Update(name, description string, autoSyncOnScan bool, cacheTTLMinutes int) error
- func (s *TemplateSource) Validate() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GitSourceConfig ¶
type GitSourceConfig struct {
URL string `json:"url"` // https://github.com/org/repo
Branch string `json:"branch"` // main, develop
Path string `json:"path,omitempty"` // templates/nuclei/
AuthType string `json:"auth_type,omitempty"` // none, ssh, token, oauth
}
GitSourceConfig holds configuration for Git repository sources.
func (*GitSourceConfig) Validate ¶
func (c *GitSourceConfig) Validate() error
Validate validates the Git source configuration.
type HTTPSourceConfig ¶
type HTTPSourceConfig struct {
URL string `json:"url"`
AuthType string `json:"auth_type,omitempty"` // none, bearer, basic, api_key
Headers map[string]string `json:"headers,omitempty"`
Timeout int `json:"timeout,omitempty"` // Seconds
}
HTTPSourceConfig holds configuration for HTTP URL sources.
func (*HTTPSourceConfig) Validate ¶
func (c *HTTPSourceConfig) Validate() error
Validate validates the HTTP source configuration.
type ListInput ¶
type ListInput struct {
TenantID shared.ID
SourceType *SourceType // Filter by source type
TemplateType *scannertemplate.TemplateType // Filter by template type
Enabled *bool // Filter by enabled status
Page int
PageSize int
SortBy string
SortOrder string
}
ListInput represents the input for listing template sources.
type ListOutput ¶
type ListOutput struct {
Items []*TemplateSource
TotalCount int
}
ListOutput represents the output of listing template sources.
type Repository ¶
type Repository interface {
// Create creates a new template source.
Create(ctx context.Context, source *TemplateSource) error
// GetByID retrieves a template source by ID.
GetByID(ctx context.Context, id shared.ID) (*TemplateSource, error)
// GetByTenantAndID retrieves a template source by tenant ID and source ID.
GetByTenantAndID(ctx context.Context, tenantID, sourceID shared.ID) (*TemplateSource, error)
// GetByTenantAndName retrieves a template source by tenant and name.
GetByTenantAndName(ctx context.Context, tenantID shared.ID, name string) (*TemplateSource, error)
// List lists template sources with pagination and filtering.
List(ctx context.Context, input ListInput) (*ListOutput, error)
// ListByTenantAndTemplateType lists sources for a tenant and template type.
ListByTenantAndTemplateType(ctx context.Context, tenantID shared.ID, templateType scannertemplate.TemplateType) ([]*TemplateSource, error)
// ListEnabledForSync lists enabled sources that need syncing for a tenant.
ListEnabledForSync(ctx context.Context, tenantID shared.ID) ([]*TemplateSource, error)
// ListAllNeedingSync lists all enabled sources across all tenants that need syncing.
// Used by background sync scheduler.
ListAllNeedingSync(ctx context.Context) ([]*TemplateSource, error)
// Update updates a template source.
Update(ctx context.Context, source *TemplateSource) error
// Delete deletes a template source.
Delete(ctx context.Context, id shared.ID) error
// UpdateSyncStatus updates only the sync-related fields.
UpdateSyncStatus(ctx context.Context, source *TemplateSource) error
// CountByTenant counts the total sources for a tenant.
CountByTenant(ctx context.Context, tenantID shared.ID) (int, error)
}
Repository defines the interface for template source persistence.
type S3SourceConfig ¶
type S3SourceConfig struct {
Bucket string `json:"bucket"`
Region string `json:"region"`
Prefix string `json:"prefix,omitempty"` // scanner-templates/nuclei/
Endpoint string `json:"endpoint,omitempty"` // For MinIO
AuthType string `json:"auth_type,omitempty"` // keys, sts_role
RoleArn string `json:"role_arn,omitempty"` // For cross-account
ExternalID string `json:"external_id,omitempty"` // For STS
}
S3SourceConfig holds configuration for S3/MinIO bucket sources.
func (*S3SourceConfig) Validate ¶
func (c *S3SourceConfig) Validate() error
Validate validates the S3 source configuration.
type SourceType ¶
type SourceType string
SourceType represents the type of template source.
const ( // SourceTypeGit represents a Git repository source. SourceTypeGit SourceType = "git" // SourceTypeS3 represents an S3/MinIO bucket source. SourceTypeS3 SourceType = "s3" // SourceTypeHTTP represents an HTTP URL source. SourceTypeHTTP SourceType = "http" )
func (SourceType) IsValid ¶
func (s SourceType) IsValid() bool
IsValid checks if the source type is valid.
type SyncStatus ¶
type SyncStatus string
SyncStatus represents the status of the last sync operation.
const ( // SyncStatusPending means sync has not been attempted yet. SyncStatusPending SyncStatus = "pending" // SyncStatusInProgress means sync is currently running. SyncStatusInProgress SyncStatus = "in_progress" // SyncStatusSuccess means the last sync was successful. SyncStatusSuccess SyncStatus = "success" // SyncStatusFailed means the last sync failed. SyncStatusFailed SyncStatus = "failed" )
func (SyncStatus) IsValid ¶
func (s SyncStatus) IsValid() bool
IsValid checks if the sync status is valid.
type TemplateSource ¶
type TemplateSource struct {
ID shared.ID
TenantID shared.ID
Name string
SourceType SourceType
TemplateType scannertemplate.TemplateType
Description string
Enabled bool
// Source-specific configuration (polymorphic)
GitConfig *GitSourceConfig `json:"git_config,omitempty"`
S3Config *S3SourceConfig `json:"s3_config,omitempty"`
HTTPConfig *HTTPSourceConfig `json:"http_config,omitempty"`
// Lazy sync settings (NO background polling - sync on scan trigger)
AutoSyncOnScan bool // Check for updates when scan triggers
CacheTTLMinutes int // Minutes to cache before re-check (default: 60)
// Last sync info
LastSyncAt *time.Time
LastSyncHash string // ETag/commit hash for change detection
LastSyncStatus SyncStatus
LastSyncError *string
// Sync statistics
TotalTemplates int
LastSyncCount int // Templates synced in last sync
// Credential reference
CredentialID *shared.ID
// Audit
CreatedBy *shared.ID
CreatedAt time.Time
UpdatedAt time.Time
}
TemplateSource represents an external source for scanner templates.
func NewTemplateSource ¶
func NewTemplateSource( tenantID shared.ID, name string, sourceType SourceType, templateType scannertemplate.TemplateType, createdBy *shared.ID, ) (*TemplateSource, error)
NewTemplateSource creates a new template source.
func (*TemplateSource) BelongsToTenant ¶
func (s *TemplateSource) BelongsToTenant(tenantID shared.ID) bool
BelongsToTenant checks if this source belongs to the specified tenant.
func (*TemplateSource) CanManage ¶
func (s *TemplateSource) CanManage(tenantID shared.ID) error
CanManage checks if the given tenant can manage this source.
func (*TemplateSource) ClearCredential ¶
func (s *TemplateSource) ClearCredential()
ClearCredential clears the credential reference.
func (*TemplateSource) CompleteSyncFailure ¶
func (s *TemplateSource) CompleteSyncFailure(err string)
CompleteSyncFailure marks the sync as failed.
func (*TemplateSource) CompleteSyncSuccess ¶
func (s *TemplateSource) CompleteSyncSuccess(hash string, templateCount int)
CompleteSyncSuccess marks the sync as successful.
func (*TemplateSource) GetSourceConfig ¶
func (s *TemplateSource) GetSourceConfig() any
GetSourceConfig returns the active source configuration based on source type.
func (*TemplateSource) NeedsSync ¶
func (s *TemplateSource) NeedsSync() bool
NeedsSync checks if the source needs to be synced based on cache TTL.
func (*TemplateSource) SetCredential ¶
func (s *TemplateSource) SetCredential(credentialID shared.ID)
SetCredential sets the credential reference.
func (*TemplateSource) SetGitConfig ¶
func (s *TemplateSource) SetGitConfig(config *GitSourceConfig) error
SetGitConfig sets the Git source configuration.
func (*TemplateSource) SetHTTPConfig ¶
func (s *TemplateSource) SetHTTPConfig(config *HTTPSourceConfig) error
SetHTTPConfig sets the HTTP source configuration.
func (*TemplateSource) SetS3Config ¶
func (s *TemplateSource) SetS3Config(config *S3SourceConfig) error
SetS3Config sets the S3 source configuration.
func (*TemplateSource) StartSync ¶
func (s *TemplateSource) StartSync()
StartSync marks the sync as in progress.
func (*TemplateSource) Update ¶
func (s *TemplateSource) Update(name, description string, autoSyncOnScan bool, cacheTTLMinutes int) error
Update updates the template source.
func (*TemplateSource) Validate ¶
func (s *TemplateSource) Validate() error
Validate validates the source configuration.