assetgroup

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package asset_group provides domain models for asset group management. Asset groups organize assets for CTEM (Continuous Threat Exposure Management) scoping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllowedSortFields

func AllowedSortFields() map[string]string

AllowedSortFields returns the allowed sort fields for asset groups.

Types

type AssetGroup

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

AssetGroup represents a logical grouping of assets.

func NewAssetGroup

func NewAssetGroup(name string, environment Environment, criticality Criticality) (*AssetGroup, error)

NewAssetGroup creates a new AssetGroup entity.

func NewAssetGroupWithTenant

func NewAssetGroupWithTenant(tenantID shared.ID, name string, environment Environment, criticality Criticality) (*AssetGroup, error)

NewAssetGroupWithTenant creates a new AssetGroup entity with tenant.

func Reconstitute

func Reconstitute(
	id shared.ID,
	tenantID shared.ID,
	name string,
	description string,
	environment Environment,
	criticality Criticality,
	businessUnit string,
	owner string,
	ownerEmail string,
	tags []string,
	assetCount int,
	domainCount int,
	websiteCount int,
	serviceCount int,
	repositoryCount int,
	cloudCount int,
	credentialCount int,
	riskScore int,
	findingCount int,
	createdAt time.Time,
	updatedAt time.Time,
) *AssetGroup

Reconstitute recreates an AssetGroup from persistence.

func (*AssetGroup) AddTag

func (g *AssetGroup) AddTag(tag string)

func (*AssetGroup) AssetCount

func (g *AssetGroup) AssetCount() int

func (*AssetGroup) BusinessUnit

func (g *AssetGroup) BusinessUnit() string

func (*AssetGroup) CloudCount

func (g *AssetGroup) CloudCount() int

func (*AssetGroup) CreatedAt

func (g *AssetGroup) CreatedAt() time.Time

func (*AssetGroup) CredentialCount

func (g *AssetGroup) CredentialCount() int

func (*AssetGroup) Criticality

func (g *AssetGroup) Criticality() Criticality

func (*AssetGroup) Description

func (g *AssetGroup) Description() string

func (*AssetGroup) DomainCount

func (g *AssetGroup) DomainCount() int

func (*AssetGroup) Environment

func (g *AssetGroup) Environment() Environment

func (*AssetGroup) FindingCount

func (g *AssetGroup) FindingCount() int

func (*AssetGroup) ID

func (g *AssetGroup) ID() shared.ID

func (*AssetGroup) Name

func (g *AssetGroup) Name() string

func (*AssetGroup) Owner

func (g *AssetGroup) Owner() string

func (*AssetGroup) OwnerEmail

func (g *AssetGroup) OwnerEmail() string

func (*AssetGroup) RemoveTag

func (g *AssetGroup) RemoveTag(tag string)

func (*AssetGroup) RepositoryCount

func (g *AssetGroup) RepositoryCount() int

func (*AssetGroup) RiskScore

func (g *AssetGroup) RiskScore() int

func (*AssetGroup) ServiceCount

func (g *AssetGroup) ServiceCount() int

func (*AssetGroup) SetTags

func (g *AssetGroup) SetTags(tags []string)

func (*AssetGroup) SetTenantID

func (g *AssetGroup) SetTenantID(tenantID shared.ID)

func (*AssetGroup) Tags

func (g *AssetGroup) Tags() []string

func (*AssetGroup) TenantID

func (g *AssetGroup) TenantID() shared.ID

func (*AssetGroup) UpdateBusinessUnit

func (g *AssetGroup) UpdateBusinessUnit(bu string)

func (*AssetGroup) UpdateCounts

func (g *AssetGroup) UpdateCounts(total, domain, website, service, repository, cloud, credential int)

UpdateCounts updates the asset counts.

func (*AssetGroup) UpdateCriticality

func (g *AssetGroup) UpdateCriticality(crit Criticality) error

func (*AssetGroup) UpdateDescription

func (g *AssetGroup) UpdateDescription(description string)

func (*AssetGroup) UpdateEnvironment

func (g *AssetGroup) UpdateEnvironment(env Environment) error

func (*AssetGroup) UpdateName

func (g *AssetGroup) UpdateName(name string) error

func (*AssetGroup) UpdateOwner

func (g *AssetGroup) UpdateOwner(owner, email string)

func (*AssetGroup) UpdateRiskMetrics

func (g *AssetGroup) UpdateRiskMetrics(riskScore, findingCount int)

UpdateRiskMetrics updates risk score and finding count.

func (*AssetGroup) UpdatedAt

func (g *AssetGroup) UpdatedAt() time.Time

func (*AssetGroup) WebsiteCount

func (g *AssetGroup) WebsiteCount() int

type Criticality

type Criticality string

Criticality represents the business criticality of an asset group.

const (
	CriticalityCritical Criticality = "critical"
	CriticalityHigh     Criticality = "high"
	CriticalityMedium   Criticality = "medium"
	CriticalityLow      Criticality = "low"
)

func AllCriticalities

func AllCriticalities() []Criticality

func ParseCriticality

func ParseCriticality(s string) (Criticality, bool)

func (Criticality) IsValid

func (c Criticality) IsValid() bool

func (Criticality) Score

func (c Criticality) Score() int

Score returns a numeric score for the criticality (for risk calculations).

func (Criticality) String

func (c Criticality) String() string

type Environment

type Environment string

Environment represents the deployment environment of an asset group.

const (
	EnvironmentProduction  Environment = "production"
	EnvironmentStaging     Environment = "staging"
	EnvironmentDevelopment Environment = "development"
	EnvironmentTesting     Environment = "testing"
)

