Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SteampipeMetadata with sdk version to _ctx #717

Merged
merged 3 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading