parse

package
v1.3.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2024 License: AGPL-3.0 Imports: 40 Imported by: 2

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:       schema.BlockTypeConnection,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypePlugin,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeOptions,
			LabelNames: []string{"type"},
		},
		{
			Type:       schema.BlockTypeWorkspaceProfile,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeCredential,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeCredentialImport,
			LabelNames: []string{schema.LabelName},
		},
		{
			Type:       schema.BlockTypeIntegration,
			LabelNames: []string{schema.LabelType, schema.LabelName},
		},
		{
			Type:       schema.BlockTypeNotifier,
			LabelNames: []string{schema.LabelName},
		},
	},
}

TODO: Flowpipe and Steampipe is sharing this config block schema .. but I don't think it should?

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{"type"},
		},
	},
}
View Source
var DashboardBlockSchema = &hcl.BodySchema{
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       schema.BlockTypeInput,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeParam,
			LabelNames: []string{"name"},
		},
		{
			Type: schema.BlockTypeWith,
		},
		{
			Type: schema.BlockTypeContainer,
		},
		{
			Type: schema.BlockTypeCard,
		},
		{
			Type: schema.BlockTypeChart,
		},
		{
			Type: schema.BlockTypeBenchmark,
		},
		{
			Type: schema.BlockTypeControl,
		},
		{
			Type: schema.BlockTypeFlow,
		},
		{
			Type: schema.BlockTypeGraph,
		},
		{
			Type: schema.BlockTypeHierarchy,
		},
		{
			Type: schema.BlockTypeImage,
		},
		{
			Type: schema.BlockTypeTable,
		},
		{
			Type: schema.BlockTypeText,
		},
	},
}

DashboardBlockSchema is only used to validate the blocks of a Dashboard

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

DashboardContainerBlockSchema is only used to validate the blocks of a DashboardContainer

View Source
var NodeAndEdgeProviderSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "args"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "param",
			LabelNames: []string{"name"},
		},
		{
			Type:       "category",
			LabelNames: []string{"name"},
		},
		{
			Type:       "with",
			LabelNames: []string{"name"},
		},
		{
			Type: schema.BlockTypeNode,
		},
		{
			Type: schema.BlockTypeEdge,
		},
	},
}

NodeAndEdgeProviderSchema is used to decode graph/hierarchy/flow (EXCEPT categories)

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{"name"},
		},
	},
}
View Source
var QueryProviderBlockSchema = &hcl.BodySchema{
	Attributes: []hcl.AttributeSchema{
		{Name: "args"},
	},
	Blocks: []hcl.BlockHeaderSchema{
		{
			Type:       "param",
			LabelNames: []string{"name"},
		},
		{
			Type:       "with",
			LabelNames: []string{"name"},
		},
	},
}

QueryProviderBlockSchema schema for all blocks satisfying QueryProvider interface NOTE: these are just the blocks/attributes that are explicitly decoded other query provider properties are implicitly decoded using tags

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(schema.BlockTypeMod),
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeVariable,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeQuery,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeControl,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeBenchmark,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeDashboard,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeCard,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeChart,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeFlow,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeGraph,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeHierarchy,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeImage,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeInput,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeTable,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeText,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeNode,
			LabelNames: []string{"name"},
		},
		{
			Type:       schema.BlockTypeEdge,
			LabelNames: []string{"name"},
		},
		{
			Type: schema.BlockTypeLocals,
		},
		{
			Type:       schema.BlockTypeCategory,
			LabelNames: []string{"name"},
		},

		{
			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{"type"},
		},
	},
}

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 added in v1.0.2

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

func DecodeConnection

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

func DecodeCredential

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

func DecodeCredentialImport added in v0.3.0

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

func DecodeIntegration added in v0.3.0

func DecodeIntegration(configPath string, block *hcl.Block) (modconfig.Integration, hcl.Diagnostics)

func DecodeNotifier added in v0.3.0

func DecodeNotifier(configPath string, block *hcl.Block, evalCtx *hcl.EvalContext) (*modconfig.NotifierImpl, hcl.Diagnostics)

func DecodeOptions

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

