parse

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: AGPL-3.0 Imports: 51 Imported by: 1

Documentation

Index

Constants

View Source
const RootDependencyNode = "RootDependencyNode"

Variables

View Source
var AppSpecificGetResourceSchemaFunc func(resource modconfig.HclResource, bodySchema *hcl.BodySchema) *hcl.BodySchema
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 ConnectionBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{
			Name:     "plugin",
			Required: true,
		},
		{
			Name: "type",
		},
		{
			Name: "connections",
		},
		{
			Name: "import_schema",
		},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "options",
			LabelNames: []string{schema.LabelType},
		},
	},
}
View Source
var FlowpipeConfigBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{

			Type:       schema.BlockTypeConnection,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeOptions,
			LabelNames: []string{"type"},
		},
		{
			Type:       schema.BlockTypeWorkspaceProfile,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeCredential,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeCredentialImport,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeConnectionImport,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeIntegration,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeNotifier,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeOptions,
			LabelNames: []string{"type"},
		},
	},
}

FlowpipeConfigBlockSchema defines the config schema for Flowpipe config blocks. The connection block setup is different, Steampipe only has one label while Pipelingconnections has 2 labels. Credential, CredentialImport, Integration and Notifer are specific to Flowpipe

View Source
var ModDecoderFunc func(...DecoderOption) Decoder

ModDecoderFunc is the appspecific constructor function used to construct a decoder which knows how to decode resources for the app in question

View Source
var ParamDefBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "description"},
		{Name: "default"},
	},
}
View Source
var PluginBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       schema.BlockTypeRateLimiter,
			LabelNames: []string{schema.LabelName},
		},
	},
}
View Source
var PowerpipeConfigBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{

			Type:       schema.BlockTypeConnection,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeWorkspaceProfile,
			LabelNames: []string{"name"},
		},
	},
}

PowerpipeConfigBlockSchema defines the config schema for Flowpipe config blocks. The connection block setup is different, Steampipe only has one label while Pipelingconnections has 2 labels. Credential, CredentialImport, Integration and Notifer are specific to Flowpipe

View Source
var ResourceSchemaCache = make(map[string]*hcl.BodySchema)

cache resource schemas

View Source
var SteampipeConfigBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       schema.BlockTypeConnection,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypePlugin,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeOptions,
			LabelNames: []string{"type"},
		},
		{
			Type:       schema.BlockTypeWorkspaceProfile,
			LabelNames: []string{schema.LabelName},
		},
	},
}
View Source
var TailpipeConfigBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{

			Type:       schema.BlockTypeConnection,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeWorkspaceProfile,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypePartition,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypePlugin,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeTable,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeFormat,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
	},
}
View Source
var VariableBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{
			Name: schema.AttributeTypeTitle,
		},
		{
			Name: schema.AttributeTypeDescription,
		},
		{
			Name: schema.AttributeTypeDefault,
		},
		{
			Name: schema.AttributeTypeType,
		},
		{
			Name: schema.AttributeTypeSensitive,
		},
		{
			Name: schema.AttributeTypeTags,
		},
		{
			Name: schema.AttributeTypeEnum,
		},
		{
			Name: schema.AttributeTypeFormat,
		},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type: "validation",
		},
	},
}
View Source
var WorkspaceBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       string(schema.BlockTypeMod),
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeVariable,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeQuery,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeControl,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeDetection,
			LabelNames: []string{schema.LabelName},
		},

		{
			Type:       schema.BlockTypeBenchmark,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeDashboard,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeCard,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeChart,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeFlow,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeGraph,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeHierarchy,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeImage,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeInput,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeTable,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeText,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeNode,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeEdge,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type: schema.BlockTypeLocals,
		},
		{
			Type:       schema.BlockTypeCategory,
			LabelNames: []string{schema.LabelName},
		},

		{
			Type:       schema.BlockTypePipeline,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeTrigger,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeIntegration,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
	},
}

WorkspaceBlockSchema is the top level schema for all workspace resources

View Source
var WorkspaceProfileBlockSchema = &hcl.BodySchema{

	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "options",
			LabelNames: []string{schema.LabelType},
		},
	},
}

