datasource

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// APIKeyPrefixLive is the prefix for live/production API keys.
	APIKeyPrefixLive = "oc_live_"

	// APIKeyPrefixTest is the prefix for test/development API keys.
	APIKeyPrefixTest = "oc_test_"
)

Variables

View Source
var (
	// Validation errors
	ErrTenantIDRequired  = errors.New("tenant ID is required")
	ErrNameRequired      = errors.New("name is required")
	ErrInvalidSourceType = errors.New("invalid source type")
	ErrInvalidStatus     = errors.New("invalid source status")
	ErrAPIKeyRequired    = errors.New("API key is required for this source type")

	// Not found errors
	ErrDataSourceNotFound  = errors.New("data source not found")
	ErrAssetSourceNotFound = errors.New("asset source not found")

	// Conflict errors
	ErrDataSourceExists = errors.New("data source with this name already exists")

	// Authentication errors
	ErrInvalidAPIKey  = errors.New("invalid API key")
	ErrAPIKeyExpired  = errors.New("API key has expired")
	ErrSourceDisabled = errors.New("data source is disabled")
	ErrSourceInactive = errors.New("data source is inactive")

	// Operation errors
	ErrCannotAcceptData = errors.New("data source cannot accept data in current state")
)

Domain errors for data source operations.

Functions

func AlreadyExistsError

func AlreadyExistsError(name string) error

AlreadyExistsError returns an already exists error for a specific data source name.

func GenerateAPIKeyPrefix

func GenerateAPIKeyPrefix(key string) string

GenerateAPIKeyPrefix generates the visible prefix for an API key.

func NotFoundError

func NotFoundError(id string) error

NotFoundError returns a not found error for a specific data source.

func ValidationError

func ValidationError(msg string) error

ValidationError creates a validation error with a custom message.

Types

type AssetSource

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

AssetSource represents the relationship between an asset and a data source. It tracks when and how a source discovered/reported an asset, and what data the source contributed.

func NewAssetSource

func NewAssetSource(
	assetID shared.ID,
	sourceType SourceType,
	sourceID *shared.ID,
) (*AssetSource, error)

NewAssetSource creates a new asset source record.

func ReconstructAssetSource

func ReconstructAssetSource(
	id shared.ID,
	assetID shared.ID,
	sourceType SourceType,
	sourceID *shared.ID,
	firstSeenAt time.Time,
	lastSeenAt time.Time,
	sourceRef string,
	contributedData map[string]any,
	confidence int,
	isPrimary bool,
	seenCount int,
	createdAt time.Time,
	updatedAt time.Time,
) *AssetSource

ReconstructAssetSource creates an AssetSource from stored data (used by repository).

func (*AssetSource) AssetID

func (as *AssetSource) AssetID() shared.ID

func (*AssetSource) Confidence

func (as *AssetSource) Confidence() int

func (*AssetSource) ContributedData

func (as *AssetSource) ContributedData() map[string]any

func (*AssetSource) CreatedAt

func (as *AssetSource) CreatedAt() time.Time

func (*AssetSource) DaysSinceLastSeen

func (as *AssetSource) DaysSinceLastSeen() int

DaysSinceLastSeen returns the number of days since this source last saw the asset.

func (*AssetSource) FirstSeenAt

func (as *AssetSource) FirstSeenAt() time.Time

func (*AssetSource) ID

func (as *AssetSource) ID() shared.ID

func (*AssetSource) IsPrimary

func (as *AssetSource) IsPrimary() bool

func (*AssetSource) IsStale

func (as *AssetSource) IsStale(threshold time.Duration) bool

IsStale returns true if the source hasn't seen the asset recently.

func (*AssetSource) LastSeenAt

func (as *AssetSource) LastSeenAt() time.Time

func (*AssetSource) MergeContributedData

func (as *AssetSource) MergeContributedData(data map[string]any)

MergeContributedData merges new data into the existing contributed data.

func (*AssetSource) RecordSighting

func (as *AssetSource) RecordSighting()

RecordSighting records that this source has seen the asset again. Updates last_seen_at and increments seen_count.

func (*AssetSource) RecordSightingWithData

func (as *AssetSource) RecordSightingWithData(data map[string]any, sourceRef string)

RecordSightingWithData records a sighting with new contributed data.

func (*AssetSource) SeenCount

