Documentation ¶
Overview ¶
Package policy implements management of snapshot policies.
Index ¶
- Variables
- func ApplyRetentionPolicy(ctx context.Context, rep *repo.Repository, sourceInfo snapshot.SourceInfo, ...) ([]*snapshot.Manifest, error)
- func FilesPolicyGetter(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) (ignorefs.FilesPolicyGetter, error)
- func GetEffectivePolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) (*Policy, []*Policy, error)
- func RemovePolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) error
- func SetPolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo, pol *Policy) error
- type Policy
- func GetDefinedPolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) (*Policy, error)
- func GetPolicyByID(ctx context.Context, rep *repo.Repository, id string) (*Policy, error)
- func ListPolicies(ctx context.Context, rep *repo.Repository) ([]*Policy, error)
- func MergePolicies(policies []*Policy) *Policy
- type RetentionPolicy
- type SchedulingPolicy
- type TimeOfDay
Constants ¶
This section is empty.
Variables ¶
var ErrPolicyNotFound = errors.New("policy not found")
ErrPolicyNotFound is returned when the policy is not found.
var GlobalPolicySourceInfo = snapshot.SourceInfo{}
GlobalPolicySourceInfo is a source where global policy is attached.
Functions ¶
func ApplyRetentionPolicy ¶
func ApplyRetentionPolicy(ctx context.Context, rep *repo.Repository, sourceInfo snapshot.SourceInfo, reallyDelete bool) ([]*snapshot.Manifest, error)
ApplyRetentionPolicy applies retention policy to a given source by deleting expired snapshots.
func FilesPolicyGetter ¶
func FilesPolicyGetter(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) (ignorefs.FilesPolicyGetter, error)
FilesPolicyGetter returns ignorefs.FilesPolicyGetter for a given source.
func GetEffectivePolicy ¶
func GetEffectivePolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) (*Policy, []*Policy, error)
GetEffectivePolicy calculates effective snapshot policy for a given source by combining the source-specifc policy (if any) with parent policies. The source must contain a path. Returns the effective policies and all source policies that contributed to that (most specific first).
func RemovePolicy ¶
func RemovePolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) error
RemovePolicy removes the policy for a given source.
func SetPolicy ¶
func SetPolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo, pol *Policy) error
SetPolicy sets the policy on a given source.
Types ¶
type Policy ¶
type Policy struct { Labels map[string]string `json:"-"` RetentionPolicy RetentionPolicy `json:"retention,omitempty"` FilesPolicy ignorefs.FilesPolicy `json:"files,omitempty"` SchedulingPolicy SchedulingPolicy `json:"scheduling,omitempty"` NoParent bool `json:"noParent,omitempty"` }
Policy describes snapshot policy for a single source.
func GetDefinedPolicy ¶
func GetDefinedPolicy(ctx context.Context, rep *repo.Repository, si snapshot.SourceInfo) (*Policy, error)
GetDefinedPolicy returns the policy defined on the provided snapshot.SourceInfo or ErrPolicyNotFound if not present.
func GetPolicyByID ¶
GetPolicyByID gets the policy for a given unique ID or ErrPolicyNotFound if not found.
func ListPolicies ¶
ListPolicies returns a list of all policies.
func MergePolicies ¶
MergePolicies computes the policy by applying the specified list of policies in order.
func (*Policy) Target ¶
func (p *Policy) Target() snapshot.SourceInfo
Target returns the snapshot.SourceInfo describing username, host and path targeted by the policy.
type RetentionPolicy ¶
type RetentionPolicy struct { KeepLatest *int `json:"keepLatest,omitempty"` KeepHourly *int `json:"keepHourly,omitempty"` KeepDaily *int `json:"keepDaily,omitempty"` KeepWeekly *int `json:"keepWeekly,omitempty"` KeepMonthly *int `json:"keepMonthly,omitempty"` KeepAnnual *int `json:"keepAnnual,omitempty"` }
RetentionPolicy describes snapshot retention policy.
func (*RetentionPolicy) ComputeRetentionReasons ¶
func (r *RetentionPolicy) ComputeRetentionReasons(manifests []*snapshot.Manifest)
ComputeRetentionReasons computes the reasons why each snapshot is retained, based on the settings in retention policy and stores them in RetentionReason field.
func (*RetentionPolicy) Merge ¶
func (r *RetentionPolicy) Merge(src RetentionPolicy)
Merge applies default values from the provided policy.
type SchedulingPolicy ¶
type SchedulingPolicy struct { IntervalSeconds int64 `json:"intervalSeconds,omitempty"` TimesOfDay []TimeOfDay `json:"timeOfDay,omitempty"` }
SchedulingPolicy describes policy for scheduling snapshots.
func (*SchedulingPolicy) Interval ¶
func (p *SchedulingPolicy) Interval() time.Duration
Interval returns the snapshot interval or zero if not specified.
func (*SchedulingPolicy) Merge ¶
func (p *SchedulingPolicy) Merge(src SchedulingPolicy)
Merge applies default values from the provided policy.
func (*SchedulingPolicy) SetInterval ¶
func (p *SchedulingPolicy) SetInterval(d time.Duration)
SetInterval sets the snapshot interval (zero disables).
type TimeOfDay ¶
TimeOfDay represents the time of day (hh:mm) using 24-hour time format.
func SortAndDedupeTimesOfDay ¶
SortAndDedupeTimesOfDay sorts the slice of times of day and removes duplicates.