policy

package
v5.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

type Condition map[string]string

Conditions are a set of values that can be compared with a base truth and return true if all of the facets of the condition match.

func (Condition) AppliesTo

func (cond Condition) AppliesTo(truth Condition) bool

AppliesTo returns true if all the facets of this condition match the given truth.

func (Condition) ValidateKeys

func (cond Condition) ValidateKeys(allowedKeys []string) error

ValidateKeys ensures all of the keys of the condition exist in the set of allowed keys.

type Policy

type Policy struct {
	Comment   string    `json:"//"`
	Condition Condition `json:"if"`

	Declarations map[string]interface{} `json:"then"`
}

Policy combines a condition with several sets of values that are set if the condition holds true.

type PolicyList

type PolicyList struct {
	// Policies are ordered from least to greatest precidence.
	Policies []Policy `json:"policy"`

	// Assertions are used to validate the ordering of Policies.
	Assertions []Policy `json:"assert"`
}

PolicyList contains the set of policies.

func NewPolicyListFromJson

func NewPolicyListFromJson(value json.RawMessage, validConditionKeys []string) (*PolicyList, error)

NewPolicyListFromJson creates a PolicyList from the given JSON version. It will fail on invalid condition names and failed assertions.

Exactly one of PolicyList or error will be returned.

func (*PolicyList) Apply

func (pl *PolicyList) Apply(groundTruth Condition) map[string]interface{}

Apply runs through the list of policies, first to last, and cascades the values of each if they match the given condition, returning the merged map at the end.

func (*PolicyList) CheckAssertions

func (pl *PolicyList) CheckAssertions() error

CheckAssertions tests each assertion in the Assertions list against the policies list. The condition is used as the ground truth and the actions are used as the expected output. If the actions don't match then an error is returned.

func (*PolicyList) Validate

func (pl *PolicyList) Validate(validConditionKeys []string) error

Validate checks that the PolicyList struct is valid, that the keys for the conditions are valid and that all assertions hold.

Jump to

Keyboard shortcuts

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