func (as *AssetSource) SeenCount() int

func (*AssetSource) SetConfidence

func (as *AssetSource) SetConfidence(confidence int)

SetConfidence sets the confidence score.

func (*AssetSource) SetContributedData

func (as *AssetSource) SetContributedData(data map[string]any)

SetContributedData sets the contributed data.

func (*AssetSource) SetPrimary

func (as *AssetSource) SetPrimary(primary bool)

SetPrimary sets whether this is the primary source.

func (*AssetSource) SetSourceRef

func (as *AssetSource) SetSourceRef(ref string)

SetSourceRef sets the source reference.

func (*AssetSource) SourceID

func (as *AssetSource) SourceID() *shared.ID

func (*AssetSource) SourceRef

func (as *AssetSource) SourceRef() string

func (*AssetSource) SourceType

func (as *AssetSource) SourceType() SourceType

func (*AssetSource) ToSummary

func (as *AssetSource) ToSummary(sourceName string) AssetSourceSummary

ToSummary converts an AssetSource to a summary (source name must be provided externally).

func (*AssetSource) UpdatedAt

func (as *AssetSource) UpdatedAt() time.Time

type AssetSourceFilter

type AssetSourceFilter struct {
	AssetID    shared.ID  // Filter by asset ID
	SourceID   shared.ID  // Filter by source ID
	SourceType SourceType // Filter by source type
	IsPrimary  *bool      // Filter by primary flag
}

AssetSourceFilter defines the filter options for listing asset sources.

type AssetSourceListOptions

type AssetSourceListOptions struct {
	Page      int
	PerPage   int
	SortBy    string // first_seen_at, last_seen_at, confidence
	SortOrder string // asc, desc
}

AssetSourceListOptions defines options for listing asset sources.

type AssetSourceListResult

type AssetSourceListResult struct {
	Data       []*AssetSource
	Total      int64
	Page       int
	PerPage    int
	TotalPages int
}

AssetSourceListResult represents a paginated list result.

type AssetSourceRepository

type AssetSourceRepository interface {
	// Create creates a new asset source record.
	Create(ctx context.Context, as *AssetSource) error

	// GetByID retrieves an asset source by ID.
	GetByID(ctx context.Context, id shared.ID) (*AssetSource, error)

	// GetByAssetAndSource retrieves an asset source by asset ID, source type, and source ID.
	GetByAssetAndSource(ctx context.Context, assetID shared.ID, sourceType SourceType, sourceID *shared.ID) (*AssetSource, error)

	// Update updates an existing asset source.
	Update(ctx context.Context, as *AssetSource) error

	// Upsert creates or updates an asset source.
	// If the asset source exists, it updates the last_seen_at, seen_count, and contributed_data.
	Upsert(ctx context.Context, as *AssetSource) error

	// Delete deletes an asset source by ID.
	Delete(ctx context.Context, id shared.ID) error

	// DeleteByAsset deletes all asset sources for an asset.
	DeleteByAsset(ctx context.Context, assetID shared.ID) error

	// DeleteBySource deletes all asset sources for a data source.
	DeleteBySource(ctx context.Context, sourceID shared.ID) error

	// List lists asset sources with filtering and pagination.
	List(ctx context.Context, filter AssetSourceFilter, opts AssetSourceListOptions) (AssetSourceListResult, error)

	// GetByAsset retrieves all sources for an asset.
	GetByAsset(ctx context.Context, assetID shared.ID) ([]*AssetSource, error)

	// GetPrimaryByAsset retrieves the primary source for an asset.
	GetPrimaryByAsset(ctx context.Context, assetID shared.ID) (*AssetSource, error)

	// SetPrimary sets a source as the primary source for an asset.
	// This will unset any existing primary source for the asset.
	SetPrimary(ctx context.Context, assetSourceID shared.ID) error

	// CountBySource returns the number of assets for a data source.
	CountBySource(ctx context.Context, sourceID shared.ID) (int64, error)
}

AssetSourceRepository defines the interface for asset source persistence.

type AssetSourceSummary

type AssetSourceSummary struct {
	SourceType      SourceType     `json:"source_type"`
	SourceID        *string        `json:"source_id,omitempty"`
	SourceName      string         `json:"source_name,omitempty"`
	FirstSeenAt     time.Time      `json:"first_seen_at"`
	LastSeenAt      time.Time      `json:"last_seen_at"`
	SourceRef       string         `json:"source_ref,omitempty"`
	ContributedData map[string]any `json:"contributed_data,omitempty"`
	Confidence      int            `json:"confidence"`
	IsPrimary       bool           `json:"is_primary"`
	SeenCount       int            `json:"seen_count"`
}

AssetSourceSummary is a lightweight summary of an asset source for API responses.

type Capabilities

type Capabilities []Capability

Capabilities is a list of capabilities.

func ParseCapabilities

func ParseCapabilities(ss []string) Capabilities

ParseCapabilities parses a string slice into Capabilities.

func (Capabilities) Contains

func (c Capabilities) Contains(cap Capability) bool

Contains checks if the capabilities list contains a specific capability.

func (Capabilities) Strings

func (c Capabilities) Strings() []string

Strings returns the capabilities as a string slice.

type Capability

type Capability string

Capability represents a capability of a data source.

const (
	// Asset collection capabilities
	CapabilityDomain       Capability = "domain"
	CapabilitySubdomain    Capability = "subdomain"
	CapabilityIPAddress    Capability = "ip_address"
	CapabilityCertificate  Capability = "certificate"
	CapabilityRepository   Capability = "repository"
	CapabilityCloudAccount Capability = "cloud_account"
	CapabilityCompute      Capability = "compute"
	CapabilityStorage      Capability = "storage"
	CapabilityContainer    Capability = "container"
	CapabilityKubernetes   Capability = "kubernetes"
	CapabilityNetwork      Capability = "network"
	CapabilityDatabase     Capability = "database"
	CapabilityService      Capability = "service"

	// Finding/vulnerability capabilities
	CapabilityVulnerability    Capability = "vulnerability"
	CapabilitySecret           Capability = "secret"
	CapabilityMisconfiguration Capability = "misconfiguration"
	CapabilityCompliance       Capability = "compliance"
)

func (Capability) String

func (c Capability) String() string

String returns the string representation of the capability.

type DataSource

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

DataSource represents a data source that can push or pull assets and findings. It can be an integration (pull), collector (push), scanner (push), or manual.

func NewDataSource

func NewDataSource(
	tenantID shared.ID,
	name string,
	typ SourceType,
) (*DataSource, error)

NewDataSource creates a new data source.

func Reconstruct

func Reconstruct(
	id shared.ID,
	tenantID shared.ID,
	name string,
	typ SourceType,
	description string,
	version string,
	hostname string,
	ipAddress net.IP,
	apiKeyHash string,
	apiKeyPrefix string,
	status SourceStatus,
	lastSeenAt *time.Time,
	lastError string,
	errorCount int,
	apiKeyLastUsedAt *time.Time,
	capabilities Capabilities,
	config map[string]any,
	metadata map[string]any,
	assetsCollected int64,
	findingsReported int64,
	lastSyncAt *time.Time,
	lastSyncDurationMs int,
	lastSyncAssets int,
	lastSyncFindings int,
	createdAt time.Time,
	updatedAt time.Time,
) *DataSource

Reconstruct creates a DataSource from stored data (used by repository).

func (*DataSource) APIKeyHash

func (d *DataSource) APIKeyHash() string

func (*DataSource) APIKeyLastUsedAt

func (d *DataSource) APIKeyLastUsedAt() *time.Time

func (*DataSource) APIKeyPrefix

func (d *DataSource) APIKeyPrefix() string

func (*DataSource) AssetsCollected

func (d *DataSource) AssetsCollected() int64

func (*DataSource) CanAcceptData

func (d *DataSource) CanAcceptData() bool

CanAcceptData returns true if the source can accept data pushes.

func (*DataSource) Capabilities

func (d *DataSource) Capabilities() Capabilities

func (*DataSource) Config

func (d *DataSource) Config() map[string]any

func (*DataSource) CreatedAt

func (d *DataSource) CreatedAt() time.Time

func (*DataSource) Description

func (d *DataSource) Description() string

func (*DataSource) Enable

func (d *DataSource) Enable()

Enable enables a disabled source (sets to pending).

func (*DataSource) ErrorCount

func (d *DataSource) ErrorCount() int

func (*DataSource) FindingsReported

func (d *DataSource) FindingsReported() int64

func (*DataSource) HasCapability

func (d *DataSource) HasCapability(cap Capability) bool

