parse

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: AGPL-3.0 Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BenchmarkBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "children"},
		{Name: "description"},
		{Name: "documentation"},
		{Name: "tags"},
		{Name: "title"},

		{Name: "width"},
		{Name: "base"},
		{Name: "type"},
		{Name: "display"},
	},
}
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 DashboardBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "args"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       modconfig.BlockTypeInput,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeParam,
			LabelNames: []string{"name"},
		},
		{
			Type: modconfig.BlockTypeContainer,
		},
		{
			Type: modconfig.BlockTypeCard,
		},
		{
			Type: modconfig.BlockTypeChart,
		},
		{
			Type: modconfig.BlockTypeBenchmark,
		},
		{
			Type: modconfig.BlockTypeControl,
		},
		{
			Type: modconfig.BlockTypeFlow,
		},
		{
			Type: modconfig.BlockTypeHierarchy,
		},
		{
			Type: modconfig.BlockTypeImage,
		},
		{
			Type: modconfig.BlockTypeTable,
		},
		{
			Type: modconfig.BlockTypeText,
		},
	},
}

DashboardBlockSchema contains the Dashboard attributes which cannot be automatically decoded

View Source
var DashboardContainerBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "args"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       modconfig.BlockTypeInput,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeParam,
			LabelNames: []string{"name"},
		},
		{
			Type: modconfig.BlockTypeContainer,
		},
		{
			Type: modconfig.BlockTypeCard,
		},
		{
			Type: modconfig.BlockTypeChart,
		},
		{
			Type: modconfig.BlockTypeBenchmark,
		},
		{
			Type: modconfig.BlockTypeControl,
		},
		{
			Type: modconfig.BlockTypeFlow,
		},
		{
			Type: modconfig.BlockTypeHierarchy,
		},
		{
			Type: modconfig.BlockTypeImage,
		},
		{
			Type: modconfig.BlockTypeTable,
		},
		{
			Type: modconfig.BlockTypeText,
		},
	},
}

DashboardContainerBlockSchema contains the DashboardContainer attributes which cannot be automatically decoded

View Source
var ModBlockSchema = &hcl.BodySchema{
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type: modconfig.BlockTypeRequire,
		},
	},
}

schema for the mod blocks which must be manually decoded

View Source
var ParamDefBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "description"},
		{Name: "default"},
	},
}
View Source
var QueryProviderBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "args"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "param",
			LabelNames: []string{"name"},
		},
	},
}

QueryProviderBlockSchema schema for all blocks satisfying QueryProvider interface

View Source
var RequireBlockSchema = &hcl.BodySchema{
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       modconfig.BlockTypeMod,
			LabelNames: []string{"name"},
		},
	},
}
View Source
var RequireModBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "args"},
	},
}
View Source
var VariableBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{
			Name: "description",
		},
		{
			Name: "default",
		},
		{
			Name: "type",
		},
		{
			Name: "sensitive",
		},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type: "validation",
		},
	},
}
View Source
var WorkspaceBlockSchema = &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.BlockTypeDashboard,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeCard,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeChart,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeFlow,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeHierarchy,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeImage,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeInput,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeTable,
			LabelNames: []string{"name"},
		},
		{
			Type:       modconfig.BlockTypeText,
			LabelNames: []string{"name"},
		},
		{
			Type: modconfig.BlockTypeLocals,
		},
	},
}

WorkspaceBlockSchema is the top level schema for all workspace resources

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

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

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

func DecodeConnection

func DecodeConnection(block *hcl.Block) (*modconfig.Connection, hcl.Diagnostics)

func DecodeOptions

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

DecodeOptions decodes an options block

func GetMetadataForParsedResource

