Skip to content

Commit

Permalink
Cleanup connection state file to remove old legacy properties. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
pskrbasu committed Feb 6, 2023
1 parent 5d67412 commit 7235e7d
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 207 deletions.
1 change: 0 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ func migrateLegacyFiles() error {
}
return error_helpers.CombineErrors(
migrate.Migrate(&statefile.State{}, filepaths.LegacyStateFilePath()),
migrate.Migrate(&steampipeconfig.ConnectionDataMap{}, filepaths.ConnectionStatePath()),
migrate.Migrate(&versionfile.PluginVersionFile{}, filepaths.PluginVersionFilePath()),
migrate.Migrate(&versionfile.DatabaseVersionFile{}, filepaths.DatabaseVersionFilePath()),
)
Expand Down
28 changes: 0 additions & 28 deletions pkg/steampipeconfig/connection_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ type ConnectionData struct {
SchemaHash string `json:"schema_hash,omitempty"`
// the creation time of the plugin file (only used for local plugins)
ModTime time.Time `json:"mod_time"`

// legacy properties included for backwards compatibility with v0.13
LegacyPlugin string `json:"Plugin,omitempty"`
LegacyConnection *modconfig.Connection `json:"Connection,omitempty"`
LegacySchemaMode string `json:"SchemaMode,omitempty"`
LegacySchemaHash string `json:"SchemaHash,omitempty"`
LegacyModTime time.Time `json:"ModTime,omitempty"`
}