HasCapability returns true if the source has the given capability.

func (*DataSource) Hostname

func (d *DataSource) Hostname() string

func (*DataSource) ID

func (d *DataSource) ID() shared.ID

func (*DataSource) IPAddress

func (d *DataSource) IPAddress() net.IP

func (*DataSource) IncrementAssets

func (d *DataSource) IncrementAssets(count int)

IncrementAssets increments the assets collected count.

func (*DataSource) IncrementFindings

func (d *DataSource) IncrementFindings(count int)

IncrementFindings increments the findings reported count.

func (*DataSource) IsStale

func (d *DataSource) IsStale(threshold time.Duration) bool

IsStale returns true if the source hasn't been seen recently.

func (*DataSource) LastError

func (d *DataSource) LastError() string

func (*DataSource) LastSeenAt

func (d *DataSource) LastSeenAt() *time.Time

func (*DataSource) LastSyncAssets

func (d *DataSource) LastSyncAssets() int

func (*DataSource) LastSyncAt

func (d *DataSource) LastSyncAt() *time.Time

func (*DataSource) LastSyncDurationMs

func (d *DataSource) LastSyncDurationMs() int

func (*DataSource) LastSyncFindings

func (d *DataSource) LastSyncFindings() int

func (*DataSource) MarkActive

func (d *DataSource) MarkActive()

MarkActive marks the source as active.

func (*DataSource) MarkDisabled

func (d *DataSource) MarkDisabled()

MarkDisabled marks the source as disabled.

func (*DataSource) MarkError

func (d *DataSource) MarkError(errMsg string)

MarkError marks the source as having an error.

func (*DataSource) MarkInactive

func (d *DataSource) MarkInactive()

MarkInactive marks the source as inactive.

func (*DataSource) Metadata

func (d *DataSource) Metadata() map[string]any

func (*DataSource) Name

func (d *DataSource) Name() string

func (*DataSource) RecordAPIKeyUsage

func (d *DataSource) RecordAPIKeyUsage()

RecordAPIKeyUsage records API key usage.

func (*DataSource) RecordHeartbeat

func (d *DataSource) RecordHeartbeat(version, hostname string, ip net.IP)

RecordHeartbeat records a heartbeat from the source.

func (*DataSource) RecordSync

func (d *DataSource) RecordSync(durationMs, assetsCount, findingsCount int)

RecordSync records a sync operation.

func (*DataSource) SetAPIKey

func (d *DataSource) SetAPIKey(hash, prefix string)

SetAPIKey sets the API key hash and prefix.

func (*DataSource) SetCapabilities

func (d *DataSource) SetCapabilities(caps Capabilities)

SetCapabilities sets the capabilities.

func (*DataSource) SetConfig

func (d *DataSource) SetConfig(config map[string]any)

SetConfig sets the configuration.

func (*DataSource) SetDescription

func (d *DataSource) SetDescription(description string)

SetDescription sets the description.

func (*DataSource) SetHostname

func (d *DataSource) SetHostname(hostname string)

SetHostname sets the hostname.

func (*DataSource) SetIPAddress

func (d *DataSource) SetIPAddress(ip net.IP)

SetIPAddress sets the IP address.

func (*DataSource) SetMetadata

func (d *DataSource) SetMetadata(metadata map[string]any)

SetMetadata sets the metadata.

func (*DataSource) SetVersion

func (d *DataSource) SetVersion(version string)

SetVersion sets the version.

func (*DataSource) Status

func (d *DataSource) Status() SourceStatus

func (*DataSource) TenantID

func (d *DataSource) TenantID() shared.ID

func (*DataSource) Type

func (d *DataSource) Type() SourceType

func (*DataSource) UpdatedAt

func (d *DataSource) UpdatedAt() time.Time

func (*DataSource) Version

func (d *DataSource) Version() string

type Filter

type Filter struct {
	TenantID     string         // Filter by tenant ID
	Type         SourceType     // Filter by source type
	Types        []SourceType   // Filter by multiple source types
	Status       SourceStatus   // Filter by status
	Statuses     []SourceStatus // Filter by multiple statuses
	Search       string         // Search in name and description
	Capabilities []Capability   // Filter by capabilities
}

Filter defines the filter options for listing data sources.

type FindingDataSource

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