func GetMetadataForParsedResource(resourceName string, srcRange hcl.Range, 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 ModfileExists

func ModfileExists(modPath string) bool

ModfileExists returns whether a mod file exists at the specified path

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, 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

func ParseModDefinition(modPath string) (*modconfig.Mod, error)

ParseModDefinition parses the modfile only it is expected the calling code will have verified the existence of the modfile by calling ModfileExists this is called before parsing the workspace to, for example, identify dependency mods

func ParseModResourceNames

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

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')

func VariableValueMap

func VariableValueMap(variables map[string]*modconfig.Variable) map[string]cty.Value

VariableValueMap converts a map of variables to a map of the underlying cty value

Types

type InstalledMod

type InstalledMod struct {
	Mod     *modconfig.Mod
	Version *semver.Version
}

type ParseModFlag

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

type ReferenceTypeValueMap

type ReferenceTypeValueMap map[string]map[string]cty.Value
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
	// the workspace lock data
	WorkspaceLock    *versionmap.WorkspaceLock
	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
	RootEvalPath         string
	// if set, only decode these blocks
	BlockTypes []string
	// if set, exclude these block types
	BlockTypeExclusions []string

	// Variables is a map of the variables in the current mod
	// it is used to populate the variables property on the mod
	Variables map[string]*modconfig.Variable

	// DependencyVariables is a map of the variables in the dependency mods of the current mod
	// it is used to populate the variables property on the dependency
	DependencyVariables map[string]map[string]*modconfig.Variable
	ParentRunCtx        *RunContext
	// contains filtered or unexported fields
}

func NewRunContext

func NewRunContext(workspaceLock *versionmap.WorkspaceLock, rootEvalPath string, flags ParseModFlag, listOptions *filehelpers.ListOptions) *RunContext

func (*RunContext) AddDependencies

func (r *RunContext) AddDependencies(block *hcl.Block, name string, dependencies map[string]*modconfig.ResourceDependency) 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) AddInputVariables

func (r *RunContext) AddInputVariables(inputVariables *modconfig.ModVariableMap)

AddInputVariables adds variables to the run context. This function is called for the root run context after loading all input variables

func (*RunContext) AddLoadedDependentMods

func (r *RunContext) AddLoadedDependentMods(mods modconfig.ModMap)

func (*RunContext) AddMod

func (r *RunContext) AddMod(mod *modconfig.Mod) 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) 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

func (r *RunContext) CreatePseudoResources() bool

CreatePseudoResources returns whether the flag is set to create pseudo resources

func (*RunContext) DetermineBlockName

func (r *RunContext) DetermineBlockName(block *hcl.Block) string

func (*RunContext) EnsureWorkspaceLock

func (r *RunContext) EnsureWorkspaceLock(mod *modconfig.Mod) error

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) GetCachedBlockName

func (r *RunContext) GetCachedBlockName(block *hcl.Block) (string, bool)

func (*RunContext) GetCachedBlockShortName

func (r *RunContext) GetCachedBlockShortName(block *hcl.Block) (string, bool)

func (*RunContext) GetDecodedResourceForBlock

func (r *RunContext) GetDecodedResourceForBlock(block *hcl.Block) (modconfig.HclResource, bool)

func (*RunContext) GetMod

func (r *RunContext) GetMod(modShortName string) *modconfig.Mod

func (*RunContext) GetResourceMaps

func (r *RunContext) GetResourceMaps() *modconfig.ModResources

func (*RunContext) PeekParent

func (r *RunContext) PeekParent() string

func (*RunContext) PopParent

func (r *RunContext) PopParent() string

func (*RunContext) PushParent

func (r *RunContext) PushParent(parent modconfig.ModTreeItem)

func (*RunContext) SetDecodeContent

func (r *RunContext) SetDecodeContent(content *hcl.BodyContent, fileData map[string][]byte)

func (*RunContext) SetVariablesForDependencyMod

func (r *RunContext) SetVariablesForDependencyMod(mod *modconfig.Mod, dependencyVariablesMap map[string]map[string]*modconfig.Variable)

SetVariablesForDependencyMod adds variables to the run context. This function is called for dependent mod run context

func (*RunContext) ShouldCreateDefaultMod

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

func (r *RunContext) ShouldIncludeBlock(block *hcl.Block) bool

Jump to

Keyboard shortcuts

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