func AllEnvironments

func AllEnvironments() []Environment

func ParseEnvironment

func ParseEnvironment(s string) (Environment, bool)

func (Environment) IsValid

func (e Environment) IsValid() bool

func (Environment) String

func (e Environment) String() string

type Filter

type Filter struct {
	TenantID      *string
	Search        *string
	Environments  []Environment
	Criticalities []Criticality
	BusinessUnit  *string
	Owner         *string
	Tags          []string
	HasFindings   *bool
	MinRiskScore  *int
	MaxRiskScore  *int
}

Filter defines the filtering options for listing asset groups.

func NewFilter

func NewFilter() Filter

NewFilter creates an empty filter.

func (Filter) WithBusinessUnit

func (f Filter) WithBusinessUnit(bu string) Filter

WithBusinessUnit adds a business unit filter.

func (Filter) WithCriticalities

func (f Filter) WithCriticalities(crits ...Criticality) Filter

WithCriticalities adds a criticalities filter.

func (Filter) WithEnvironments

func (f Filter) WithEnvironments(envs ...Environment) Filter

WithEnvironments adds an environments filter.

func (Filter) WithHasFindings

func (f Filter) WithHasFindings(hasFindings bool) Filter

WithHasFindings adds a has findings filter.

func (Filter) WithSearch

func (f Filter) WithSearch(search string) Filter

WithSearch adds a search filter.

func (Filter) WithTags

func (f Filter) WithTags(tags ...string) Filter

WithTags adds a tags filter.

func (Filter) WithTenantID

func (f Filter) WithTenantID(tenantID string) Filter

WithTenantID adds a tenant ID filter.

type GroupAsset

type GroupAsset struct {
	ID           shared.ID
	Name         string
	Type         string
	Status       string
	RiskScore    int
	FindingCount int
	LastSeen     string
}

GroupAsset represents a simplified asset for group context.

type GroupFinding

type GroupFinding struct {
	ID           shared.ID
	Title        string
	Severity     string
	Status       string
	AssetID      shared.ID
	AssetName    string
	AssetType    string
	DiscoveredAt string
}

GroupFinding represents a finding in group context (joined with asset info).

type ListOptions

type ListOptions struct {
	Sort *pagination.SortOption
}

ListOptions contains options for listing asset groups.

func NewListOptions

func NewListOptions() ListOptions

NewListOptions creates empty list options.

func (ListOptions) WithSort

func (o ListOptions) WithSort(sort *pagination.SortOption) ListOptions

WithSort adds sorting options.

type Repository

type Repository interface {
	// Create persists a new asset group.
	Create(ctx context.Context, group *AssetGroup) error

	// GetByID retrieves an asset group by its ID.
	GetByID(ctx context.Context, id shared.ID) (*AssetGroup, error)

	// Update updates an existing asset group.
	Update(ctx context.Context, group *AssetGroup) error

	// Delete removes an asset group by its ID.
	Delete(ctx context.Context, id shared.ID) error

	// List retrieves asset groups with filtering, sorting, and pagination.
	List(ctx context.Context, filter Filter, opts ListOptions, page pagination.Pagination) (pagination.Result[*AssetGroup], error)

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

	// ExistsByName checks if an asset group with the given name exists.
	ExistsByName(ctx context.Context, tenantID shared.ID, name string) (bool, error)

	// GetStats returns aggregated statistics for asset groups.
	GetStats(ctx context.Context, tenantID shared.ID) (*Stats, error)

	// AddAssets adds assets to a group.
	AddAssets(ctx context.Context, groupID shared.ID, assetIDs []shared.ID) error

	// RemoveAssets removes assets from a group.
	RemoveAssets(ctx context.Context, groupID shared.ID, assetIDs []shared.ID) error

	// GetGroupAssets returns assets belonging to a group.
	GetGroupAssets(ctx context.Context, groupID shared.ID, page pagination.Pagination) (pagination.Result[*GroupAsset], error)

	// GetGroupFindings returns findings for assets belonging to a group.
	GetGroupFindings(ctx context.Context, groupID shared.ID, page pagination.Pagination) (pagination.Result[*GroupFinding], error)

	// GetGroupIDsByAssetID returns IDs of groups containing a specific asset.
	GetGroupIDsByAssetID(ctx context.Context, assetID shared.ID) ([]shared.ID, error)

	// RecalculateCounts recalculates asset counts for a group.
	RecalculateCounts(ctx context.Context, groupID shared.ID) error

	// GetDistinctAssetTypes returns all unique asset types in a group.
	// Used for scan compatibility checking.
	GetDistinctAssetTypes(ctx context.Context, groupID shared.ID) ([]string, error)

	// GetDistinctAssetTypesMultiple returns all unique asset types across multiple groups.
	// Used when scan has multiple asset groups (AssetGroupIDs[]).
	GetDistinctAssetTypesMultiple(ctx context.Context, groupIDs []shared.ID) ([]string, error)

	// CountAssetsByType returns count of assets per type in a group.
	// Used for compatibility preview at scan creation.
	CountAssetsByType(ctx context.Context, groupID shared.ID) (map[string]int64, error)
}

Repository defines the interface for asset group persistence.

type Stats

type Stats struct {
	Total            int64
	ByEnvironment    map[Environment]int64
	ByCriticality    map[Criticality]int64
	TotalAssets      int64
	TotalFindings    int64
	AverageRiskScore float64
}

Stats represents aggregated statistics for asset groups.

Jump to

Keyboard shortcuts

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