FindingDataSource represents the relationship between a finding and a data source. It tracks when and how a source discovered/reported a finding, and what data the source contributed. This is separate from vulnerability.FindingSource which is an enum representing the scan type (sast, dast, etc.).

func NewFindingDataSource

func NewFindingDataSource(
	findingID shared.ID,
	sourceType SourceType,
	sourceID *shared.ID,
) (*FindingDataSource, error)

NewFindingDataSource creates a new finding data source record.

func ReconstructFindingDataSource

func ReconstructFindingDataSource(
	id shared.ID,
	findingID shared.ID,
	sourceType SourceType,
	sourceID *shared.ID,
	firstSeenAt time.Time,
	lastSeenAt time.Time,
	sourceRef string,
	scanID string,
	contributedData map[string]any,
	confidence int,
	isPrimary bool,
	seenCount int,
	createdAt time.Time,
	updatedAt time.Time,
) *FindingDataSource

ReconstructFindingDataSource creates a FindingDataSource from stored data (used by repository).

func (*FindingDataSource) Confidence

func (fs *FindingDataSource) Confidence() int

func (*FindingDataSource) ContributedData

func (fs *FindingDataSource) ContributedData() map[string]any

func (*FindingDataSource) CreatedAt

func (fs *FindingDataSource) CreatedAt() time.Time

func (*FindingDataSource) DaysSinceLastSeen

func (fs *FindingDataSource) DaysSinceLastSeen() int

DaysSinceLastSeen returns the number of days since this source last saw the finding.

func (*FindingDataSource) FindingID

func (fs *FindingDataSource) FindingID() shared.ID

func (*FindingDataSource) FirstSeenAt

func (fs *FindingDataSource) FirstSeenAt() time.Time

func (*FindingDataSource) ID

func (fs *FindingDataSource) ID() shared.ID

func (*FindingDataSource) IsPrimary

func (fs *FindingDataSource) IsPrimary() bool

func (*FindingDataSource) IsStale

func (fs *FindingDataSource) IsStale(threshold time.Duration) bool

IsStale returns true if the source hasn't seen the finding recently.

func (*FindingDataSource) LastSeenAt

func (fs *FindingDataSource) LastSeenAt() time.Time

func (*FindingDataSource) MergeContributedData

func (fs *FindingDataSource) MergeContributedData(data map[string]any)

MergeContributedData merges new data into the existing contributed data.

func (*FindingDataSource) RecordSighting

func (fs *FindingDataSource) RecordSighting()

RecordSighting records that this source has seen the finding again. Updates last_seen_at and increments seen_count.

func (*FindingDataSource) RecordSightingWithData

func (fs *FindingDataSource) RecordSightingWithData(data map[string]any, sourceRef, scanID string)

RecordSightingWithData records a sighting with new contributed data.

func (*FindingDataSource) ScanID

func (fs *FindingDataSource) ScanID() string

func (*FindingDataSource) SeenCount

func (fs *FindingDataSource) SeenCount() int

func (*FindingDataSource) SetConfidence

func (fs *FindingDataSource) SetConfidence(confidence int)

SetConfidence sets the confidence score.

func (*FindingDataSource) SetContributedData

func (fs *FindingDataSource) SetContributedData(data map[string]any)

SetContributedData sets the contributed data.

func (*FindingDataSource) SetPrimary

func (fs *FindingDataSource) SetPrimary(primary bool)

SetPrimary sets whether this is the primary source.

func (*FindingDataSource) SetScanID

func (fs *FindingDataSource) SetScanID(scanID string)

SetScanID sets the scan ID.

func (*FindingDataSource) SetSourceRef

func (fs *FindingDataSource) SetSourceRef(ref string)

SetSourceRef sets the source reference.

func (*FindingDataSource) SourceID

func (fs *FindingDataSource) SourceID() *shared.ID

func (*FindingDataSource) SourceRef

func (fs *FindingDataSource) SourceRef() string

func (*FindingDataSource) SourceType

func (fs *FindingDataSource) SourceType() SourceType

func (*FindingDataSource) ToSummary

func (fs *FindingDataSource) ToSummary(sourceName string) FindingDataSourceSummary

ToSummary converts a FindingDataSource to a summary (source name must be provided externally).

func (*FindingDataSource) UpdatedAt

func (fs *FindingDataSource) UpdatedAt() time.Time