Functions

func AddReferences

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

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

func AddResourceMetadata

func AddResourceMetadata(resourceWithMetadata modconfig.ResourceWithMetadata, srcRange hcl.Range, parseCtx *ModParseContext) hcl.Diagnostics

func AddResourceToMod

func AddResourceToMod(resource modconfig.HclResource, block *hcl.Block, decoder Decoder, parseCtx *ModParseContext) hcl.Diagnostics

func BuildTemporaryConnectionMapForEvalContext

func BuildTemporaryConnectionMapForEvalContext(allConnections map[string]connection.PipelingConnection) map[string]cty.Value

**WARNING** this function has a specific use case do not use

The key word is "temporary"

func ConnectionNameFromTemporaryConnectionMap

func ConnectionNameFromTemporaryConnectionMap(valueMap map[string]cty.Value) (string, bool)

func ConnectionNamesValueFromCtyValue

func ConnectionNamesValueFromCtyValue(v cty.Value) (cty.Value, bool)

ConnectionNamesValueFromCtyValue takes the cty value of a variable, and if the variable contains one or more temporary connections, it builds a list of the connection names and returns as a cty value

func DecodeConnection

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

func DecodeConnectionImport

func DecodeConnectionImport(configPath string, block *hcl.Block) (*modconfig.ConnectionImport, hcl.Diagnostics)

func DecodeCredential

func DecodeCredential(configPath string, block *hcl.Block) (credential.Credential, hcl.Diagnostics)

func DecodeCredentialImport

func DecodeCredentialImport(configPath string, block *hcl.Block) (*credential.CredentialImport, hcl.Diagnostics)

func DecodeHclBody

func DecodeHclBody(body hcl.Body, evalCtx *hcl.EvalContext, resourceProvider modconfig.ResourceProvider, resource modconfig.HclResource) (diags hcl.Diagnostics)

func DecodeLimiter

func DecodeLimiter(block *hcl.Block) (*plugin.RateLimiter, hcl.Diagnostics)

func DecodeOptions

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

DecodeOptions decodes an options block

func DecodePipelingConnection

func DecodePipelingConnection(configPath string, block *hcl.Block) (connection.PipelingConnection, hcl.Diagnostics)

func DecodeProperty

func DecodeProperty(content *hcl.BodyContent, property string, dest interface{}, evalCtx *hcl.EvalContext) hcl.Diagnostics

func DecodeTypeExpression

func DecodeTypeExpression(attr *hcl.Attribute) (cty.Type, hcl.Diagnostics)

func DecodeVarFormat

func DecodeVarFormat(ty cty.Type, attr *hcl.Attribute, parseCtx *ModParseContext) (string, hcl.Diagnostics)

func DecodeVariableBlock

func DecodeVariableBlock(block *hcl.Block, content *hcl.BodyContent, parseCtx *ModParseContext) (*modconfig.RawVariable, hcl.Diagnostics)

func DefaultWorkspaceSampleFileName

func DefaultWorkspaceSampleFileName() string

func DiagsToDependency

func DiagsToDependency(diag *hcl.Diagnostic) *modconfig.ResourceDependency

DiagsToDependency determines whether the diag is a dependency error, and if so, return a dependency object

func EscapeTemplateTokens

func EscapeTemplateTokens(fileData []byte, filePath string, disableTemplateForProperties []string) ([]byte, hcl.Diagnostics)

EscapeTemplateTokens escapes template expressions in any properties specified by disableTemplateForProperties

func ExtractExpressionString

func ExtractExpressionString(expr hcl.Expression, src []byte) string

func GetChildNameStringsFromModTreeItem

func GetChildNameStringsFromModTreeItem(children []modconfig.ModTreeItem) []string

func GetMetadataForParsedResource

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

func GetNestedStructVals

func GetNestedStructVals(val any) (_ []any, diags hcl.Diagnostics)

GetNestedStructVals return a slice of any nested structs within val

func GetNestedStructValsRecursive

func GetNestedStructValsRecursive(val any) ([]any, hcl.Diagnostics)

