dataspec

package
v0.4.3-final-apache Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Documentable wrapper types form

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAndEvalAttr

func DecodeAndEvalAttr(ctx context.Context, hclAttr *hclsyntax.Attribute, spec *AttrSpec, dataCtx plugindata.Map) (val cty.Value, diags diagnostics.Diag)

DecodeAndEvalAttr decodes hclsyntax.Attribute into a Attr according to the given AttrSpec and evaluates it.

func EvalAttr

func EvalAttr(ctx context.Context, attr *Attr, dataCtx plugindata.Map) (val cty.Value, diags diagnostics.Diag)

EvalAttr evaluates deferred values in the given attribute and validates it.

func EvalBlock

func EvalBlock(ctx context.Context, block *Block, dataCtx plugindata.Map) (diags diagnostics.Diag)

EvalBlock evaluates deferred values in the given block and validates the attributes. WARNING: This function modifies the input block (its attributes and blocks) in place. Not suitable for evaluating deferred blocks

func EvaluateDeferred

func EvaluateDeferred(ctx context.Context, dataCtx plugindata.Map, val *Attr) (res cty.Value, diags diagnostics.Diag)

EvaluateDeferred evaluates deferred values in the given attribute.

func RenderDoc

func RenderDoc(spec *RootSpec, blockName string, labels ...string) string

RenderDoc renders the block documentation for spec.

Types

type Attr

type Attr struct {
	Name       string
	NameRange  hcl.Range
	Value      cty.Value
	ValueRange hcl.Range
	Secret     bool
	// contains filtered or unexported fields
}

func DecodeAttr

func DecodeAttr(ctx *hcl.EvalContext, attr *hclsyntax.Attribute, spec *AttrSpec) (val *Attr, diags diagnostics.Diag)

Decodes hclsyntax.Attribute into a cty.Value according to the given AttrSpec. No validation is performed on the value.

func (*Attr) GetInt

func (a *Attr) GetInt() (val int, diags diagnostics.Diag)

func (*Attr) GetStringList

func (a *Attr) GetStringList() (_ []string, diags diagnostics.Diag)

func (*Attr) Range

func (a *Attr) Range() hcl.Range

type AttrSpec

type AttrSpec struct {
	Name       string
	Type       cty.Type
	DefaultVal cty.Value
	ExampleVal cty.Value
	Doc        string

	Constraints constraint.Constraints
	// If set then value must be one of the specified values
	OneOf constraint.OneOf
	// For numbers - min value; for collections - min number of elements; for strings - min length
	MinInclusive cty.Value
	// For numbers - max value; for collections - max number of elements; for strings - max length
	MaxInclusive cty.Value
	// If specified – a deprecation warning would appear if an attribute is specified
	Deprecated string
	// If set then the value is hidden in logs
	Secret bool
}

func (*AttrSpec) DocComment

func (a *AttrSpec) DocComment() hclwrite.Tokens

func (*AttrSpec) ValidateSpec

func (a *AttrSpec) ValidateSpec() (diags diagnostics.Diag)

func (*AttrSpec) ValidateValue

func (a *AttrSpec) ValidateValue(val cty.Value) (diags diagnostics.Diag)

func (*AttrSpec) WriteDoc

func (a *AttrSpec) WriteDoc(w *hclwrite.Body)

type Attributes

type Attributes map[string]*Attr

type Block

type Block struct {
	// Type + labels
	Header       []string
	HeaderRanges []hcl.Range

	Attrs  Attributes
	Blocks Blocks

	// Full range of the block, between {} (inclusive)
	ContentsRange hcl.Range
}

func DecodeAndEvalBlock

func DecodeAndEvalBlock(ctx context.Context, block *hclsyntax.Block, rootSpec *RootSpec, dataCtx plugindata.Map) (res *Block, diags diagnostics.Diag)

Decodes hclsyntax.Block into a Block according to the given RootSpec. Deferred evaluation is performed immediatly.

func DecodeBlock

func DecodeBlock(ctx context.Context, block *hclsyntax.Block, rootSpec *RootSpec) (res *Block, diags diagnostics.Diag)

Decodes hclsyntax.Block into a Block according to the given RootSpec. Basic validation is performed on the keys, values of attributes are not fully defined until deferred evaluation, so they are not type-checked in the resulting block. This function's result is expected to be processed later with EvalBlock to resolve the deferred values and validate everything.

func EvalBlockCopy

func EvalBlockCopy(ctx context.Context, block *Block, dataCtx plugindata.Map) (evaluatedBlock *Block, diags diagnostics.Diag)

EvalBlockCopy evaluates deferred values in the given block and validates the attributes. The original block is not modified.

func NewBlock deprecated

func NewBlock(headers []string, attrs map[string]cty.Value, blocks ...*Block) *Block

Quickly create a new block without spec (no ranges will be assigned)

Deprecated: use plugintest.NewTestDecoder instead

func (*Block) DefRange

func (b *Block) DefRange() hcl.Range

func (*Block) GetAttrChecked

func (b *Block) GetAttrChecked(name string) (val *Attr, diags diagnostics.Diag)

func (*Block) GetAttrVal

func (b *Block) GetAttrVal(name string) cty.Value

Attempts to get attribute value, returns cty.NilVal if it's missing

func (*Block) HasAttr

func (b *Block) HasAttr(name string) bool

func (*Block) MissingItemRange

func (b *Block) MissingItemRange() hcl.Range

func (*Block) Range

func (b *Block) Range() hcl.Range

type BlockSpec

type BlockSpec struct {
	Header     HeadersSpec
	Required   bool
	Repeatable bool

	Doc string

	Blocks []*BlockSpec
	Attrs  []*AttrSpec

	AllowUnspecifiedBlocks     bool
	AllowUnspecifiedAttributes bool
}

func (*BlockSpec) ValidateSpec

func (b *BlockSpec) ValidateSpec() (errs diagnostics.Diag)

func (*BlockSpec) WriteBlockDoc

func (b *BlockSpec) WriteBlockDoc(w *hclwrite.Body)

func (*BlockSpec) WriteBodyDoc

func (b *BlockSpec) WriteBodyDoc(w *hclwrite.Body)

type Blocks

type Blocks []*Block

func (Blocks) GetFirstMatching

func (b Blocks) GetFirstMatching(header ...string) *Block

type ExactMatcher

type ExactMatcher []string

func (ExactMatcher) Match

func (m ExactMatcher) Match(ty string, labels []string) bool

type HeadersSpec

type HeadersSpec []NameMatcher

func (HeadersSpec) AsDocLabels

func (hs HeadersSpec) AsDocLabels() (name string, labels []string)

func (HeadersSpec) Match

func (hs HeadersSpec) Match(ty string, labels []string) bool

type NameMatcher

type NameMatcher interface {
	Match(ty string, labels []string) bool
}

type RootSpec

type RootSpec struct {
	Doc string

	Blocks []*BlockSpec
	Attrs  []*AttrSpec

	Required                   bool
	AllowUnspecifiedBlocks     bool
	AllowUnspecifiedAttributes bool
	// contains filtered or unexported fields
}

A subset of BlockSpec that represents the root block.

func RootSpecFromBlock

func RootSpecFromBlock(b *BlockSpec) *RootSpec

func (*RootSpec) BlockSpec

func (r *RootSpec) BlockSpec() *BlockSpec

func (*RootSpec) IsRequired

func (r *RootSpec) IsRequired() bool

func (*RootSpec) ValidateSpec

func (r *RootSpec) ValidateSpec() (errs diagnostics.Diag)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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