cpolicy

package
v0.15.0-beta Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2016 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoolType = "bool"
)
View Source
const (
	FloatType = "float"
)
View Source
const (
	IntegerType = "integer"
)
View Source
const (
	StringType = "string"
)

Variables

View Source
var (
	EmptyKeyError = errors.New("key cannot be empty")
)

Functions

This section is empty.

Types

type BoolRule

type BoolRule struct {
	// contains filtered or unexported fields
}

BoolRule validating against string-typed config

func NewBoolRule

func NewBoolRule(key string, req bool, opts ...bool) (*BoolRule, error)

NewBoolRule Returns a new bool-typed rule. Arguments are key(string), required(bool), default(bool).

func (*BoolRule) Default

func (b *BoolRule) Default() ctypes.ConfigValue

Default returns a default value is it exists.

func (*BoolRule) GobDecode

func (b *BoolRule) GobDecode(buf []byte) error

GobDecode decodes a GOB into a BoolRule

func (*BoolRule) GobEncode

func (b *BoolRule) GobEncode() ([]byte, error)

GobEncode encodes a BoolRule in to a GOB

func (*BoolRule) Key

func (b *BoolRule) Key() string

Key returns the key

func (*BoolRule) MarshalJSON

func (b *BoolRule) MarshalJSON() ([]byte, error)

MarshalJSON marshals a BoolRule into JSON

func (*BoolRule) Maximum

func (b *BoolRule) Maximum() ctypes.ConfigValue

Maximum returns Maximum possible value of BoolRule

func (*BoolRule) Minimum

func (b *BoolRule) Minimum() ctypes.ConfigValue

Minimum returns Minimum possible value of BoolRule

func (*BoolRule) Required

func (b *BoolRule) Required() bool

Required indicates this rule is required.

func (*BoolRule) Type

func (b *BoolRule) Type() string

Type Returns a type of Rule

func (*BoolRule) Validate

func (b *BoolRule) Validate(cv ctypes.ConfigValue) error

Validate validates a config value against this rule.

type ConfigPolicy

type ConfigPolicy struct {
	// contains filtered or unexported fields
}

Allows adding of config policy by namespace and retrieving of policy from a tree at a specific namespace (merging the relevant hiearchy). Uses pkg.ConfigTree.

func New

func New() *ConfigPolicy

Returns a new ConfigPolicy.

func (*ConfigPolicy) Add

func (c *ConfigPolicy) Add(ns []string, cpn *ConfigPolicyNode)

Adds a ConfigPolicyNode at the provided namespace.

func (*ConfigPolicy) Freeze

func (c *ConfigPolicy) Freeze()

Freezes the ConfigPolicy from future writes (adds) and triggers compression of tree into read-performant version.

func (*ConfigPolicy) Get

func (c *ConfigPolicy) Get(ns []string) *ConfigPolicyNode

Returns a ConfigPolicyNode that is a merged version of the namespace provided.

func (*ConfigPolicy) GetAll

func (c *ConfigPolicy) GetAll() map[string]*ConfigPolicyNode

func (*ConfigPolicy) GobDecode

func (c *ConfigPolicy) GobDecode(buf []byte) error

func (*ConfigPolicy) GobEncode

func (c *ConfigPolicy) GobEncode() ([]byte, error)

func (*ConfigPolicy) MarshalJSON

func (c *ConfigPolicy) MarshalJSON() ([]byte, error)

MarshalJSON marshals a ConfigPolicy into JSON

func (*ConfigPolicy) UnmarshalJSON

func (c *ConfigPolicy) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON into a ConfigPolicy

type ConfigPolicyNode

type ConfigPolicyNode struct {
	// contains filtered or unexported fields
}

func NewPolicyNode

func NewPolicyNode() *ConfigPolicyNode

func (*ConfigPolicyNode) Add

func (p *ConfigPolicyNode) Add(rules ...Rule)

Adds a rule to this policy node

func (*ConfigPolicyNode) AddDefaults

AddDefaults validates and returns a processed policy node or nil and error if validation has failed

func (*ConfigPolicyNode) GobDecode

func (c *ConfigPolicyNode) GobDecode(buf []byte) error

func (*ConfigPolicyNode) GobEncode

func (c *ConfigPolicyNode) GobEncode() ([]byte, error)

func (*ConfigPolicyNode) HasRules

func (c *ConfigPolicyNode) HasRules() bool

func (*ConfigPolicyNode) MarshalJSON

func (c *ConfigPolicyNode) MarshalJSON() ([]byte, error)

func (ConfigPolicyNode) Merge

func (c ConfigPolicyNode) Merge(n ctree.Node) ctree.Node

Merges a ConfigPolicyNode on top of this one (overwriting items where it occurs).

func (*ConfigPolicyNode) Process

Validates and returns a processed policy node or nil and error if validation has failed

func (*ConfigPolicyNode) RulesAsTable

func (p *ConfigPolicyNode) RulesAsTable() []RuleTable

func (*ConfigPolicyNode) UnmarshalJSON

func (c *ConfigPolicyNode) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON into a ConfigPolicyNode

type FloatRule

type FloatRule struct {
	// contains filtered or unexported fields
}

FloatRule A rule validating against string-typed config

func NewFloatRule

func NewFloatRule(key string, req bool, opts ...float64) (*FloatRule, error)

NewFloatRule Returns a new float-typed rule. Arguments are key(string), required(bool), default(float64), min(float64), max(float64)

func (*FloatRule) Default

func (f *FloatRule) Default() ctypes.ConfigValue

