Skip to content

Commit

Permalink
Fix legacy mod 'requires' property validation. #1686
Browse files Browse the repository at this point in the history
  • Loading branch information
kaidaguerre committed Mar 17, 2022
1 parent d370381 commit 8161066
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
36 changes: 19 additions & 17 deletions steampipeconfig/modconfig/block_type.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package modconfig

const (
BlockTypeMod = "mod"
BlockTypeQuery = "query"
BlockTypeControl = "control"
BlockTypeBenchmark = "benchmark"
BlockTypeDashboard = "dashboard"
BlockTypeContainer = "container"
BlockTypeChart = "chart"
BlockTypeCard = "card"
BlockTypeFlow = "flow"
BlockTypeHierarchy = "hierarchy"
BlockTypeImage = "image"
BlockTypeInput = "input"
BlockTypeTable = "table"
BlockTypeText = "text"
BlockTypeLocals = "locals"
BlockTypeVariable = "variable"
BlockTypeParam = "param"
BlockTypeMod = "mod"
BlockTypeQuery = "query"
BlockTypeControl = "control"
BlockTypeBenchmark = "benchmark"
BlockTypeDashboard = "dashboard"
BlockTypeContainer = "container"
BlockTypeChart = "chart"
BlockTypeCard = "card"
BlockTypeFlow = "flow"
BlockTypeHierarchy = "hierarchy"
BlockTypeImage = "image"
BlockTypeInput = "input"
BlockTypeTable = "table"
BlockTypeText = "text"
BlockTypeLocals = "locals"
BlockTypeVariable = "variable"
BlockTypeParam = "param"
BlockTypeRequire = "require"
BlockTypeLegacyRequires = "requires"
)

// QueryProviderBlocks is a list of block types which implement QueryProvider
Expand Down
16 changes: 10 additions & 6 deletions steampipeconfig/modconfig/mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/Masterminds/semver"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
"github.com/hashicorp/hcl/v2/hclwrite"
"github.com/turbot/go-kit/helpers"
typehelpers "github.com/turbot/go-kit/types"
Expand Down Expand Up @@ -249,12 +250,15 @@ func (m *Mod) OnDecoded(block *hcl.Block, resourceMapProvider ModResourcesProvid

// handle legacy requires block
if m.LegacyRequire != nil && !m.LegacyRequire.Empty() {
if m.Require != nil && !m.Require.Empty() {
return hcl.Diagnostics{&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Both 'require' and legacy 'requires' blocks are defined",
Subject: &block.DefRange,
}}
// ensure that both 'require' and 'requires' were not set
for _, b := range block.Body.(*hclsyntax.Body).Blocks {
if b.Type == BlockTypeRequire {
return hcl.Diagnostics{&hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Both 'require' and legacy 'requires' blocks are defined",
Subject: &block.DefRange,
}}
}
}
m.Require = m.LegacyRequire
}
Expand Down
2 changes: 0 additions & 2 deletions steampipeconfig/parse/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,6 @@ func ModfileExists(modPath string) bool {
// ParseModDefinition parses the modfile only
// it is expected the calling code will have verified the existence of the modfile by calling ModfileExists
func ParseModDefinition(modPath string) (*modconfig.Mod, error) {
// TODO think about variables

// if there is no mod at this location, return error
modFilePath := filepaths.ModFilePath(modPath)
if _, err := os.Stat(modFilePath); os.IsNotExist(err) {
Expand Down

0 comments on commit 8161066

Please sign in to comment.