Skip to content

Commit

Permalink
Validate that input references are of the form self.input.<input-name…
Browse files Browse the repository at this point in the history
…>.value. Closes #2990
  • Loading branch information
kaidaguerre committed Jan 12, 2023
1 parent 56f5946 commit 38efbc6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/steampipeconfig/modconfig/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/steampipeconfig/modconfig/parsed_property_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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:]
}
Expand Down
24 changes: 24 additions & 0 deletions pkg/steampipeconfig/parse/decode_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
8 changes: 3 additions & 5 deletions tests/manual_testing/node_reuse/inputs/dashboard.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -31,5 +29,5 @@ dashboard "inputs" {
query "q1"{
sql = "select arn from aws_account where arn = $1"
param "arn" { }
search_path="test"

}

0 comments on commit 38efbc6

Please sign in to comment.