Validate that input references are of the form self.input.<input-name>.value. Closes #2990

This commit is contained in:
kaidaguerre
2023-01-16 12:30:34 +00:00
committed by GitHub
parent 2080bc1bd5
commit 076b5c1957
4 changed files with 30 additions and 8 deletions

View File

@@ -12,7 +12,7 @@ import (
)
const rootRuntimeDependencyNode = "rootRuntimeDependencyNode"
const runtimeDependencyDashboardScope = "self"
const RuntimeDependencyDashboardScope = "self"
// Dashboard is a struct representing the Dashboard resource
type Dashboard struct {

View File

@@ -10,7 +10,7 @@ type ParsedPropertyPath struct {
ItemType string
Name string
PropertyPath []string
// optional scope of this property path ("root or parent")
// optional scope of this property path ("self")
Scope string
Original string
}
@@ -49,7 +49,7 @@ func ParseResourcePropertyPath(propertyPath string) (*ParsedPropertyPath, error)
}
// special case handling for runtime dependencies which may have use the "self" qualifier
if parts[0] == runtimeDependencyDashboardScope {
if parts[0] == RuntimeDependencyDashboardScope {
res.Scope = parts[0]
parts = parts[1:]
}

View File

@@ -183,6 +183,12 @@ func getRuntimeDepFromExpression(expr hcl.Expression, targetProperty, parentProp
return nil, err
}
if propertyPath.ItemType == modconfig.BlockTypeInput {
// tactical: validate input dependency
if err := validateInputRuntimeDependency(propertyPath); err != nil {
return nil, err
}
}
ret := &modconfig.RuntimeDependency{
PropertyPath: propertyPath,
ParentPropertyName: parentProperty,
@@ -248,6 +254,12 @@ func identifyRuntimeDependenciesFromArray(attr *hcl.Attribute, idx int, parentPr
if err != nil {
return nil, err
}
// tactical: validate input dependency
if propertyPath.ItemType == modconfig.BlockTypeInput {
if err := validateInputRuntimeDependency(propertyPath); err != nil {
return nil, err
}
}
ret := &modconfig.RuntimeDependency{
PropertyPath: propertyPath,
ParentPropertyName: parentProperty,
@@ -261,6 +273,18 @@ func identifyRuntimeDependenciesFromArray(attr *hcl.Attribute, idx int, parentPr
return nil, fmt.Errorf("could not extract runtime dependency for arg %d - not found in attribute list", idx)
}
// tactical - if runtime dependency is an input, validate it is of correct format
// TODO - include this with the main runtime dependency validaiton, when it is rewritten https://github.com/turbot/steampipe/issues/2925
func validateInputRuntimeDependency(propertyPath *modconfig.ParsedPropertyPath) error {
// input references must be of form self.input.<input_name>.value
if propertyPath.Scope != modconfig.RuntimeDependencyDashboardScope ||
len(propertyPath.PropertyPath) != 1 ||
propertyPath.PropertyPath[0] != "value" {
return fmt.Errorf("could not resolve runtime dependency resource %s", propertyPath.Original)
}
return nil
}
func decodeParam(block *hcl.Block, parseCtx *ModParseContext) (*modconfig.ParamDef, []*modconfig.RuntimeDependency, hcl.Diagnostics) {
def := modconfig.NewParamDef(block)
var runtimeDependencies []*modconfig.RuntimeDependency

View File

@@ -13,12 +13,10 @@ dashboard "inputs" {
}
table {
param "foo" {}
sql = "select $1"
args = {
arn = self.input.i1.value
}
args =[self.input.i1.value]
}
table {
query = query.q1
args = {
@@ -31,5 +29,5 @@ dashboard "inputs" {
query "q1"{
sql = "select arn from aws_account where arn = $1"
param "arn" { }
search_path="test"
}