ruleformats

package
v6.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package ruleformats contains logic required for akamai_property_rules_builder data source.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is used when value not found in schema.ResourceData.
	ErrNotFound = errors.New("not found")
	// ErrTypeAssertion is used when type assertion failed.
	ErrTypeAssertion = errors.New("type assertion")
	// ErrTooManyElements is used when too many elements were found in a list.
	ErrTooManyElements = errors.New("too many elements")
	// ErrOnlyForDefault is used when some fields are used outside "default" rules in data source
	ErrOnlyForDefault = errors.New("cannot be used outside 'default' rule")
	// ErrNotForDefault is used when some fields cannot be used in "default" rules in data source
	ErrNotForDefault = errors.New("cannot be used in 'default' rule")
)

Functions

func NameMappings

func NameMappings(ruleFormat string) map[string]string

NameMappings returns a map of option name mappings for a given rule format

For example, field "detect_smart_dns_proxy" converted to camelCase would end up as "detectSmartDnsProxy" and it would be incorrect. Correct value that is expected by API should be "detectSmartDNSProxy" and the returned map would contain following mapping: {"detectSmartDnsProxy":"detectSmartDNSProxy"}

func Schemas

func Schemas() map[string]*schema.Schema

Schemas returns map of terraform schemas for all rule formats that are in the registry.

func ShouldFlattenFunc

func ShouldFlattenFunc(ruleFormat string) func(string) bool

ShouldFlattenFunc returns a function for given rule format that can be called with given "{behavior_name}.{option_name}" as input, and it returns if it should get flatten it is useful for flattening lists that are expected to be objects in json.

func TypeMappings

func TypeMappings(ruleFormat string) map[string]any

TypeMappings returns a map of mappings for a given rule format that is: mappings of values to its expected form in json the keys are "{behavior}.{option_name}.{value}".

For example if a certain enum expects some of the fields to be of a different type than the others, type mapping will take care of the conversion from the common terraform type of that attribute.

Types

type NotFoundError

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

NotFoundError defines an error that is used when value is not found in the schema.ResourceData.

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

Error returns NotFoundError as a string.

func (*NotFoundError) Unwrap

func (e *NotFoundError) Unwrap() error

Unwrap unwraps NotFoundError into ErrNotFound.

type RuleFormat

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

RuleFormat contains information about a specific ruleformat schema.

type RuleItem

type RuleItem struct {
	Name string
	Item map[string]any
}

RuleItem is a struct for holding information about a single behavior or criterion.

type RuleItems

type RuleItems []RuleItem

RuleItems contains slice of RuleItem.

func (RuleItems) Names

func (r RuleItems) Names() []string

Names returns names of all RuleItem contained by RuleItems.

type RuleVersion

type RuleVersion string

RuleVersion contains rule format version and allows for version format conversion.

func GetUsedRuleFormat

func GetUsedRuleFormat(d *schema.ResourceData) RuleVersion

GetUsedRuleFormat finds RuleVersion that is used in schema.ResourceData.

func RulesFormats

func RulesFormats() []RuleVersion

RulesFormats returns a list of all rule formats that are in registry.

func (RuleVersion) SchemaKey

func (v RuleVersion) SchemaKey() string

SchemaKey returns schema key under which given rule version can be found.

func (RuleVersion) Version

func (v RuleVersion) Version() string

Version returns schema version in normalized format.

type RulesBuilder

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

RulesBuilder orchestrates the construction of papi.Rules from the terraform schema.

func NewBuilder

func NewBuilder(d *schema.ResourceData) *RulesBuilder

NewBuilder returns a new RulesBuilder that uses the provided schema.ResourceData to construct papi.Rules.

func (RulesBuilder) Build

func (r RulesBuilder) Build() (*papi.Rules, error)

Build returns papi.Rules built from the terraform schema.

type RulesSchemaReader

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

RulesSchemaReader knows how to retrieve data from schema.ResourceData.

func NewRulesSchemaReader

func NewRulesSchemaReader(d *schema.ResourceData) *RulesSchemaReader

NewRulesSchemaReader creates a new RulesSchemaReader for the given schema.ResourceData.

func (*RulesSchemaReader) GetBehaviorsList

func (r *RulesSchemaReader) GetBehaviorsList() ([]RuleItem, error)

GetBehaviorsList reads and returns a slice of RuleItem, which are behaviors.

func (*RulesSchemaReader) GetChildrenList

func (r *RulesSchemaReader) GetChildrenList() ([]string, error)

GetChildrenList reads and returns slice of children.

func (*RulesSchemaReader) GetCriteriaList

func (r *RulesSchemaReader) GetCriteriaList() ([]RuleItem, error)

GetCriteriaList reads and returns a slice of RuleItem, which are rule criteria.

func (*RulesSchemaReader) GetRuleFormat

func (r *RulesSchemaReader) GetRuleFormat() string

GetRuleFormat returns rule format as a string.

func (*RulesSchemaReader) GetVariablesList

func (r *RulesSchemaReader) GetVariablesList() ([]map[string]any, error)

GetVariablesList reads and returns rule variables as slice of map[string]any.

type RulesUpdate

type RulesUpdate struct {
	RuleFormat string `json:"_ruleFormat_"`
	papi.RulesUpdate
}

RulesUpdate is a helper structure for easier injecting rule format AND preserving the order of fields

type TooManyElementsError

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

TooManyElementsError defines an error that is used when too many elements were found in the list.

func (*TooManyElementsError) Error

func (e *TooManyElementsError) Error() string

Error returns TooManyElementsError as a string.

func (*TooManyElementsError) Unwrap

func (e *TooManyElementsError) Unwrap() error

Unwrap unwraps TooManyElementsError into ErrTooManyElements.

type TypeAssertionError

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

TypeAssertionError defines an error that is used when type assertion failed.

func (*TypeAssertionError) Error

func (e *TypeAssertionError) Error() string

Error returns TypeAssertionError as a string.

func (*TypeAssertionError) Unwrap

func (e *TypeAssertionError) Unwrap() error

Unwrap unwraps TypeAssertionError into ErrTypeAssertion.

Jump to

Keyboard shortcuts

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