Documentation ¶
Index ¶
- Variables
- func AddReferences(resource modconfig.HclResource, block *hcl.Block, runCtx *RunContext) hcl.Diagnostics
- func ContextFunctions(workspaceDir string) map[string]function.Function
- func CtyToJSON(val cty.Value) (string, error)
- func DecodeConnection(block *hcl.Block) (*modconfig.Connection, hcl.Diagnostics)
- func DecodeOptions(block *hcl.Block) (options.Options, hcl.Diagnostics)
- func GetMetadataForParsedResource(resourceName string, srcRange hcl.Range, fileData map[string][]byte, ...) (*modconfig.ResourceMetadata, error)
- func LoadFileData(paths ...string) (map[string][]byte, hcl.Diagnostics)
- func ModfileExists(modPath string) bool
- func ParseHclFiles(fileData map[string][]byte) (hcl.Body, hcl.Diagnostics)
- func ParseMod(modPath string, fileData map[string][]byte, ...) (*modconfig.Mod, error)
- func ParseModDefinition(modPath string) (*modconfig.Mod, error)
- func ParseModResourceNames(fileData map[string][]byte) (*modconfig.WorkspaceResources, error)
- func ParsePreparedStatementInvocation(arg string) (string, *modconfig.QueryArgs, error)
- func VariableValueMap(variables map[string]*modconfig.Variable) map[string]cty.Value
- type InstalledMod
- type ParseModFlag
- type ReferenceTypeValueMap
- type RunContext
- func (r *RunContext) AddDependencies(block *hcl.Block, name string, dependencies []*dependency) hcl.Diagnostics
- func (r *RunContext) AddMod(mod *modconfig.Mod, content *hcl.BodyContent, fileData map[string][]byte) hcl.Diagnostics
- func (r *RunContext) AddResource(resource modconfig.HclResource) hcl.Diagnostics
- func (r *RunContext) AddVariables(inputVariables map[string]*modconfig.Variable)
- func (r *RunContext) BlocksToDecode() (hcl.Blocks, error)
- func (r *RunContext) ClearDependencies()
- func (r *RunContext) CreatePseudoResources() bool
- func (r *RunContext) EvalComplete() bool
- func (r *RunContext) FormatDependencies() string
- func (r *RunContext) ShouldCreateDefaultMod() bool
- func (r *RunContext) ShouldIncludeBlock(block *hcl.Block) bool
Constants ¶
This section is empty.
Variables ¶
var ConfigBlockSchema = &hcl.BodySchema{ Attributes: []hcl.AttributeSchema{}, Blocks: []hcl.BlockHeaderSchema{ { Type: "connection", LabelNames: []string{"name"}, }, { Type: "options", LabelNames: []string{"type"}, }, }, }
var ConnectionBlockSchema = &hcl.BodySchema{ Attributes: []hcl.AttributeSchema{ { Name: "plugin", Required: true, }, { Name: "type", }, { Name: "connections", }, }, Blocks: []hcl.BlockHeaderSchema{ { Type: "options", LabelNames: []string{"type"}, }, }, }
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"}, }, }, }
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
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"}, }, }, }
var ParamDefBlockSchema = &hcl.BodySchema{
Attributes: []hcl.AttributeSchema{
{Name: "description"},
{Name: "default"},
},
}
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"}, }, }, }
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, runCtx *RunContext) hcl.Diagnostics
AddReferences populates the 'References' resource field, used for the introspection tables
func ContextFunctions ¶
ContextFunctions returns the set of functions that should be used to when evaluating expressions
func DecodeConnection ¶ added in v0.9.0
func DecodeConnection(block *hcl.Block) (*modconfig.Connection, hcl.Diagnostics)
func DecodeOptions ¶ added in v0.9.0
DecodeOptions decodes an options block
func LoadFileData ¶
LoadFileData builds a map of filepath to file data
func ModfileExists ¶ added in v0.9.0
ModfileExists returns whether a mod file exists at the specified path
func ParseHclFiles ¶
ParseHclFiles parses hcl file data and returns the hcl body object
func ParseMod ¶
func ParseMod(modPath string, fileData map[string][]byte, pseudoResources []modconfig.MappableResource, runCtx *RunContext) (*modconfig.Mod, error)
ParseMod parses all source hcl files for the mod path and associated resources, and returns the mod object NOTE: the mod definition has already been parsed (or a default created) and is in opts.RunCtx.RootMod
func ParseModDefinition ¶ added in v0.9.0
ParseModDefinition parses the modfile only it is expected the callign code wil lhave verified the existence of the modfile by calling ModfileExists
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 ParsePreparedStatementInvocation ¶ added in v0.8.0
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 InstalledMod ¶ added in v0.9.0
type ParseModFlag ¶
type ParseModFlag uint32
const ( CreateDefaultMod ParseModFlag = 1 << iota CreatePseudoResources )
type ReferenceTypeValueMap ¶ added in v0.9.0
ReferenceTypeValueMap is the raw data used to build the evaluation context
When resolving hcl references like : - query.q1 - var.v1 - mod1.query.my_query.sql
ReferenceTypeValueMap is keyed by resource type, then by resource name
type RunContext ¶
type RunContext struct { // the mod which is currently being parsed CurrentMod *modconfig.Mod UnresolvedBlocks map[string]*unresolvedBlock FileData map[string][]byte // the eval context used to decode references in HCL EvalCtx *hcl.EvalContext Flags ParseModFlag ListOptions *filehelpers.ListOptions LoadedDependencyMods modconfig.ModMap WorkspacePath string ModInstallationPath string // if set, only decode these blocks BlockTypes []string // if set, exclude these block types BlockTypeExclusions []string Variables map[string]*modconfig.Variable // contains filtered or unexported fields }
func NewRunContext ¶
func NewRunContext(workspacePath string, flags ParseModFlag, listOptions *filehelpers.ListOptions) *RunContext
func (*RunContext) AddDependencies ¶
func (r *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) AddMod ¶ added in v0.9.0
func (r *RunContext) AddMod(mod *modconfig.Mod, content *hcl.BodyContent, fileData map[string][]byte) hcl.Diagnostics
AddMod is used to add a mod with any pseudo resources to the eval context - in practice this will be a shell mod with just pseudo resources - other resources will be added as they are parsed
func (*RunContext) AddResource ¶
func (r *RunContext) AddResource(resource modconfig.HclResource) hcl.Diagnostics
AddResource stores this resource as a variable to be added to the eval context. It alse
func (*RunContext) AddVariables ¶ added in v0.9.0
func (r *RunContext) AddVariables(inputVariables map[string]*modconfig.Variable)
AddVariables adds variables to the run context. We load and evaluate variables before loading the workspace
func (*RunContext) BlocksToDecode ¶
func (r *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 (r *RunContext) ClearDependencies()
func (*RunContext) CreatePseudoResources ¶ added in v0.9.0
func (r *RunContext) CreatePseudoResources() bool
CreatePseudoResources returns whether the flag is set to create pseudo resources
func (*RunContext) EvalComplete ¶
func (r *RunContext) EvalComplete() bool
EvalComplete returns whether all elements in the dependency tree fully evaluated
func (*RunContext) FormatDependencies ¶
func (r *RunContext) FormatDependencies() string
func (*RunContext) ShouldCreateDefaultMod ¶ added in v0.9.0
func (r *RunContext) ShouldCreateDefaultMod() bool
ShouldCreateDefaultMod returns whether the flag is set to create a default mod if no mod definition exists
func (*RunContext) ShouldIncludeBlock ¶ added in v0.9.0
func (r *RunContext) ShouldIncludeBlock(block *hcl.Block) bool