mirror of
https://github.com/turbot/steampipe.git
synced 2026-04-27 19:00:07 -04:00
Settings Strip source_definition, documentation, search_path and search_path_prefix from snapshot shares and exports. Closes #2702
Snapshot exports and local shares should have no indentation or newlines. Closes #2701
This commit is contained in:
@@ -25,6 +25,7 @@ _What's new?_
|
||||
* Add `Variables` and `Inputs` to dashboard `ExecutionStarted` event. ([#2606](https://github.com/turbot/steampipe/issues/2606))
|
||||
* Validate check output and export formats _before_ execution. ([#2619](https://github.com/turbot/steampipe/issues/2619))
|
||||
* When starting a plugin process, pass a SecureConfig, to silence the `nil SecureConfig` error. ([#2567](https://github.com/turbot/steampipe/issues/2567))
|
||||
* Optimise autocomplete by only loading completions on startup or when connection config changes, rather than every time a query is entered . ([#2561](https://github.com/turbot/steampipe/issues/2561))
|
||||
|
||||
_Bug fixes_
|
||||
* Update `GetPathKeys` to treat key columns with `AnyOf` require property with the same precedence as `Required`. ([#254](https://github.com/turbot/steampipe-postgres-fdw/issues/254))
|
||||
|
||||
@@ -90,7 +90,7 @@ func uploadSnapshot(ctx context.Context, snapshot *dashboardtypes.SteampipeSnaps
|
||||
}
|
||||
|
||||
// strip verbose/sensitive fields
|
||||
stripSnapshotForUpload(cloudSnapshot)
|
||||
dashboardtypes.StripSnapshot(cloudSnapshot)
|
||||
|
||||
req := steampipecloud.CreateWorkspaceSnapshotRequest{Data: *cloudSnapshot, Tags: tags, Visibility: &visibility}
|
||||
req.SetTitle(title)
|
||||
@@ -116,28 +116,6 @@ func uploadSnapshot(ctx context.Context, snapshot *dashboardtypes.SteampipeSnaps
|
||||
return snapshotUrl, nil
|
||||
}
|
||||
|
||||
func stripSnapshotForUpload(snapshot *steampipecloud.WorkspaceSnapshotData) {
|
||||
propertiesToStrip := []string{
|
||||
"sql",
|
||||
"source_definition",
|
||||
"documentation",
|
||||
"search_path",
|
||||
"search_path_prefix"}
|
||||
for _, p := range snapshot.Panels {
|
||||
panel := p.(map[string]any)
|
||||
properties, _ := panel["properties"].(map[string]any)
|
||||
for _, property := range propertiesToStrip {
|
||||
// look both at top level and under properties
|
||||
delete(panel, property)
|
||||
if properties != nil {
|
||||
delete(properties, property)
|
||||
}
|
||||
}
|
||||
}
|
||||
// clear top level search path
|
||||
snapshot.SearchPath = []string{}
|
||||
}
|
||||
|
||||
func resolveSnapshotTitle(snapshot *dashboardtypes.SteampipeSnapshot) string {
|
||||
if titleArg := viper.GetString(constants.ArgSnapshotTitle); titleArg != "" {
|
||||
return titleArg
|
||||
|
||||
@@ -37,3 +37,40 @@ func (s *SteampipeSnapshot) AsCloudSnapshot() (*steampipecloud.WorkspaceSnapshot
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *SteampipeSnapshot) AsStrippedJson(indent bool) ([]byte, error) {
|
||||
res, err := s.AsCloudSnapshot()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err = StripSnapshot(res); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if indent {
|
||||
return json.MarshalIndent(res, "", " ")
|
||||
}
|
||||
return json.Marshal(res)
|
||||
}
|
||||
|
||||
func StripSnapshot(snapshot *steampipecloud.WorkspaceSnapshotData) error {
|
||||
propertiesToStrip := []string{
|
||||
"sql",
|
||||
"source_definition",
|
||||
"documentation",
|
||||
"search_path",
|
||||
"search_path_prefix"}
|
||||
for _, p := range snapshot.Panels {
|
||||
panel := p.(map[string]any)
|
||||
properties, _ := panel["properties"].(map[string]any)
|
||||
for _, property := range propertiesToStrip {
|
||||
// look both at top level and under properties
|
||||
delete(panel, property)
|
||||
if properties != nil {
|
||||
delete(properties, property)
|
||||
}
|
||||
}
|
||||
}
|
||||
// clear top level search path
|
||||
snapshot.SearchPath = []string{}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package export
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/turbot/steampipe/pkg/constants"
|
||||
"github.com/turbot/steampipe/pkg/dashboard/dashboardtypes"
|
||||
@@ -15,16 +14,15 @@ type SnapshotExporter struct {
|
||||
|
||||
func (e *SnapshotExporter) Export(_ context.Context, input ExportSourceData, filePath string) error {
|
||||
snapshot, ok := input.(*dashboardtypes.SteampipeSnapshot)
|
||||
|
||||
if !ok {
|
||||
return fmt.Errorf("SnapshotExporter inp-ut must be *dashboardtypes.SteampipeSnapshot")
|
||||
}
|
||||
snapshotStr, err := json.MarshalIndent(snapshot, "", " ")
|
||||
snapshotBytes, err := snapshot.AsStrippedJson(false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
res := strings.NewReader(fmt.Sprintf("%s\n", string(snapshotStr)))
|
||||
res := strings.NewReader(fmt.Sprintf("%s\n", string(snapshotBytes)))
|
||||
|
||||
return Write(filePath, res)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user