func GetSchemaForStruct

func GetSchemaForStruct(t reflect.Type) *hcl.BodySchema

func LoadFileData

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

LoadFileData builds a map of filepath to file data

func LoadModfile

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

func LoadWorkspaceProfiles

func LoadWorkspaceProfiles[T workspace_profile.WorkspaceProfile](workspaceProfilePath string, opts ...ParseHclOpt) (profileMap map[string]T, err error)

func ModFileExists

func ModFileExists(modPath string) (string, bool)

ModFileExists returns whether a mod file exists at the specified path and if so returns the filepath

func ParseConfig

func ParseConfig(configString []byte, filename string, startPos hcl.Pos) (hcl.Body, hcl.Diagnostics)

func ParseHclFiles

func ParseHclFiles(fileDataMap map[string][]byte, opts ...ParseHclOpt) (hcl.Body, hcl.Diagnostics)

ParseHclFiles parses hcl, json or yaml file data and returns the hcl body object

func ParseJsonConfig

func ParseJsonConfig(configString []byte, filename string) (hcl.Body, hcl.Diagnostics)

func ParseMod

func ParseMod(_ context.Context, fileData map[string][]byte, parseCtx *ModParseContext) (*modconfig.Mod, error_helpers.ErrorAndWarnings)

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 ParseTime

func ParseTime(input string, now time.Time) (time.Time, error)

ParseTime parses a time string into a time.Time object.

func ResolveChildrenFromNames

func ResolveChildrenFromNames(childNames []string, block *hcl.Block, supportedChildren []string, parseCtx *ModParseContext) ([]modconfig.ModTreeItem, hcl.Diagnostics)

func ResolveConnectionImportSource

func ResolveConnectionImportSource(source *string) ([]string, error)

func ResolveConnectionString

func ResolveConnectionString(content *hcl.BodyContent, evalCtx *hcl.EvalContext) (csp connection.ConnectionStringProvider, searchPath, searchPathPrefix []string, diags hcl.Diagnostics)

func ResolveCredentialImportSource

func ResolveCredentialImportSource(source *string) ([]string, error)

func ValidateName

func ValidateName(block *hcl.Block) hcl.Diagnostics

func VariableValueCtyMap

func VariableValueCtyMap(variables map[string]*modconfig.Variable, supportLateBinding bool) (ret, lateBindingVars, lateBindingVarDeps map[string]cty.Value)

VariableValueCtyMap converts a map of variables to a map of the underlying cty value Note: if the variable type is a late binding type (i.e. PipelingConnection), DO NOT add to map

Types

type DecodeFunc

type DecodeFunc func(*hcl.Block, *ModParseContext) (modconfig.HclResource, *DecodeResult)

type DecodeResult

type DecodeResult struct {
	Diags   hcl.Diagnostics
	Depends map[string]*modconfig.ResourceDependency
}

DecodeResult holds the result of a decoding operation - diags and resource dependencies

func NewDecodeResult

func NewDecodeResult() *DecodeResult

func ParseModDefinition

func ParseModDefinition(modFilePath string, evalCtx *hcl.EvalContext) (*modconfig.Mod, *DecodeResult)

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

This function only parse the "mod" block, and does not parse any resources in the mod file

func (*DecodeResult) AddDiags

func (p *DecodeResult) AddDiags(diags hcl.Diagnostics)

func (*DecodeResult) HandleDecodeDiags

func (p *DecodeResult) HandleDecodeDiags(diags hcl.Diagnostics)

HandleDecodeDiags adds dependencies to the result if the diags contains dependency errors, otherwise adds diags to the result

func (*DecodeResult) Merge

func (p *DecodeResult) Merge(other *DecodeResult) *DecodeResult

Merge merges this decode result with another

func (*DecodeResult) Success

func (p *DecodeResult) Success() bool

Success returns if the was parsing successful - true if there are no errors and no dependencies

func (*DecodeResult) VariableDependenciesToWarnings

func (p *DecodeResult) VariableDependenciesToWarnings() []string

type Decoder

