policy

package
Version: v0.0.0-...-6f06747 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ComparisonExact      = "exact"
	ComparisonIgnoreCase = "ignorecase"
	ComparisonRegex      = "regex"
)

Comparison types for matching policy criteria.

View Source
const (
	// DefaultLimit is the limit returned for empty policy sets.
	DefaultLimit = ^uint(0)
	// DefaultDuration is the duration returned for empty policy sets.
	DefaultDuration = time.Minute * 15
	// DefaultStrategy is the default resource counting strategy.
	DefaultStrategy = strategy.Instance
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Policies returns the set of policies from the cache.
	Policies() (Set, error)

	// SetPolicies writes the set of policies to the cache.
	SetPolicies(Set) error
}

Cache is a cache of policies.

type Criteria

type Criteria []Criterion

Criteria describes a set of conditions for a policy to be applied.

func (Criteria) Match

func (c Criteria) Match(props lease.Properties) bool

Match returns true if the criteria match the provided lease properties.

func (Criteria) String

func (c Criteria) String() string

String returns a string representation of the criteria.

type Criterion

type Criterion struct {
	Key        string `json:"key"`        // The lease property to be examined
	Comparison string `json:"comparison"` // The operator of the comparison
	Value      string `json:"value"`      // The value the property will be compared with

}

Criterion describes a single condition required for a policy to match.

func (*Criterion) Match

func (c *Criterion) Match(props lease.Properties) bool

Match returns true if the given process is a match.

func (*Criterion) String

func (c *Criterion) String() string

String returns a string representation of the criterion.

type Hash

type Hash [28]byte

Hash is a 224-bit policy hash.

func (Hash) String

func (h Hash) String() string

String returns a string representation of the hash.

type Policy

type Policy struct {
	Resource   string            `json:"resource,omitempty"`   // Which resource pool this policy counts against
	Criteria   Criteria          `json:"criteria,omitempty"`   // Matching criteria for lease properties
	Strategy   strategy.Strategy `json:"strategy,omitempty"`   // Lease counting strategy
	Limit      uint              `json:"limit,omitempty"`      // Max concurrent leases
	Duration   time.Duration     `json:"duration,omitempty"`   // Time before a leased resource is automatically released
	Decay      time.Duration     `json:"decay,omitempty"`      // Time before a released resource is considered available again
	Refresh    lease.Refresh     `json:"refresh,omitempty"`    // Time between lease acquisitions while maintaining a lease
	Properties lease.Properties  `json:"properties,omitempty"` // Merged with each lease's properties
}

Policy describes the matching conditions and rules for handling a particular resource.

A policy is applied only if all of its conditions are matched.

func New

func New(resource string, strat strategy.Strategy, limit uint, duration time.Duration, criteria Criteria) Policy

New returns a new policy for a particular resource with the given limit, duration and criteria.

func (*Policy) Hash

func (p *Policy) Hash() Hash

Hash returns a 224-bit hash of the policy.

func (*Policy) MarshalJSON

func (p *Policy) MarshalJSON() ([]byte, error)

MarshalJSON will encode the policy as JSON.

func (*Policy) Match

func (p *Policy) Match(props lease.Properties) bool

Match returns true if the policy applies to a lease with the given properites.

All of the policy's conditions must match for the policy to be applied.

func (*Policy) String

func (p *Policy) String() string

String returns a string representation of the policy.

func (*Policy) UnmarshalJSON

func (p *Policy) UnmarshalJSON(data []byte) error

UnmarshalJSON will decode JSON policy data.

type Provider

type Provider interface {
	// ProviderName returns the name of the provider.
	ProviderName() string

	// Policies returns the set of policies.
	Policies() (Set, error)

	// Close releases any resources consumed by the provider.
	Close() error
}

Provider is a source of policies.

type Set

type Set []Policy

Set is a set of policies.

func (Set) Decay

func (s Set) Decay() (decay time.Duration)

Decay returns the lease decay for the policy set, which is the maximum value within the set.

If the set is empty, a zero value is returned.

func (Set) Diff

func (s Set) Diff(next Set) (additions, deletions Set)

Diff returns the additions and deletions in next when compared with s.

func (Set) Duration

func (s Set) Duration() (duration time.Duration)

Duration returns the lease duration for the policy set, which is the minimum value within the set.

If the set is empty, DefaultDuration is returned.

func (Set) Limit

func (s Set) Limit() (limit uint)

Limit returns the lease limit for the policy set, which is the minimum value within the set.

If the set is empty, DefaultLimit is returned.

func (Set) Match

func (s Set) Match(props lease.Properties) (matches Set)

Match returns the subset of policies which match the given properties.

func (Set) MatchResource

func (s Set) MatchResource(resource string) (matches Set)

MatchResource returns the subset of policies which apply to resource.

func (Set) Properties

func (s Set) Properties() (props lease.Properties)

Properties returns the merged properties of all policies in the set.

func (Set) Refresh

func (s Set) Refresh() (refresh lease.Refresh)

Refresh returns the lease refresh intervals for the policy set, which are the first non-zero intervals within the set.

If the set is empty, a zero value is returned.

func (Set) Resource

func (s Set) Resource() (resource string)

Resource returns the first resource defined in the policy set.

If the set is empty, the returned value will be blank.

func (Set) Resources

func (s Set) Resources() (resources []string)

Resources returns a slice of unique resources within the policy set.

If the set is empty, the returned value will be nil.

func (Set) Strategy

func (s Set) Strategy() strategy.Strategy

Strategy returns the resource counting strategy for the policy set. The first non-empty strategy in the set will be returned. If the set does not define a non-empty strategy, DefaultStrategy will be returned.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL