mirror of
https://github.com/turbot/steampipe.git
synced 2026-03-31 18:00:19 -04:00
Update check to te-add implicit conversion of named query name to named query, so setting the SQL field to a query name would work. Update reflection tables to fix JSONB arrays Workspace loads and watches files recursively if a mod.sp file exists in the workspace folder Update reflection tables - 'labels' and 'links' are now JSONB columns rename control property Query to SQL and do NOT try to resolve this as a named query Add documentation property to control_group
66 lines
2.0 KiB
Go
66 lines
2.0 KiB
Go
package parse
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/hashicorp/hcl/v2"
|
|
"github.com/hashicorp/hcl/v2/gohcl"
|
|
"github.com/hashicorp/hcl/v2/hclsyntax"
|
|
"github.com/turbot/steampipe/ociinstaller"
|
|
"github.com/turbot/steampipe/steampipeconfig/modconfig"
|
|
)
|
|
|
|
func ParseConnection(block *hcl.Block, fileData map[string][]byte) (*modconfig.Connection, hcl.Diagnostics) {
|
|
connectionContent, rest, diags := block.Body.PartialContent(ConnectionSchema)
|
|
if diags.HasErrors() {
|
|
return nil, diags
|
|
}
|
|
|
|
// get connection name
|
|
connection := &modconfig.Connection{Name: block.Labels[0]}
|
|
|
|
var pluginName string
|
|
diags = gohcl.DecodeExpression(connectionContent.Attributes["plugin"].Expr, nil, &pluginName)
|
|
if diags.HasErrors() {
|
|
return nil, diags
|
|
}
|
|
connection.Plugin = ociinstaller.NewSteampipeImageRef(pluginName).DisplayImageRef()
|
|
|
|
// check for nested options
|
|
for _, connectionBlock := range connectionContent.Blocks {
|
|
switch connectionBlock.Type {
|
|
case "options":
|
|
// if we already found settings, fail
|
|
opts, moreDiags := ParseOptions(connectionBlock)
|
|
if moreDiags.HasErrors() {
|
|
diags = append(diags, moreDiags...)
|
|
break
|
|
}
|
|
connection.SetOptions(opts, connectionBlock)
|
|
|
|
default:
|
|
// this can probably 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,
|
|
})
|
|
}
|
|
}
|
|
// now build a string containing the hcl for all other connection config properties
|
|
restBody := rest.(*hclsyntax.Body)
|
|
var configProperties []string
|
|
for name, a := range restBody.Attributes {
|
|
// if this attribute does not appear in connectionContent, load the hcl string
|
|
if _, ok := connectionContent.Attributes[name]; !ok {
|
|
configProperties = append(configProperties, string(a.SrcRange.SliceBytes(fileData[a.SrcRange.Filename])))
|
|
}
|
|
}
|
|
sort.Strings(configProperties)
|
|
connection.Config = strings.Join(configProperties, "\n")
|
|
|
|
return connection, diags
|
|
}
|