Documentation
¶
Overview ¶
Package asset_group provides domain models for asset group management. Asset groups organize assets for CTEM (Continuous Threat Exposure Management) scoping.
Index ¶
- func AllowedSortFields() map[string]string
- type AssetGroup
- func NewAssetGroup(name string, environment Environment, criticality Criticality) (*AssetGroup, error)
- func NewAssetGroupWithTenant(tenantID shared.ID, name string, environment Environment, ...) (*AssetGroup, error)
- func Reconstitute(id shared.ID, tenantID shared.ID, name string, description string, ...) *AssetGroup
- func (g *AssetGroup) AddTag(tag string)
- func (g *AssetGroup) AssetCount() int
- func (g *AssetGroup) BusinessUnit() string
- func (g *AssetGroup) CloudCount() int
- func (g *AssetGroup) CreatedAt() time.Time
- func (g *AssetGroup) CredentialCount() int
- func (g *AssetGroup) Criticality() Criticality
- func (g *AssetGroup) Description() string
- func (g *AssetGroup) DomainCount() int
- func (g *AssetGroup) Environment() Environment
- func (g *AssetGroup) FindingCount() int
- func (g *AssetGroup) ID() shared.ID
- func (g *AssetGroup) Name() string
- func (g *AssetGroup) Owner() string
- func (g *AssetGroup) OwnerEmail() string
- func (g *AssetGroup) RemoveTag(tag string)
- func (g *AssetGroup) RepositoryCount() int
- func (g *AssetGroup) RiskScore() int
- func (g *AssetGroup) ServiceCount() int
- func (g *AssetGroup) SetTags(tags []string)
- func (g *AssetGroup) SetTenantID(tenantID shared.ID)
- func (g *AssetGroup) Tags() []string
- func (g *AssetGroup) TenantID() shared.ID
- func (g *AssetGroup) UpdateBusinessUnit(bu string)
- func (g *AssetGroup) UpdateCounts(total, domain, website, service, repository, cloud, credential int)
- func (g *AssetGroup) UpdateCriticality(crit Criticality) error
- func (g *AssetGroup) UpdateDescription(description string)
- func (g *AssetGroup) UpdateEnvironment(env Environment) error
- func (g *AssetGroup) UpdateName(name string) error
- func (g *AssetGroup) UpdateOwner(owner, email string)
- func (g *AssetGroup) UpdateRiskMetrics(riskScore, findingCount int)
- func (g *AssetGroup) UpdatedAt() time.Time
- func (g *AssetGroup) WebsiteCount() int
- type Criticality
- type Environment
- type Filter
- func (f Filter) WithBusinessUnit(bu string) Filter
- func (f Filter) WithCriticalities(crits ...Criticality) Filter
- func (f Filter) WithEnvironments(envs ...Environment) Filter
- func (f Filter) WithHasFindings(hasFindings bool) Filter
- func (f Filter) WithSearch(search string) Filter
- func (f Filter) WithTags(tags ...string) Filter
- func (f Filter) WithTenantID(tenantID string) Filter
- type GroupAsset
- type GroupFinding
- type ListOptions
- type Repository
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllowedSortFields ¶
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 (Filter) WithBusinessUnit ¶
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 ¶
WithHasFindings adds a has findings filter.
func (Filter) WithSearch ¶
WithSearch adds a search filter.
func (Filter) WithTenantID ¶
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 (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.