type FindingDataSourceFilter

type FindingDataSourceFilter struct {
	FindingID  shared.ID  // Filter by finding ID
	SourceID   shared.ID  // Filter by source ID
	SourceType SourceType // Filter by source type
	IsPrimary  *bool      // Filter by primary flag
}

FindingDataSourceFilter defines the filter options for listing finding data sources.

type FindingDataSourceListOptions

type FindingDataSourceListOptions struct {
	Page      int
	PerPage   int
	SortBy    string // first_seen_at, last_seen_at, confidence
	SortOrder string // asc, desc
}

FindingDataSourceListOptions defines options for listing finding data sources.

type FindingDataSourceListResult

type FindingDataSourceListResult struct {
	Data       []*FindingDataSource
	Total      int64
	Page       int
	PerPage    int
	TotalPages int
}

FindingDataSourceListResult represents a paginated list result.

type FindingDataSourceRepository

type FindingDataSourceRepository interface {
	// Create creates a new finding data source record.
	Create(ctx context.Context, fs *FindingDataSource) error

	// GetByID retrieves a finding data source by ID.
	GetByID(ctx context.Context, id shared.ID) (*FindingDataSource, error)

	// GetByFindingAndSource retrieves a finding data source by finding ID, source type, and source ID.
	GetByFindingAndSource(ctx context.Context, findingID shared.ID, sourceType SourceType, sourceID *shared.ID) (*FindingDataSource, error)

	// Update updates an existing finding data source.
	Update(ctx context.Context, fs *FindingDataSource) error

	// Upsert creates or updates a finding data source.
	// If the finding data source exists, it updates the last_seen_at, seen_count, and contributed_data.
	Upsert(ctx context.Context, fs *FindingDataSource) error

	// Delete deletes a finding data source by ID.
	Delete(ctx context.Context, id shared.ID) error

	// DeleteByFinding deletes all data sources for a finding.
	DeleteByFinding(ctx context.Context, findingID shared.ID) error

	// DeleteBySource deletes all finding data sources for a data source.
	DeleteBySource(ctx context.Context, sourceID shared.ID) error

	// List lists finding data sources with filtering and pagination.
	List(ctx context.Context, filter FindingDataSourceFilter, opts FindingDataSourceListOptions) (FindingDataSourceListResult, error)

	// GetByFinding retrieves all data sources for a finding.
	GetByFinding(ctx context.Context, findingID shared.ID) ([]*FindingDataSource, error)

	// GetPrimaryByFinding retrieves the primary data source for a finding.
	GetPrimaryByFinding(ctx context.Context, findingID shared.ID) (*FindingDataSource, error)

	// SetPrimary sets a data source as the primary source for a finding.
	// This will unset any existing primary source for the finding.
	SetPrimary(ctx context.Context, findingDataSourceID shared.ID) error

	// CountBySource returns the number of findings for a data source.
	CountBySource(ctx context.Context, sourceID shared.ID) (int64, error)
}

FindingDataSourceRepository defines the interface for finding data source persistence.

type FindingDataSourceSummary

type FindingDataSourceSummary struct {
	SourceType      SourceType     `json:"source_type"`
	SourceID        *string        `json:"source_id,omitempty"`
	SourceName      string         `json:"source_name,omitempty"`
	FirstSeenAt     time.Time      `json:"first_seen_at"`
	LastSeenAt      time.Time      `json:"last_seen_at"`
	SourceRef       string         `json:"source_ref,omitempty"`
	ScanID          string         `json:"scan_id,omitempty"`
	ContributedData map[string]any `json:"contributed_data,omitempty"`
	Confidence      int            `json:"confidence"`
	IsPrimary       bool           `json:"is_primary"`
	SeenCount       int            `json:"seen_count"`
}

FindingDataSourceSummary is a lightweight summary for API responses.

type ListOptions

type ListOptions struct {
	Page      int
	PerPage   int
	SortBy    string // name, type, status, created_at, updated_at, last_seen_at
	SortOrder string // asc, desc
}

ListOptions defines options for listing data sources.

type ListResult

type ListResult struct {
	Data       []*DataSource
	Total      int64
	Page       int
	PerPage    int
	TotalPages int
}

ListResult represents a paginated list result.

type Repository

type Repository interface {
	// Create creates a new data source.
	Create(ctx context.Context, ds *DataSource) error

	// GetByID retrieves a data source by ID.
	GetByID(ctx context.Context, id shared.ID) (*DataSource, error)

	// GetByTenantAndName retrieves a data source by tenant ID and name.
	GetByTenantAndName(ctx context.Context, tenantID shared.ID, name string) (*DataSource, error)

	// GetByAPIKeyPrefix retrieves a data source by API key prefix.
	// Used for quick lookup during authentication.
	GetByAPIKeyPrefix(ctx context.Context, prefix string) (*DataSource, error)

	// Update updates an existing data source.
	Update(ctx context.Context, ds *DataSource) error

	// Delete deletes a data source by ID.
	Delete(ctx context.Context, id shared.ID) error

	// List lists data sources with filtering and pagination.
	List(ctx context.Context, filter Filter, opts ListOptions) (ListResult, error)

	// Count returns the total number of data sources matching the filter.
	Count(ctx context.Context, filter Filter) (int64, error)

	// MarkStaleAsInactive marks data sources that haven't been seen recently as inactive.
	// Returns the number of sources marked as inactive.
	MarkStaleAsInactive(ctx context.Context, tenantID shared.ID, staleThresholdMinutes int) (int, error)

	// GetActiveByTenant retrieves all active data sources for a tenant.
	GetActiveByTenant(ctx context.Context, tenantID shared.ID) ([]*DataSource, error)
}

Repository defines the interface for data source persistence.

type SourceStatus

type SourceStatus string

SourceStatus represents the status of a data source.

const (
	// SourceStatusPending indicates the source is registered but not yet active.
	SourceStatusPending SourceStatus = "pending"

	// SourceStatusActive indicates the source is running and reporting data.
	SourceStatusActive SourceStatus = "active"

	// SourceStatusInactive indicates the source has not reported recently.
	SourceStatusInactive SourceStatus = "inactive"

	// SourceStatusError indicates the source has errors.
	SourceStatusError SourceStatus = "error"

	// SourceStatusDisabled indicates the source was manually disabled.
	SourceStatusDisabled SourceStatus = "disabled"
)

func AllSourceStatuses

func AllSourceStatuses() []SourceStatus

AllSourceStatuses returns all valid source statuses.

func ParseSourceStatus

func ParseSourceStatus(s string) (SourceStatus, error)

ParseSourceStatus parses a string into a SourceStatus.

func (SourceStatus) CanReceiveData

func (s SourceStatus) CanReceiveData() bool

CanReceiveData returns true if the source can receive data.

func (SourceStatus) IsOperational

func (s SourceStatus) IsOperational() bool

IsOperational returns true if the source is in an operational state (pending or active).

func (SourceStatus) IsValid

func (s SourceStatus) IsValid() bool

IsValid checks if the source status is valid.

func (SourceStatus) String

func (s SourceStatus) String() string

String returns the string representation of the source status.

type SourceType

type SourceType string

SourceType represents the type of data source.

const (
	// SourceTypeIntegration represents a pull-based integration (GitHub, AWS, etc.)
	SourceTypeIntegration SourceType = "integration"

	// SourceTypeCollector represents a push-based passive collector (logs, inventory)
	SourceTypeCollector SourceType = "collector"

	// SourceTypeScanner represents a push-based active scanner (vuln scan, port scan)
	SourceTypeScanner SourceType = "scanner"

	// SourceTypeManual represents user-created assets via UI/API
	SourceTypeManual SourceType = "manual"
)

func AllSourceTypes

func AllSourceTypes() []SourceType

AllSourceTypes returns all valid source types.

func ParseSourceType

func ParseSourceType(s string) (SourceType, error)

ParseSourceType parses a string into a SourceType.

func (SourceType) IsPull

func (t SourceType) IsPull() bool

IsPull returns true if this source type pulls data from external systems.

func (SourceType) IsPush

func (t SourceType) IsPush() bool

IsPush returns true if this source type pushes data to the server.

func (SourceType) IsValid

func (t SourceType) IsValid() bool

IsValid checks if the source type is valid.

func (SourceType) RequiresAPIKey

func (t SourceType) RequiresAPIKey() bool

RequiresAPIKey returns true if this source type requires an API key for authentication.

func (SourceType) String

func (t SourceType) String() string

String returns the string representation of the source type.

Jump to

Keyboard shortcuts

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