type Decoder interface {
	Decode(*ModParseContext) hcl.Diagnostics
	ShouldAddToMod(modconfig.HclResource, *hcl.Block, *ModParseContext) bool
}

type DecoderImpl

type DecoderImpl struct {
	// registered block types
	DecodeFuncs map[string]DecodeFunc
	// optional default decode function
	DefaultDecodeFunc DecodeFunc
	// optional resource validation func
	ValidateFunc func(resource modconfig.HclResource) hcl.Diagnostics
}

func NewDecoderImpl

func NewDecoderImpl() DecoderImpl

func (*DecoderImpl) Decode

func (d *DecoderImpl) Decode(parseCtx *ModParseContext) hcl.Diagnostics

func (*DecoderImpl) DecodeBlock

func (d *DecoderImpl) DecodeBlock(block *hcl.Block, parseCtx *ModParseContext) (modconfig.HclResource, *DecodeResult)

func (*DecoderImpl) HandleModDecodeResult

func (d *DecoderImpl) HandleModDecodeResult(resource modconfig.HclResource, res *DecodeResult, block *hcl.Block, parseCtx *ModParseContext)

HandleModDecodeResult if decode was successful: - generate and set resource metadata - add resource to ModParseContext (which adds it to the mod)HandleModDecodeResult

func (*DecoderImpl) ShouldAddToMod

func (d *DecoderImpl) ShouldAddToMod(resource modconfig.HclResource, block *hcl.Block, parseCtx *ModParseContext) bool

ShouldAddToMod determines whether the resource should be added to the mod this may be overridden by the app specific decoder to add app-specific resource logic

type DecoderOption

type DecoderOption func(Decoder)

type ModDependencyConfig

type ModDependencyConfig struct {
	ModDependency  *versionmap.ResolvedVersionConstraint
	DependencyPath *string
}

func NewDependencyConfig

func NewDependencyConfig(modDependency *versionmap.ResolvedVersionConstraint) *ModDependencyConfig

func (ModDependencyConfig) SetModProperties

func (c ModDependencyConfig) SetModProperties(mod *modconfig.Mod)

type ModParseContext

type ModParseContext struct {
	ParseContext

	// the mod which is currently being parsed
	CurrentMod *modconfig.Mod
	// the workspace lock data
	WorkspaceLock *versionmap.WorkspaceLock

	Flags       ParseModFlag
	ListOptions filehelpers.ListOptions

	// Variables is a tree of maps of the variables in the current mod and child dependency mods
	Variables *modconfig.ModVariableMap

	PipelingConnections map[string]connection.PipelingConnection

	ParentParseCtx *ModParseContext

	// if we are loading dependency mod, this contains the details
	DependencyConfig *ModDependencyConfig
	// contains filtered or unexported fields
}

func NewChildModParseContext

func NewChildModParseContext(parent *ModParseContext, modVersion *versionmap.ResolvedVersionConstraint, rootEvalPath string) (*ModParseContext, error)

func NewModParseContext

func NewModParseContext(workspaceLock *versionmap.WorkspaceLock, rootEvalPath string, opts ...ModParseContextOption) (*ModParseContext, error)

func (*ModParseContext) AddDependencies

func (m *ModParseContext) 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 (*ModParseContext) AddInputVariableValues

func (m *ModParseContext) AddInputVariableValues(inputVariables *modconfig.ModVariableMap)

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

func (*ModParseContext) AddLoadedDependencyMod

func (m *ModParseContext) AddLoadedDependencyMod(mod *modconfig.Mod)

func (*ModParseContext) AddModResources

func (m *ModParseContext) AddModResources(mod *modconfig.Mod) hcl.Diagnostics

AddModResources is used to add mod resources to the eval context

func (*ModParseContext) AddResource

func (m *ModParseContext) AddResource(resource modconfig.HclResource) hcl.Diagnostics

AddResource stores this resource as a variable to be added to the eval context.

func (*ModParseContext) AddVariablesToEvalContext

func (m *ModParseContext) AddVariablesToEvalContext()

func (*ModParseContext) DetermineBlockName

func (m *ModParseContext) DetermineBlockName(block *hcl.Block) string

