Skip to content

Commit

Permalink
Revert: Validate that input references are of the form self.input.<i…
Browse files Browse the repository at this point in the history
…nput-name>.value. Remove until mods are updated. #2990
  • Loading branch information
kaidaguerre committed Feb 21, 2023
1 parent 016d373 commit 8f87f78
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 46 deletions.
62 changes: 20 additions & 42 deletions pkg/steampipeconfig/parse/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,28 @@ func DecodeConnection(block *hcl.Block) (*modconfig.Connection, hcl.Diagnostics)
connection.ConnectionNames = connections
}

// NOTE: 'option' blocks are included in the ConnectionBlockSchema so we can parse out of connectionContent
// however 'table' blocks are not in the schema - this is because the label is optional,
// something not supported when using a block schema - so we decode those from the 'rest'
// check for nested options
for _, connectionBlock := range connectionContent.Blocks {
if connectionBlock.Type != modconfig.BlockTypeOptions {
// not expected - ConnectionBlockSchema only defines options
panic(fmt.Sprintf("unexpected block type %s in decoded connection config", connectionBlock.Type))
}

opts, moreDiags := DecodeOptions(connectionBlock)
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
break
}
moreDiags = connection.SetOptions(opts, connectionBlock)
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
}
}
// now look for table blocks in `rest`
// NOTE: only supported for hcl config, NOT yml
if restBody, ok := rest.(*hclsyntax.Body); ok {
for _, connectionBlock := range restBody.Blocks {
switch connectionBlock.Type {
case modconfig.BlockTypeTable:
// table block is only valid for aggregator connection
if connection.Type != modconfig.ConnectionTypeAggregator {
diags.Append(&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "only aggregator connections can define 'table' blocks",
Subject: &block.DefRange})
break
}
case modconfig.BlockTypeOptions:
// ignore
default:
subject := connectionBlock.DefRange()
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: fmt.Sprintf("invalid block type '%s' - only 'options' and 'table' blocks are supported for Connections", connectionBlock.Type),
Subject: &subject,
})
switch connectionBlock.Type {
case "options":
// if we already found settings, fail
opts, moreDiags := DecodeOptions(connectionBlock)
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
break
}
moreDiags = connection.SetOptions(opts, connectionBlock)
if moreDiags.HasErrors() {
diags = append(diags, moreDiags...)
}

default:
// this can never happen
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: fmt.Sprintf("invalid block type '%s' - only 'options' blocks are supported for Connections", connectionBlock.Type),
Subject: &connectionBlock.DefRange,
})
}
}
// convert the remaining config to a hcl string to pass to the plugin
Expand All @@ -106,7 +85,6 @@ func DecodeConnection(block *hcl.Block) (*modconfig.Connection, hcl.Diagnostics)
}

return connection, diags

}

// build a hcl string with all attributes in the conneciton config which are NOT specified in the coneciton block schema
Expand Down
6 changes: 2 additions & 4 deletions pkg/steampipeconfig/parse/decode_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,10 @@ func identifyRuntimeDependenciesFromArray(attr *hcl.Attribute, idx int, parentPr
}

// 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
// TODO - include this with the main runtime dependency validation, 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" {
if propertyPath.Scope != modconfig.RuntimeDependencyDashboardScope {
return fmt.Errorf("could not resolve runtime dependency resource %s", propertyPath.Original)
}
return nil
Expand Down

0 comments on commit 8f87f78

Please sign in to comment.