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

Fix defaulting #590

Merged
merged 2 commits into from
Oct 22, 2024
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
14 changes: 4 additions & 10 deletions modconfig/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ type Mod struct {
// convenient aggregation of all resources
ResourceMaps *ResourceMaps `json:"-"`

// store mod database, search path and search path prefix in separate variables from the ModTreeItemImpl fields
// as these have lower precedence
ModDatabase *string `cty:"mod_database"`
ModSearchPath []string `cty:"mod_search_path"`
ModSearchPathPrefix []string `cty:"mod_search_path_prefix"`

// the filepath of the mod.sp/mod.fp/mod.pp file (will be empty for default mod)
modFilePath string
}
Expand Down Expand Up @@ -407,15 +401,15 @@ func (m *Mod) RequireHasUnresolvedArgs() bool {
}

func (m *Mod) GetConnectionDependsOn() []string {
if m.ModDatabase != nil && strings.HasPrefix(*m.ModDatabase, "connection.") {
return []string{strings.TrimPrefix(*m.ModDatabase, "connection.")}
if m.Database != nil && strings.HasPrefix(*m.Database, "connection.") {
return []string{strings.TrimPrefix(*m.Database, "connection.")}
}
return nil
}

func (m *Mod) GetDefaultConnectionString(evalContext *hcl.EvalContext) (string, error) {
if m.ModDatabase != nil {
modDatabase := *m.ModDatabase
if m.Database != nil {
modDatabase := *m.Database

// if the database is actually a connection name, try to resolve from eval context
if strings.HasPrefix(modDatabase, "connection.") {
Expand Down
24 changes: 20 additions & 4 deletions modconfig/mod_tree_item_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hashicorp/hcl/v2"
"github.com/turbot/pipe-fittings/cty_helpers"
"github.com/turbot/pipe-fittings/printers"
"github.com/turbot/pipe-fittings/schema"
"github.com/zclconf/go-cty/cty"
"golang.org/x/exp/maps"
)
Expand Down Expand Up @@ -89,9 +90,15 @@ func (b *ModTreeItemImpl) GetDatabase() *string {
if b.Database != nil {
return b.Database
}

// if we have a parent, ask for its database
// (stop when we get to the mod - the mod database property has lower precedence)
if len(b.parents) > 0 {
return b.GetParents()[0].GetDatabase()
if parent := b.GetParents()[0]; parent.BlockType() != schema.BlockTypeMod {
return parent.GetDatabase()
}
}

return nil
}

Expand All @@ -100,8 +107,12 @@ func (b *ModTreeItemImpl) GetSearchPath() []string {
if len(b.SearchPath) != 0 {
return b.SearchPath
}
// if we have a parent, ask for its search path
// (stop when we get to the mod - the mod database property has lower precedence)
if len(b.parents) > 0 {
return b.GetParents()[0].GetSearchPath()
if parent := b.GetParents()[0]; parent.BlockType() != schema.BlockTypeMod {
return parent.GetSearchPath()
}
}

return nil
Expand All @@ -112,9 +123,14 @@ func (b *ModTreeItemImpl) GetSearchPathPrefix() []string {
if len(b.SearchPathPrefix) != 0 {
return b.SearchPathPrefix
}
if len(b.GetParents()) > 0 {
return b.GetParents()[0].GetSearchPathPrefix()
// if we have a parent, ask for its search path prefix
// (stop when we get to the mod - the mod database property has lower precedence)
if len(b.parents) > 0 {
if parent := b.GetParents()[0]; parent.BlockType() != schema.BlockTypeMod {
return parent.GetSearchPath()
}
}

return nil
}

Expand Down
8 changes: 4 additions & 4 deletions parse/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ func decodeMod(block *hcl.Block, evalCtx *hcl.EvalContext, mod *modconfig.Mod) (

// if connection string or search path was specified (by the mod referencing a connection), set them
if connectionString != nil {
mod.ModDatabase = connectionString
mod.Database = connectionString
}
if searchPath != nil {
mod.ModSearchPath = searchPathPrefix
mod.SearchPath = searchPath
}
if searchPathPrefix != nil {
mod.ModSearchPathPrefix = searchPathPrefix
mod.SearchPathPrefix = searchPathPrefix
}

return mod, res
Expand Down Expand Up @@ -423,7 +423,7 @@ func resolveConnectionString(content *hcl.BodyContent, evalCtx *hcl.EvalContext)
if dbValue.Type() == cty.String {
connectionString = dbValue.AsString()
} else {
// if this is a temporary connection, ignore (this will only occur during the vareiable parsing phase)
// if this is a temporary connection, ignore (this will only occur during the variable parsing phase)
if dbValue.Type().HasAttribute("temporary") {
return nil, searchPath, searchPathPrefix, diags
}
Expand Down
4 changes: 0 additions & 4 deletions steampipeconfig/pipes_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ type PipesMetadata struct {
ConnectionString string `json:"-"`
}

func (c *PipesMetadata) GetConnectionString() string {
return c.ConnectionString
}

type ActorMetadata struct {
Id string `json:"id,omitempty"`
Handle string `json:"handle,omitempty"`
Expand Down
Loading