Default returns the rule's default value

func (*FloatRule) GobDecode

func (f *FloatRule) GobDecode(buf []byte) error

GobDecode decodes a GOB into a FloatRule

func (*FloatRule) GobEncode

func (f *FloatRule) GobEncode() ([]byte, error)

GobEncode encodes a FloatRule into a GOB

func (*FloatRule) Key

func (f *FloatRule) Key() string

Key Returns the key

func (*FloatRule) MarshalJSON

func (f *FloatRule) MarshalJSON() ([]byte, error)

MarshalJSON marshals a FloatRule into JSON

func (*FloatRule) Maximum

func (i *FloatRule) Maximum() ctypes.ConfigValue

func (*FloatRule) Minimum

func (i *FloatRule) Minimum() ctypes.ConfigValue

func (*FloatRule) Required

func (f *FloatRule) Required() bool

Required a bool indicating whether the rule is required

func (*FloatRule) SetMaximum

func (f *FloatRule) SetMaximum(m float64)

SetMaximum sets the maximum allowable value for this rule

func (*FloatRule) SetMinimum

func (f *FloatRule) SetMinimum(m float64)

SetMinimum sets the minimum allowable value for this rule

func (*FloatRule) Type

func (s *FloatRule) Type() string

func (*FloatRule) Validate

func (f *FloatRule) Validate(cv ctypes.ConfigValue) error

Validate Validates a config value against this rule.

type IntRule

type IntRule struct {
	// contains filtered or unexported fields
}

A rule validating against string-typed config

func NewIntegerRule

func NewIntegerRule(key string, req bool, opts ...int) (*IntRule, error)

Returns a new int-typed rule. Arguments are key(string), required(bool), default(int), min(int), max(int)

func (*IntRule) Default

func (i *IntRule) Default() ctypes.ConfigValue

Default return this rules default value

func (*IntRule) GobDecode

func (i *IntRule) GobDecode(buf []byte) error

GobDecode decodes a GOB into a IntRule

func (*IntRule) GobEncode

func (i *IntRule) GobEncode() ([]byte, error)

GobEncode encodes a IntRule into a GOB

func (*IntRule) Key

func (i *IntRule) Key() string

Key Returns the key

func (*IntRule) MarshalJSON

func (i *IntRule) MarshalJSON() ([]byte, error)

MarshalJSON marshals a IntRule into JSON

func (*IntRule) Maximum

func (i *IntRule) Maximum() ctypes.ConfigValue

func (*IntRule) Minimum

func (i *IntRule) Minimum() ctypes.ConfigValue

func (*IntRule) Required

func (i *IntRule) Required() bool

Required returns a boolean indicating if this rule is required

func (*IntRule) SetMaximum

func (i *IntRule) SetMaximum(m int)

SetMaximum sets the maximum allowed value

func (*IntRule) SetMinimum

func (i *IntRule) SetMinimum(m int)

SetMinimum sets the minimum allowed value

func (*IntRule) Type

func (i *IntRule) Type() string

func (*IntRule) Validate

func (i *IntRule) Validate(cv ctypes.ConfigValue) error

Validate Validates a config value against this rule.

type ProcessingErrors

type ProcessingErrors struct {
	// contains filtered or unexported fields
}

func NewProcessingErrors

func NewProcessingErrors() *ProcessingErrors

func (*ProcessingErrors) AddError

func (p *ProcessingErrors) AddError(e error)

func (*ProcessingErrors) Errors

func (p *ProcessingErrors) Errors() []error

func (*ProcessingErrors) HasErrors

func (p *ProcessingErrors) HasErrors() bool

type Rule

type Rule interface {
	Key() string
	Validate(ctypes.ConfigValue) error
	Default() ctypes.ConfigValue
	Required() bool
	Type() string
	Minimum() ctypes.ConfigValue
	Maximum() ctypes.ConfigValue
}

A rule used to process ConfigData

type RuleTable

type RuleTable struct {
	Name     string
	Type     string
	Default  interface{}
	Required bool
	Minimum  interface{}
	Maximum  interface{}
}

type StringRule

type StringRule struct {
	// contains filtered or unexported fields
}

A rule validating against string-typed config

func NewStringRule

func NewStringRule(key string, req bool, opts ...string) (*StringRule, error)

Returns a new string-typed rule. Arguments are key(string), required(bool), default(string).

func (*StringRule) Default

func (s *StringRule) Default() ctypes.ConfigValue

Returns a default value is it exists.

func (*StringRule) GobDecode

func (s *StringRule) GobDecode(buf []byte) error

GobDecode decodes a GOB into a StringRule

func (*StringRule) GobEncode

func (s *StringRule) GobEncode() ([]byte, error)

GobEncode encodes a StringRule in to a GOB

func (*StringRule) Key

func (s *StringRule) Key() string

Returns the key

func (*StringRule) MarshalJSON

func (s *StringRule) MarshalJSON() ([]byte, error)

MarshalJSON marshals a StringRule into JSON

func (*StringRule) Maximum

func (s *StringRule) Maximum() ctypes.ConfigValue

func (*StringRule) Minimum

func (s *StringRule) Minimum() ctypes.ConfigValue

func (*StringRule) Required

func (s *StringRule) Required() bool

Indicates this rule is required.

func (*StringRule) Type

func (s *StringRule) Type() string

func (*StringRule) Validate

func (s *StringRule) Validate(cv ctypes.ConfigValue) error

Validates a config value against this rule.

Jump to

Keyboard shortcuts

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