func NewConnectionData(remoteSchema string, connection *modconfig.Connection, creationTime time.Time) *ConnectionData {
Expand All @@ -50,27 +43,6 @@ func (d *ConnectionData) IsValid() bool {
return d.StructVersion > 0
}

// MigrateLegacy migrates the legacy properties into new properties
func (d *ConnectionData) MigrateLegacy() {
d.StructVersion = ConnectionDataStructVersion
d.Plugin = d.LegacyPlugin
d.SchemaMode = d.LegacySchemaMode
d.SchemaHash = d.LegacySchemaHash
d.ModTime = d.LegacyModTime
d.Connection = d.LegacyConnection
d.Connection.MigrateLegacy()
}

// MaintainLegacy keeps the values of the legacy properties intact while
// refreshing connections
func (d *ConnectionData) MaintainLegacy() {
d.LegacyPlugin = d.Plugin
d.LegacySchemaMode = d.SchemaMode
d.LegacySchemaHash = d.SchemaHash
d.LegacyModTime = d.ModTime
d.LegacyConnection = d.Connection
}

func (d *ConnectionData) Equals(other *ConnectionData) bool {
if d.Connection == nil || other.Connection == nil {
// if either object has a nil Connection, then it may be data from an old connection state file
Expand Down
11 changes: 0 additions & 11 deletions pkg/steampipeconfig/connection_data_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/turbot/steampipe/pkg/filepaths"
"github.com/turbot/steampipe/pkg/migrate"
"github.com/turbot/steampipe/pkg/steampipeconfig/modconfig"
"github.com/turbot/steampipe/pkg/utils"
)
Expand All @@ -25,18 +24,8 @@ func (m ConnectionDataMap) IsValid() bool {
return true
}

func (m ConnectionDataMap) MigrateFrom() migrate.Migrateable {
for _, v := range m {
v.MigrateLegacy()
}
return m
}

func (m ConnectionDataMap) Save() error {
connFilePath := filepaths.ConnectionStatePath()
for _, v := range m {
v.MaintainLegacy()
}
connFileJSON, err := json.MarshalIndent(m, "", " ")
if err != nil {
log.Println("[ERROR]", "Error while writing state file", err)
Expand Down
127 changes: 0 additions & 127 deletions pkg/steampipeconfig/load_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"testing"

"github.com/hashicorp/hcl/v2"
"github.com/turbot/steampipe/pkg/filepaths"
"github.com/turbot/steampipe/pkg/steampipeconfig/modconfig"
"github.com/turbot/steampipe/pkg/steampipeconfig/options"
Expand Down Expand Up @@ -66,24 +65,6 @@ var testCasesLoadConfig = map[string]loadConfigTest{
Byte: 10,
},
},
LegacyName: "",
LegacyPluginShortName: "",
LegacyPlugin: "",
LegacyType: "",
LegacyConfig: "",
LegacyDeclRange: hcl.Range{
Filename: "",
Start: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
End: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
},
},
"aws_dmi_002": {
Name: "aws_dmi_002",
Expand All @@ -104,24 +85,6 @@ var testCasesLoadConfig = map[string]loadConfigTest{
Byte: 10,
},
},
LegacyName: "",
LegacyPluginShortName: "",
LegacyPlugin: "",
LegacyType: "",
LegacyConfig: "",
LegacyDeclRange: hcl.Range{
Filename: "",
Start: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
End: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
},
},
},
DefaultConnectionOptions: &options.Connection{
Expand Down Expand Up @@ -153,24 +116,6 @@ var testCasesLoadConfig = map[string]loadConfigTest{
Byte: 10,
},
},
LegacyName: "",
LegacyPluginShortName: "",
LegacyPlugin: "",
LegacyType: "",
LegacyConfig: "",
LegacyDeclRange: hcl.Range{
Filename: "",
Start: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
End: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
},
},
},
DefaultConnectionOptions: &options.Connection{
Expand Down Expand Up @@ -202,24 +147,6 @@ var testCasesLoadConfig = map[string]loadConfigTest{
Byte: 10,
},
},
LegacyName: "",
LegacyPluginShortName: "",
LegacyPlugin: "",
LegacyType: "",
LegacyConfig: "",
LegacyDeclRange: hcl.Range{
Filename: "",
Start: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
End: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
},
},
},
DefaultConnectionOptions: &options.Connection{
Expand Down Expand Up @@ -274,24 +201,6 @@ var testCasesLoadConfig = map[string]loadConfigTest{
Byte: 10,
},
},
LegacyName: "",
LegacyPluginShortName: "",
LegacyPlugin: "",
LegacyType: "",
LegacyConfig: "",
LegacyDeclRange: hcl.Range{
Filename: "",
Start: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
End: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
},
},
},
DefaultConnectionOptions: &options.Connection{
Expand Down Expand Up @@ -342,24 +251,6 @@ var testCasesLoadConfig = map[string]loadConfigTest{
Byte: 10,
},
},
LegacyName: "",
LegacyPluginShortName: "",
LegacyPlugin: "",
LegacyType: "",
LegacyConfig: "",
LegacyDeclRange: hcl.Range{
Filename: "",
Start: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
End: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
},
},
},
DefaultConnectionOptions: &options.Connection{
Expand Down Expand Up @@ -412,24 +303,6 @@ var testCasesLoadConfig = map[string]loadConfigTest{
Byte: 10,
},
},
LegacyName: "",
LegacyPluginShortName: "",
LegacyPlugin: "",
LegacyType: "",
LegacyConfig: "",
LegacyDeclRange: hcl.Range{
Filename: "",
Start: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
End: hcl.Pos{
Line: 0,
Column: 0,
Byte: 0,
},
},
},
},
DefaultConnectionOptions: &options.Connection{
Expand Down
44 changes: 4 additions & 40 deletions pkg/steampipeconfig/modconfig/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package modconfig

import (
"fmt"
"log"
"path"
"reflect"

"github.com/hashicorp/hcl/v2"
"github.com/turbot/go-kit/helpers"
sdkproto "github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe/pkg/steampipeconfig/options"
"golang.org/x/exp/maps"
"log"
"path"
"reflect"
)

const (
Expand Down Expand Up @@ -66,43 +67,6 @@ type Connection struct {
// options
Options *options.Connection `json:"options,omitempty"`
DeclRange Range `json:"decl_range,omitempty"`

// legacy properties included for backwards compatibility with v0.13
LegacyName string `json:"Name,omitempty"`
LegacyPluginShortName string `json:"PluginShortName,omitempty"`
LegacyPlugin string `json:"Plugin,omitempty"`
LegacyType string `json:"Type,omitempty"`
LegacyConnectionNames []string `json:"Connections,omitempty"`
LegacyConfig string `json:"Config,omitempty"`
LegacyOptions *options.Connection `json:"Options,omitempty"`
LegacyDeclRange hcl.Range `json:"DeclRange,omitempty"`
}

// MigrateLegacy migrates the legacy properties into new properties
func (c *Connection) MigrateLegacy() {
c.Name = c.LegacyName
c.Plugin = c.LegacyPlugin
c.PluginShortName = c.LegacyPluginShortName
c.Type = c.LegacyType
c.ConnectionNames = c.LegacyConnectionNames
c.Config = c.LegacyConfig
c.DeclRange = NewRange(c.LegacyDeclRange)
if c.LegacyOptions != nil {
c.Options = c.LegacyOptions
c.Options.MigrateLegacy()
}
}

// MaintainLegacy keeps the values of the legacy properties intact while
// refreshing connections
func (c *Connection) MaintainLegacy() {
c.LegacyName = c.Name
c.LegacyPlugin = c.Plugin
c.LegacyPluginShortName = c.PluginShortName
c.LegacyType = c.Type
c.LegacyConnectionNames = c.ConnectionNames
c.LegacyConfig = c.Config
c.LegacyDeclRange = c.DeclRange.GetLegacy()
}

// Range represents a span of characters between two positions in a source file.
Expand Down

0 comments on commit 7235e7d

Please sign in to comment.