Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
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 ¶
AppliesTo returns true if all the facets of this condition match the given truth.
func (Condition) ValidateKeys ¶
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.