mirror of
https://github.com/turbot/steampipe.git
synced 2025-12-25 03:00:48 -05:00
Remove search_path and search_path_prefix from Control and Query. Closes #2963
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -182,35 +181,6 @@ func (r *ControlRun) skip(ctx context.Context) {
|
||||
r.setRunStatus(ctx, dashboardtypes.RunComplete)
|
||||
}
|
||||
|
||||
// set search path for this control run
|
||||
func (r *ControlRun) setSearchPath(ctx context.Context, session *db_common.DatabaseSession, client db_common.Client) error {
|
||||
utils.LogTime("ControlRun.setSearchPath start")
|
||||
defer utils.LogTime("ControlRun.setSearchPath end")
|
||||
|
||||
var searchPath []string
|
||||
var searchPathPrefix []string
|
||||
|
||||
if r.Control.SearchPath == nil && r.Control.SearchPathPrefix == nil {
|
||||
return nil
|
||||
}
|
||||
if r.Control.SearchPath != nil {
|
||||
searchPath = strings.Split(*r.Control.SearchPath, ",")
|
||||
}
|
||||
if r.Control.SearchPathPrefix != nil {
|
||||
searchPathPrefix = strings.Split(*r.Control.SearchPathPrefix, ",")
|
||||
}
|
||||
|
||||
newSearchPath, err := client.ContructSearchPath(ctx, searchPath, searchPathPrefix)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// now execute the SQL to actually set the search path
|
||||
q := fmt.Sprintf("set search_path to %s", strings.Join(newSearchPath, ","))
|
||||
_, err = session.Connection.Exec(ctx, q)
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *ControlRun) execute(ctx context.Context, client db_common.Client) {
|
||||
utils.LogTime("ControlRun.execute start")
|
||||
defer utils.LogTime("ControlRun.execute end")
|
||||
@@ -275,12 +245,6 @@ func (r *ControlRun) execute(ctx context.Context, client db_common.Client) {
|
||||
return
|
||||
}
|
||||
|
||||
log.Printf("[TRACE] setting search path %s\n", control.Name())
|
||||
if err := r.setSearchPath(ctx, dbSession, client); err != nil {
|
||||
r.setError(ctx, err)
|
||||
return
|
||||
}
|
||||
|
||||
controlExecutionCtx := r.getControlQueryContext(ctx)
|
||||
|
||||
// execute the control query
|
||||
|
||||
@@ -31,7 +31,7 @@ type ExecutionTree struct {
|
||||
Progress *controlstatus.ControlProgress `json:"progress"`
|
||||
// map of dimension property name to property value to color map
|
||||
DimensionColorGenerator *DimensionColorGenerator `json:"-"`
|
||||
// the current session search path (this may be overidden for specific controls)
|
||||
// the current session search path
|
||||
SearchPath []string `json:"-"`
|
||||
Workspace *workspace.Workspace `json:"-"`
|
||||
client db_common.Client
|
||||
|
||||
@@ -19,9 +19,7 @@ type Control struct {
|
||||
// required to allow partial decoding
|
||||
Remain hcl.Body `hcl:",remain" json:"-"`
|
||||
|
||||
SearchPath *string `cty:"search_path" hcl:"search_path" column:"search_path,text" json:"search_path,omitempty"`
|
||||
SearchPathPrefix *string `cty:"search_path_prefix" hcl:"search_path_prefix" column:"search_path_prefix,text" json:"search_path_prefix,omitempty"`
|
||||
Severity *string `cty:"severity" hcl:"severity" column:"severity,text" json:"severity,omitempty"`
|
||||
Severity *string `cty:"severity" hcl:"severity" column:"severity,text" json:"severity,omitempty"`
|
||||
|
||||
// dashboard specific properties
|
||||
Base *Control `hcl:"base" json:"-"`
|
||||
@@ -62,8 +60,6 @@ func (c *Control) Equals(other *Control) bool {
|
||||
c.FullName == other.FullName &&
|
||||
typehelpers.SafeString(c.Description) == typehelpers.SafeString(other.Description) &&
|
||||
typehelpers.SafeString(c.Documentation) == typehelpers.SafeString(other.Documentation) &&
|
||||
typehelpers.SafeString(c.SearchPath) == typehelpers.SafeString(other.SearchPath) &&
|
||||
typehelpers.SafeString(c.SearchPathPrefix) == typehelpers.SafeString(other.SearchPathPrefix) &&
|
||||
typehelpers.SafeString(c.Severity) == typehelpers.SafeString(other.Severity) &&
|
||||
typehelpers.SafeString(c.SQL) == typehelpers.SafeString(other.SQL) &&
|
||||
typehelpers.SafeString(c.Title) == typehelpers.SafeString(other.Title)
|
||||
@@ -200,12 +196,6 @@ func (c *Control) Diff(other *Control) *DashboardTreeItemDiffs {
|
||||
if !utils.SafeStringsEqual(c.Documentation, other.Documentation) {
|
||||
res.AddPropertyDiff("Documentation")
|
||||
}
|
||||
if !utils.SafeStringsEqual(c.SearchPath, other.SearchPath) {
|
||||
res.AddPropertyDiff("SearchPath")
|
||||
}
|
||||
if !utils.SafeStringsEqual(c.SearchPathPrefix, other.SearchPathPrefix) {
|
||||
res.AddPropertyDiff("SearchPathPrefix")
|
||||
}
|
||||
if !utils.SafeStringsEqual(c.Severity, other.Severity) {
|
||||
res.AddPropertyDiff("Severity")
|
||||
}
|
||||
@@ -239,12 +229,6 @@ func (c *Control) setBaseProperties() {
|
||||
// call into parent nested struct setBaseProperties
|
||||
c.QueryProviderImpl.setBaseProperties()
|
||||
|
||||
if c.SearchPath == nil {
|
||||
c.SearchPath = c.Base.SearchPath
|
||||
}
|
||||
if c.SearchPathPrefix == nil {
|
||||
c.SearchPathPrefix = c.Base.SearchPathPrefix
|
||||
}
|
||||
if c.Severity == nil {
|
||||
c.Severity = c.Base.Severity
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@ type Query struct {
|
||||
// required to allow partial decoding
|
||||
Remain hcl.Body `hcl:",remain" json:"-"`
|
||||
|
||||
SearchPath *string `cty:"search_path" hcl:"search_path" column:"search_path,text" json:"search_path,omitempty"`
|
||||
SearchPathPrefix *string `cty:"search_path_prefix" hcl:"search_path_prefix" column:"search_path_prefix,text" json:"search_path_prefix,omitempty"`
|
||||
// only here as otherwise gocty.ImpliedType panics
|
||||
Unused string `cty:"unused" json:"-"`
|
||||
}
|
||||
|
||||
func NewQuery(block *hcl.Block, mod *Mod, shortName string) HclResource {
|
||||
@@ -108,8 +108,6 @@ func (q *Query) Equals(other *Query) bool {
|
||||
q.FullName == other.FullName &&
|
||||
typehelpers.SafeString(q.Description) == typehelpers.SafeString(other.Description) &&
|
||||
typehelpers.SafeString(q.Documentation) == typehelpers.SafeString(other.Documentation) &&
|
||||
typehelpers.SafeString(q.SearchPath) == typehelpers.SafeString(other.SearchPath) &&
|
||||
typehelpers.SafeString(q.SearchPathPrefix) == typehelpers.SafeString(other.SearchPathPrefix) &&
|
||||
typehelpers.SafeString(q.SQL) == typehelpers.SafeString(other.SQL) &&
|
||||
typehelpers.SafeString(q.Title) == typehelpers.SafeString(other.Title)
|
||||
if !res {
|
||||
@@ -186,10 +184,6 @@ func (q *Query) Diff(other *Query) *DashboardTreeItemDiffs {
|
||||
res.AddPropertyDiff("Name")
|
||||
}
|
||||
|
||||
if !utils.SafeStringsEqual(q.SearchPath, other.SearchPath) {
|
||||
res.AddPropertyDiff("SearchPath")
|
||||
}
|
||||
|
||||
res.populateChildDiffs(q, other)
|
||||
res.queryProviderDiff(q, other)
|
||||
|
||||
|
||||
@@ -241,26 +241,7 @@ load "$LIB_BATS_SUPPORT/load.bash"
|
||||
rm -f test.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path_prefix when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_4 --output json --export test.json
|
||||
assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f test.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_5 --output json --export test.json
|
||||
assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f test.json
|
||||
}
|
||||
|
||||
@test "steampipe check search_path and search_path_prefix when passed in the control" {
|
||||
cd $FUNCTIONALITY_TEST_MOD
|
||||
run steampipe check control.search_path_test_6 --output json --export test.json
|
||||
assert_equal "$(cat test.json | jq '.controls[0].results[0].status')" '"ok"'
|
||||
rm -f test.json
|
||||
}
|
||||
|
||||
## plugin crash
|
||||
|
||||
|
||||
Reference in New Issue
Block a user