diff --git a/pkg/steampipeconfig/parse/connection.go b/pkg/steampipeconfig/parse/connection.go index 0839790b74..fb04b67481 100644 --- a/pkg/steampipeconfig/parse/connection.go +++ b/pkg/steampipeconfig/parse/connection.go @@ -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 @@ -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 diff --git a/pkg/steampipeconfig/parse/decode_args.go b/pkg/steampipeconfig/parse/decode_args.go index 12dfbe265f..4b64c39622 100644 --- a/pkg/steampipeconfig/parse/decode_args.go +++ b/pkg/steampipeconfig/parse/decode_args.go @@ -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..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