DecodeOptions decodes an options block

func DecodeRequire added in v1.3.0

func DecodeRequire(block *hcl.Block, evalCtx *hcl.EvalContext) (*modconfig.Require, hcl.Diagnostics)

func GetIntegrationBlockSchema

func GetIntegrationBlockSchema(integrationType string) *hcl.BodySchema

func GetMetadataForParsedResource

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

func GetPipelineStepBlockSchema

func GetPipelineStepBlockSchema(stepType string) *hcl.BodySchema

func GetTriggerBlockSchema

func GetTriggerBlockSchema(triggerType string) *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 modconfig.WorkspaceProfile](workspaceProfilePath string) (profileMap map[string]T, err error)

func ModFileExists added in v0.3.0

func ModFileExists(modPath string) (string, bool)

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

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(_ 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 ParseModRequireAndShortName added in v1.3.0

func ParseModRequireAndShortName(modFilePath string) (*modconfig.Require, string, hcl.Diagnostics)

ParseModRequireAndShortName is used when migrating the workspace lock It loads the require block from the mod file and returns the require object, as well as the mod short name The migration occurs the first time the workspace lock is loaded - this will be when we load the variables the migration is done by dimply installing the workspace dependencies At this point we have not yet loaded the full mod definition so the require block is not yet loaded - we need to manually load the reuire block, as well as the mod short name, which is used as a key in the workspace lock

func ParseQueryInvocation

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

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

1) positional args query.my_query("val1","val2")

2) named args query.my_query(my_arg1 => "test", my_arg2 => "test2")

func ResolveCredentialImportSource added in v0.3.0

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

func VariableValueCtyMap

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

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

Types

type DecodeResult

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

struct to hold the result of a decoding operation

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

type InstalledMod

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

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

	// PipelineHcls map[string]*modconfig.Pipeline
	TriggerHcls     map[string]*modconfig.Trigger
	IntegrationHcls map[string]modconfig.Integration

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

	// Credentials are something different, it's not part of the mod, it's not part of the workspace, it is at the same level
	// with mod and workspace. However it can be reference by the mod, so it needs to be in the parse context
	Credentials       map[string]credential.Credential
	CredentialImports map[string]credential.CredentialImport
	Integrations      map[string]modconfig.Integration
	Notifiers         map[string]modconfig.Notifier

	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

func NewModParseContext

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

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

func (m *ModParseContext) AddPipeline(pipelineHcl *modconfig.Pipeline) hcl.Diagnostics

TODO: transition period AddPipeline stores this resource as a variable to be added to the eval context. It alse

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

func (m *ModParseContext) AddTrigger(trigger *modconfig.Trigger) hcl.Diagnostics

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

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

func (*ModParseContext) GetResourceMaps

func (m *ModParseContext) GetResourceMaps() *modconfig.ResourceMaps

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 added in v1.0.0

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) SetBlockTypeExclusions added in v1.0.0

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

func (*ModParseContext) SetBlockTypes added in v1.0.0

func (m *ModParseContext) SetBlockTypes(blockTypes ...string)

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) 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 added in v0.3.0

type ModParseContextOption func(*ModParseContext)

func WithListOptions added in v0.3.0

func WithListOptions(listOptions filehelpers.ListOptions) ModParseContextOption

func WithParseFlags added in v0.3.0

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
	// contains filtered or unexported fields
}

func NewParseContext

func NewParseContext(rootEvalPath string) ParseContext

func (*ParseContext) AddDependencies

func (r *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 (r *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 (r *ParseContext) BuildEvalContext(variables map[string]cty.Value)

func (*ParseContext) ClearDependencies

func (r *ParseContext) ClearDependencies()

func (*ParseContext) EvalComplete

func (r *ParseContext) EvalComplete() bool

EvalComplete returns whether all elements in the dependency tree fully evaluated

func (*ParseContext) FormatDependencies

func (r *ParseContext) FormatDependencies() string

func (*ParseContext) SetDecodeContent

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

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 WorkspaceProfileParseContext

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

func NewWorkspaceProfileParseContext

func NewWorkspaceProfileParseContext[T modconfig.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