Documentation
¶
Overview ¶
Package policy provides storage retention and cleanup policy management.
Index ¶
- func ParsePolicyName(name string) (string, time.Duration, error)
- type Config
- type Metadata
- type TimeBasedPolicyHandler
- func (h *TimeBasedPolicyHandler) ApplyPolicy(ctx context.Context, metadata *storage.MediaMetadata) error
- func (h *TimeBasedPolicyHandler) EnforcePolicy(ctx context.Context, baseDir string) error
- func (h *TimeBasedPolicyHandler) RegisterPolicy(policy Config) error
- func (h *TimeBasedPolicyHandler) StartEnforcement(ctx context.Context, baseDir string)
- func (h *TimeBasedPolicyHandler) Stop()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParsePolicyName ¶
ParsePolicyName extracts policy type and parameters from a policy name. Supported formats:
- "delete-after-Xmin" - Delete after X minutes
- "retain-Xdays" - Retain for X days
- "retain-Xhours" - Retain for X hours
Returns (policyType, duration, error)
Types ¶
type Config ¶ added in v1.1.3
type Config struct {
// Name is a unique identifier for this policy (e.g., "delete-after-5min", "retain-30days")
Name string `json:"name" yaml:"name"`
// Description provides human-readable documentation for this policy
Description string `json:"description,omitempty" yaml:"description,omitempty"`
// Rules contains policy-specific configuration (e.g., retention duration)
Rules map[string]interface{} `json:"rules,omitempty" yaml:"rules,omitempty"`
}
PolicyConfig defines a retention policy for media storage. Policies control how long media should be retained and when it should be deleted.
type Metadata ¶ added in v1.1.3
type Metadata struct {
// PolicyName identifies the policy applied to this media
PolicyName string `json:"policy_name"`
// ExpiresAt is when this media should be deleted (nil = never expires)
ExpiresAt *time.Time `json:"expires_at,omitempty"`
// CreatedAt is when the policy was applied
CreatedAt time.Time `json:"created_at"`
}
PolicyMetadata stores policy information in .meta files alongside media. This metadata is used by the enforcement system to determine when to delete files.
type TimeBasedPolicyHandler ¶
type TimeBasedPolicyHandler struct {
// contains filtered or unexported fields
}
TimeBasedPolicyHandler implements PolicyHandler for time-based retention policies. It applies expiration times to media based on policy names and enforces deletion of expired media through background scanning.
func NewTimeBasedPolicyHandler ¶
func NewTimeBasedPolicyHandler(enforcementInterval time.Duration) *TimeBasedPolicyHandler
NewTimeBasedPolicyHandler creates a new time-based policy handler.
func (*TimeBasedPolicyHandler) ApplyPolicy ¶
func (h *TimeBasedPolicyHandler) ApplyPolicy(ctx context.Context, metadata *storage.MediaMetadata) error
ApplyPolicy implements storage.PolicyHandler.ApplyPolicy
func (*TimeBasedPolicyHandler) EnforcePolicy ¶
func (h *TimeBasedPolicyHandler) EnforcePolicy(ctx context.Context, baseDir string) error
EnforcePolicy implements storage.PolicyHandler.EnforcePolicy
func (*TimeBasedPolicyHandler) RegisterPolicy ¶
func (h *TimeBasedPolicyHandler) RegisterPolicy(policy Config) error
RegisterPolicy adds a policy configuration to the handler.
func (*TimeBasedPolicyHandler) StartEnforcement ¶
func (h *TimeBasedPolicyHandler) StartEnforcement(ctx context.Context, baseDir string)
StartEnforcement starts a background goroutine that periodically enforces policies.
func (*TimeBasedPolicyHandler) Stop ¶
func (h *TimeBasedPolicyHandler) Stop()
Stop signals the enforcement goroutine to stop and waits for it to finish.