parse

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: AGPL-3.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "connection",
			LabelNames: []string{"name"},
		},
		{
			Type:       "options",
			LabelNames: []string{"type"},
		},
	},
}
View Source
var ConnectionBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{
			Name:     "plugin",
			Required: true,
		},
		{
			Name: "type",
		},
		{
			Name: "connections",
		},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "options",
			LabelNames: []string{"type"},
		},
	},
}
View Source
var ControlBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "description"},
		{Name: "documentation"},
		{Name: "search_path"},
		{Name: "search_path_prefix"},
		{Name: "severity"},
		{Name: "sql"},
		{Name: "query"},
		{Name: "tags"},
		{Name: "title"},
		{Name: "args"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "param",
			LabelNames: []string{"name"},
		},
	},
}
View Source
var ModBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       string(modconfig.BlockTypeMod),
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeVariable,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeQuery,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeControl,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeBenchmark,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeReport,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypePanel,
			LabelNames: []string{"name"},
		},
		{
			Type: modconfig.BlockTypeLocals,
		},
	},
}

ModBlockSchema :: top level schema for all mod resources

View Source
var PanelBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "title"},
		{Name: "text"},
		{Name: "type"},
		{Name: "width"},
		{Name: "height"},
		{Name: "source"},
		{Name: "sql"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "panel",
			LabelNames: []string{"name"},
		},
		{
			Type:       "report",
			LabelNames: []string{"type"},
		},
	},
}
View Source
var ParamDefBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "description"},
		{Name: "default"},
	},
}
View Source
var QueryBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "description"},
		{Name: "documentation"},
		{Name: "search_path"},
		{Name: "search_path_prefix"},
		{Name: "sql"},
		{Name: "tags"},
		{Name: "title"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "param",
			LabelNames: []string{"name"},
		},
	},
}
View Source
var ReportBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "title"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "panel",
			LabelNames: []string{"name"},
		},
		{
			Type:       "report",
			LabelNames: []string{"type"},
		},
	},
}

Functions

func AddReferences

func AddReferences(resource modconfig.HclResource, block *hcl.Block)

AddReferences populates the 'References' resource field, used for the metadata tables

func ContextFunctions

func ContextFunctions(workspaceDir string) map[string]function.Function

ContextFunctions :: returns the set of functions that should be used to when evaluating expressions

func GetMetadataForParsedResource

func GetMetadataForParsedResource(resourceName string, block *hcl.Block, fileData map[string][]byte, mod *modconfig.Mod) (*modconfig.ResourceMetadata, error)

func LoadFileData

func LoadFileData(paths ...string) (map[string][]byte, hcl.Diagnostics)

LoadFileData builds a map of filepath to file data

func ParseConnection

func ParseConnection(block *hcl.Block, fileData map[string][]byte) (*modconfig.Connection, hcl.Diagnostics)

func ParseHclFiles

func ParseHclFiles(fileData map[string][]byte) (hcl.Body, hcl.Diagnostics)

ParseHclFiles parses hcl file data and returns the hcl body object

func ParseMod

func ParseMod(modPath string, fileData map[string][]byte, pseudoResources []modconfig.MappableResource, opts *ParseModOptions) (*modconfig.Mod, error)

ParseMod parses all source hcl files for the mod path and associated resources, and returns the mod object

func ParseModResourceNames added in v0.8.0

func ParseModResourceNames(fileData map[string][]byte) (*modconfig.WorkspaceResources, error)

ParseModResourceNames parses all source hcl files for the mod path and associated resources, and returns the resource names

func ParseOptions

func ParseOptions(block *hcl.Block) (options.Options, hcl.Diagnostics)

func ParsePreparedStatementInvocation added in v0.8.0

func ParsePreparedStatementInvocation(arg string) (string, *modconfig.QueryArgs, error)

ParsePreparedStatementInvocation parses a query invocation and extracts the args (if any) supported formats are:

1) positional args query.my_prepared_statement('val1','val1')

2) named args query.my_prepared_statement(my_arg1 => 'test', my_arg2 => 'test2')

Types

type ParseModFlag

type ParseModFlag uint32
const (
	CreateDefaultMod ParseModFlag = 1 << iota
	CreatePseudoResources
)

type ParseModOptions

type ParseModOptions struct {
	Flags       ParseModFlag
	ListOptions *filehelpers.ListOptions
	Variables   map[string]cty.Value
	// if set, only decode these blocks
	BlockTypes []string
}

func (*ParseModOptions) CreateDefaultMod

func (o *ParseModOptions) CreateDefaultMod() bool

func (*ParseModOptions) CreatePseudoResources

func (o *ParseModOptions) CreatePseudoResources() bool

type RunContext

type RunContext struct {
	Mod              *modconfig.Mod
	UnresolvedBlocks map[string]*unresolvedBlock
	FileData         map[string][]byte

	EvalCtx *hcl.EvalContext
	// contains filtered or unexported fields
}

func NewRunContext

func NewRunContext(mod *modconfig.Mod, content *hcl.BodyContent, fileData map[string][]byte, inputVariables map[string]cty.Value) (*RunContext, hcl.Diagnostics)

func (*RunContext) AddDependencies

func (c *RunContext) AddDependencies(block *hcl.Block, name string, dependencies []*dependency) hcl.Diagnostics

AddDependencies :: the block could not be resolved as it has dependencies 1) store block as unresolved 2) add dependencies to our tree of dependencies

func (*RunContext) AddResource

func (c *RunContext) AddResource(resource modconfig.HclResource, block *hcl.Block) hcl.Diagnostics

AddResource :: store this resource as a variable to be added to the eval context

func (*RunContext) BlocksToDecode

func (c *RunContext) BlocksToDecode() (hcl.Blocks, error)

BlocksToDecode builds a list of blocks to decode, the order of which is determined by the depdnency order

func (*RunContext) ClearDependencies

func (c *RunContext) ClearDependencies()

func (*RunContext) EvalComplete

func (c *RunContext) EvalComplete() bool

EvalComplete :: Are all elements in the dependency tree fully evaluated

func (*RunContext) FormatDependencies

func (c *RunContext) FormatDependencies() string

Jump to

Keyboard shortcuts

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