DetermineBlockName determines if the block is anonymous, and if so, returns a unique name for the block, based on its type and parent

func (*ModParseContext) EnsureWorkspaceLock

func (m *ModParseContext) EnsureWorkspaceLock(mod *modconfig.Mod) error

func (*ModParseContext) GetCachedBlockName

func (m *ModParseContext) GetCachedBlockName(block *hcl.Block) (string, bool)

func (*ModParseContext) GetCachedBlockShortName

func (m *ModParseContext) GetCachedBlockShortName(block *hcl.Block) (string, bool)

func (*ModParseContext) GetDecodedResourceForBlock

func (m *ModParseContext) GetDecodedResourceForBlock(block *hcl.Block) (modconfig.HclResource, bool)

func (*ModParseContext) GetMod

func (m *ModParseContext) GetMod(modShortName string) *modconfig.Mod

GetMod finds the mod with given short name, looking only in first level dependencies this is used to resolve resource references specifically when the 'children' property of dashboards and benchmarks refers to resource in a dependency mod

func (*ModParseContext) GetModResources

func (m *ModParseContext) GetModResources() modconfig.ModResources

func (*ModParseContext) GetResource

func (m *ModParseContext) GetResource(parsedName *modconfig.ParsedResourceName) (resource modconfig.HclResource, found bool)

func (*ModParseContext) GetTopLevelDependencyMods

func (m *ModParseContext) GetTopLevelDependencyMods() modconfig.ModMap

GetTopLevelDependencyMods build a mod map of top level loaded dependencies, keyed by mod name

func (*ModParseContext) IsTopLevelBlock

func (m *ModParseContext) IsTopLevelBlock(block *hcl.Block) bool

func (*ModParseContext) LoadVariablesOnly

func (m *ModParseContext) LoadVariablesOnly() bool

LoadVariablesOnly returns whether we are ONLY loading variables

func (*ModParseContext) PeekParent

func (m *ModParseContext) PeekParent() string

func (*ModParseContext) PopParent

func (m *ModParseContext) PopParent() string

func (*ModParseContext) PushParent

func (m *ModParseContext) PushParent(parent modconfig.ModTreeItem)

func (*ModParseContext) RebuildEvalContext

func (m *ModParseContext) RebuildEvalContext()

RebuildEvalContext the eval context from the cached reference values

func (*ModParseContext) SetCurrentMod

func (m *ModParseContext) SetCurrentMod(mod *modconfig.Mod) error

func (*ModParseContext) SetDecodeContent

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

func (*ModParseContext) SetIncludeLateBindingResources

func (m *ModParseContext) SetIncludeLateBindingResources(include bool)

SetIncludeLateBindingResources sets whether connections be included in the eval context and rebuilds the eval context

func (*ModParseContext) ShouldCreateDefaultMod

func (m *ModParseContext) ShouldCreateDefaultMod() bool

ShouldCreateDefaultMod returns whether the flag is set to create a default mod if no mod definition exists

type ModParseContextOption

type ModParseContextOption func(*ModParseContext)

func WithConfigValueMap

func WithConfigValueMap(valueMaps map[string]map[string]cty.Value) ModParseContextOption

func WithConnections

func WithConnections(connections map[string]connection.PipelingConnection) ModParseContextOption

func WithDecoderOptions

func WithDecoderOptions(decoderOptions ...DecoderOption) ModParseContextOption

func WithLateBinding

func WithLateBinding(enabled bool) ModParseContextOption

func WithListOptions

func WithListOptions(listOptions filehelpers.ListOptions) ModParseContextOption

func WithParseFlags

func WithParseFlags(flags ParseModFlag) ModParseContextOption

type ParseContext

type ParseContext struct {
	UnresolvedBlocks map[string]*UnresolvedBlock
	FileData         map[string][]byte

	// the eval context used to decode references in HCL
	EvalCtx *hcl.EvalContext

	Diags hcl.Diagnostics

	RootEvalPath string

	DependencyGraph *topsort.Graph

	// function used to parse resource property path
	ResourceNameFromDependencyFunc func(propertyPath string) (string, error)
	// contains filtered or unexported fields
}

