Skip to content

Commit

Permalink
Add steampipe field to with sdk version to _ctx, including sdk ve…
Browse files Browse the repository at this point in the history
…rsion. Closes #712
  • Loading branch information
kaidaguerre authored Dec 6, 2023
1 parent ceaf92c commit 9a80c31
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
34 changes: 25 additions & 9 deletions plugin/connection_config_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package plugin

import (
"fmt"
"github.com/hashicorp/hcl/v2/json"
"log"

"github.com/hashicorp/hcl/v2"
Expand Down Expand Up @@ -140,15 +141,7 @@ func (c *ConnectionConfigSchema) parseConfigWithHclTags(config *proto.Connection
filename := ""
startPos := hcl.Pos{}

file, diags := hclsyntax.ParseConfig(configString, filename, startPos)
if diags.HasErrors() {
return nil, DiagsToError(fmt.Sprintf("failed to parse connection config for connection '%s'", config.Connection), diags)
}
_, body, diags := file.Body.PartialContent(&hcl.BodySchema{})
if diags.HasErrors() {
return nil, DiagsToError(fmt.Sprintf("failed to parse connection config for connection '%s'", config.Connection), diags)
}

body, diags := parseConfig(configString, filename, startPos)
evalCtx := &hcl.EvalContext{
Variables: make(map[string]cty.Value),
Functions: make(map[string]function.Function),
Expand All @@ -162,3 +155,26 @@ func (c *ConnectionConfigSchema) parseConfigWithHclTags(config *proto.Connection
// return the struct by value
return helpers.DereferencePointer(configStruct), nil
}

func parseConfig(configString []byte, filename string, startPos hcl.Pos) (hcl.Body, hcl.Diagnostics) {
file, diags := hclsyntax.ParseConfig(configString, filename, startPos)
if diags.HasErrors() {
// try json
return parseJsonConfig(configString, filename)

}
//_, body, diags := file.Body.PartialContent(&hcl.BodySchema{})
//if diags.HasErrors() {
// return nil, diags
//}
return file.Body, nil

}

func parseJsonConfig(configString []byte, filename string) (hcl.Body, hcl.Diagnostics) {
file, diags := json.Parse(configString, filename)
if diags.HasErrors() {
return nil, diags
}
return file.Body, nil
}
13 changes: 12 additions & 1 deletion plugin/row_with_metadata.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package plugin

import "github.com/turbot/steampipe-plugin-sdk/v5/version"

type hydrateMetadata struct {
Type string `json:"type"`
FuncName string `json:"function_name"`
Expand All @@ -8,8 +10,14 @@ type hydrateMetadata struct {
DelayMs int64 `json:"rate_limiter_delay_ms"`
}

type SteampipeMetadata struct {
SdkVersion string `json:"sdk_version"`
}

type rowCtxData struct {
Connection string `json:"connection_name"`
Connection string `json:"connection_name"`
Steampipe SteampipeMetadata `json:"steampipe"`

Diagnostics *rowCtxDiagnostics `json:"diagnostics,omitempty"`
}
type rowCtxDiagnostics struct {
Expand All @@ -20,6 +28,9 @@ func newRowCtxData(rd *rowData) *rowCtxData {
d := rd.queryData
res := &rowCtxData{
Connection: d.Connection.Name,
Steampipe: SteampipeMetadata{
SdkVersion: version.String(),
},
}

if loadDiagnosticsEnvVar() == DiagnosticsAll {
Expand Down

0 comments on commit 9a80c31

Please sign in to comment.