businessunit

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package businessunit provides domain models for business unit management.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = fmt.Errorf("%w: business unit not found", shared.ErrNotFound)

Errors

Functions

This section is empty.

Types

type BusinessUnit

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

BusinessUnit represents an organizational unit for risk aggregation.

func NewBusinessUnit

func NewBusinessUnit(tenantID shared.ID, name string) (*BusinessUnit, error)

NewBusinessUnit creates a new business unit with sensible defaults.

func ReconstituteBusinessUnit

func ReconstituteBusinessUnit(
	id, tenantID shared.ID, name, description, ownerName, ownerEmail string,
	criticality Criticality, riskTolerance RiskTolerance, parentID *shared.ID,
	assetCount, findingCount int, avgRiskScore float64, criticalFindingCount int,
	tags []string, createdAt, updatedAt time.Time,
) *BusinessUnit

ReconstituteBusinessUnit creates from persisted data.

func (*BusinessUnit) AssetCount

func (b *BusinessUnit) AssetCount() int

func (*BusinessUnit) AvgRiskScore

func (b *BusinessUnit) AvgRiskScore() float64

func (*BusinessUnit) CreatedAt

func (b *BusinessUnit) CreatedAt() time.Time

func (*BusinessUnit) CriticalFindingCount

func (b *BusinessUnit) CriticalFindingCount() int

func (*BusinessUnit) Criticality added in v0.4.0

func (b *BusinessUnit) Criticality() Criticality

func (*BusinessUnit) Description

func (b *BusinessUnit) Description() string

func (*BusinessUnit) FindingCount

func (b *BusinessUnit) FindingCount() int

func (*BusinessUnit) ID

func (b *BusinessUnit) ID() shared.ID

Getters

func (*BusinessUnit) Name

func (b *BusinessUnit) Name() string

func (*BusinessUnit) OwnerEmail

func (b *BusinessUnit) OwnerEmail() string

func (*BusinessUnit) OwnerName

func (b *BusinessUnit) OwnerName() string

func (*BusinessUnit) ParentID added in v0.4.0

func (b *BusinessUnit) ParentID() *shared.ID

func (*BusinessUnit) RiskTolerance added in v0.4.0

func (b *BusinessUnit) RiskTolerance() RiskTolerance

func (*BusinessUnit) SetCriticality added in v0.4.0

func (b *BusinessUnit) SetCriticality(c Criticality) error

SetCriticality validates and sets the business criticality.

func (*BusinessUnit) SetParent added in v0.4.0

func (b *BusinessUnit) SetParent(parentID *shared.ID) error

SetParent sets the parent business unit. A unit cannot be its own parent. Same-tenant and cycle enforcement live in the service layer, which has repository access to walk the ancestor chain.

func (*BusinessUnit) SetRiskTolerance added in v0.4.0

func (b *BusinessUnit) SetRiskTolerance(t RiskTolerance) error

SetRiskTolerance validates and sets the risk tolerance.

func (*BusinessUnit) SetTags

func (b *BusinessUnit) SetTags(tags []string)

SetTags sets tags.

func (*BusinessUnit) Tags

func (b *BusinessUnit) Tags() []string

func (*BusinessUnit) TenantID

func (b *BusinessUnit) TenantID() shared.ID

func (*BusinessUnit) Update

func (b *BusinessUnit) Update(name, description, ownerName, ownerEmail string)

Update sets mutable fields.

func (*BusinessUnit) UpdateStats

func (b *BusinessUnit) UpdateStats(assetCount, findingCount, criticalCount int, avgRisk float64)

UpdateStats updates cached statistics.

func (*BusinessUnit) UpdatedAt

func (b *BusinessUnit) UpdatedAt() time.Time

type Criticality added in v0.4.0

type Criticality string

Criticality represents the business criticality of a business unit. Values mirror the platform-wide criticality scale used by asset groups and business services (critical|high|medium|low).

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

func ParseCriticality added in v0.4.0

func ParseCriticality(s string) (Criticality, bool)

ParseCriticality parses a string into a Criticality, reporting validity.

func (Criticality) IsValid added in v0.4.0

func (c Criticality) IsValid() bool

func (Criticality) String added in v0.4.0

func (c Criticality) String() string

type Filter

type Filter struct {
	TenantID *shared.ID
	Search   *string
}

Filter defines listing criteria.

type Repository

type Repository interface {
	Create(ctx context.Context, bu *BusinessUnit) error
	GetByID(ctx context.Context, tenantID, id shared.ID) (*BusinessUnit, error)
	Update(ctx context.Context, bu *BusinessUnit) error
	Delete(ctx context.Context, tenantID, id shared.ID) error
	List(ctx context.Context, filter Filter, page pagination.Pagination) (pagination.Result[*BusinessUnit], error)
	// Asset linking
	AddAsset(ctx context.Context, tenantID, buID, assetID shared.ID) error
	RemoveAsset(ctx context.Context, tenantID, buID, assetID shared.ID) error
	ListAssetIDs(ctx context.Context, tenantID, buID shared.ID) ([]shared.ID, error)
	// RecalculateCounts refreshes the cached asset/finding rollup counters
	// for a business unit from its current membership.
	RecalculateCounts(ctx context.Context, tenantID, buID shared.ID) error
}

Repository defines persistence.

type RiskTolerance added in v0.4.0

type RiskTolerance string

RiskTolerance represents how much residual risk a business unit accepts.

const (
	RiskToleranceLow    RiskTolerance = "low"
	RiskToleranceMedium RiskTolerance = "medium"
	RiskToleranceHigh   RiskTolerance = "high"
)

func ParseRiskTolerance added in v0.4.0

func ParseRiskTolerance(s string) (RiskTolerance, bool)

ParseRiskTolerance parses a string into a RiskTolerance, reporting validity.

func (RiskTolerance) IsValid added in v0.4.0

func (t RiskTolerance) IsValid() bool

func (RiskTolerance) String added in v0.4.0

func (t RiskTolerance) String() string

Jump to

Keyboard shortcuts

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