func NewParseContext

func NewParseContext(rootEvalPath string) ParseContext

func (*ParseContext) AddDependencies

func (p *ParseContext) AddDependencies(block *hcl.Block, name string, dependencies map[string]*modconfig.ResourceDependency) hcl.Diagnostics

AddDependencies is called when a block could not be resolved as it has dependencies 1) store block as unresolved 2) add dependencies to our tree of dependencies

func (*ParseContext) BlocksToDecode

func (p *ParseContext) BlocksToDecode() (blocksToDecode hcl.Blocks, _ error)

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

func (*ParseContext) BuildEvalContext

func (p *ParseContext) BuildEvalContext(variables map[string]cty.Value)

func (*ParseContext) ClearDependencies

func (p *ParseContext) ClearDependencies()

func (*ParseContext) EvalComplete

func (p *ParseContext) EvalComplete() bool

EvalComplete returns whether all elements in the dependency tree fully evaluated

func (*ParseContext) FormatDependencies

func (p *ParseContext) FormatDependencies() string

func (*ParseContext) GetResourceCtyValue

func (m *ParseContext) GetResourceCtyValue(resource modconfig.HclResource) (cty.Value, hcl.Diagnostics)

GetResourceCtyValue converts a HclResource into a cty value, taking into account nested structs

func (*ParseContext) SetBlockTypeExclusions

func (m *ParseContext) SetBlockTypeExclusions(blockTypes ...string)

func (*ParseContext) SetBlockTypes

func (p *ParseContext) SetBlockTypes(blockTypes ...string)

func (*ParseContext) SetDecodeContent

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

type ParseHclConfig

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

type ParseHclOpt

type ParseHclOpt func(*ParseHclConfig)

func WithDisableTemplateForProperties

func WithDisableTemplateForProperties(properties []string) ParseHclOpt

WithDisableTemplateForProperties is an option to specify the properties for which hcl template expression parsing should be disabled this is used for preprties which will include a grok path which include the template opening chars '%{' if we do not escape the '%{' for these properties, they will fail ot parse

type ParseModFlag

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

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 UnresolvedBlock

type UnresolvedBlock struct {
	Name         string
	Block        *hcl.Block
	DeclRange    hcl.Range
	Dependencies map[string]*modconfig.ResourceDependency
}

func NewUnresolvedBlock

func NewUnresolvedBlock(block *hcl.Block, name string, dependencies map[string]*modconfig.ResourceDependency) *UnresolvedBlock

func (UnresolvedBlock) String

func (b UnresolvedBlock) String() string

type WorkspaceProfileLoader

type WorkspaceProfileLoader[T workspace_profile.WorkspaceProfile] struct {
	DefaultProfile    T
	ConfiguredProfile T
	ParseOpts         []ParseHclOpt
	// contains filtered or unexported fields
}

func NewWorkspaceProfileLoader

func NewWorkspaceProfileLoader[T workspace_profile.WorkspaceProfile](workspaceProfilePaths ...string) (*WorkspaceProfileLoader[T], error)

func (*WorkspaceProfileLoader[T]) GetActiveWorkspaceProfile

func (l *WorkspaceProfileLoader[T]) GetActiveWorkspaceProfile() T

func (*WorkspaceProfileLoader[T]) Load

func (l *WorkspaceProfileLoader[T]) Load() error

type WorkspaceProfileParseContext

type WorkspaceProfileParseContext[T workspace_profile.WorkspaceProfile] struct {
	ParseContext
	// contains filtered or unexported fields
}

func NewWorkspaceProfileParseContext

func NewWorkspaceProfileParseContext[T workspace_profile.WorkspaceProfile](rootEvalPath string) *WorkspaceProfileParseContext[T]

func (*WorkspaceProfileParseContext[T]) AddResource

func (c *WorkspaceProfileParseContext[T]) AddResource(workspaceProfile T) hcl.Diagnostics

AddResource stores this resource as a variable to be added to the eval context. It alse

Jump to

Keyboard shortcuts

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