Skip to content

Commit

Permalink
Update introspection tables to ensure naming consistency - fix mods a…
Browse files Browse the repository at this point in the history
…nd pseudo resources to remove type prefix. Closes #959
  • Loading branch information
kaidaguerre committed Sep 27, 2021
1 parent 903d50f commit 305ab87
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 16 deletions.
17 changes: 13 additions & 4 deletions steampipeconfig/load_mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ func createPseudoResources(modPath string, opts *parse.ParseModOptions) ([]modco
continue
}
if resource != nil {
metadata := getPseudoResourceMetadata(resource.Name(), path, fileData)
metadata, err := getPseudoResourceMetadata(resource.Name(), path, fileData)
if err != nil {
return nil, err
}
resource.SetMetadata(metadata)
res = append(res, resource)
}
Expand All @@ -192,19 +195,25 @@ func createPseudoResources(modPath string, opts *parse.ParseModOptions) ([]modco
return res, nil
}

func getPseudoResourceMetadata(name string, path string, fileData []byte) *modconfig.ResourceMetadata {
func getPseudoResourceMetadata(resourceName string, path string, fileData []byte) (*modconfig.ResourceMetadata, error) {
sourceDefinition := string(fileData)
split := strings.Split(sourceDefinition, "\n")
lineCount := len(split)

// convert the name into a short name
parsedName, err := modconfig.ParseResourceName(resourceName)
if err != nil {
return nil, err
}

m := &modconfig.ResourceMetadata{
ResourceName: name,
ResourceName: parsedName.Name,
FileName: path,
StartLineNumber: 1,
EndLineNumber: lineCount,
IsAutoGenerated: true,
SourceDefinition: sourceDefinition,
}

return m
return m, nil
}
2 changes: 1 addition & 1 deletion steampipeconfig/modconfig/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,5 +252,5 @@ func (b *Benchmark) Name() string {

// QualifiedName returns the name in format: '<modName>.control.<shortName>'
func (b *Benchmark) QualifiedName() string {
return fmt.Sprintf("%s.%s", b.metadata.ModShortName, b.FullName)
return fmt.Sprintf("%s.%s", b.metadata.ModName, b.FullName)
}
2 changes: 1 addition & 1 deletion steampipeconfig/modconfig/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func (c *Control) Name() string {

// QualifiedName returns the name in format: '<modName>.control.<shortName>'
func (c *Control) QualifiedName() string {
return fmt.Sprintf("%s.%s", c.metadata.ModShortName, c.FullName)
return fmt.Sprintf("%s.%s", c.metadata.ModName, c.FullName)
}

// GetPaths implements ModTreeItem
Expand Down
2 changes: 1 addition & 1 deletion steampipeconfig/modconfig/panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (p *Panel) Name() string {

// QualifiedName returns the name in format: '<modName>.panel.<shortName>'
func (p *Panel) QualifiedName() string {
return fmt.Sprintf("%s.%s", p.metadata.ModShortName, p.FullName)
return fmt.Sprintf("%s.%s", p.metadata.ModName, p.FullName)
}

// OnDecoded implements HclResource
Expand Down
2 changes: 1 addition & 1 deletion steampipeconfig/modconfig/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (q *Query) Name() string {

// QualifiedName returns the name in format: '<modName>.control.<shortName>'
func (q *Query) QualifiedName() string {
return fmt.Sprintf("%s.%s", q.metadata.ModShortName, q.FullName)
return fmt.Sprintf("%s.%s", q.metadata.ModName, q.FullName)
}

// GetMetadata implements ResourceWithMetadata
Expand Down
2 changes: 1 addition & 1 deletion steampipeconfig/modconfig/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (r *Report) Name() string {

// QualifiedName returns the name in format: '<modName>.report.<shortName>'
func (r *Report) QualifiedName() string {
return fmt.Sprintf("%s.%s", r.metadata.ModShortName, r.FullName)
return fmt.Sprintf("%s.%s", r.metadata.ModName, r.FullName)
}

// OnDecoded implements HclResource
Expand Down
8 changes: 2 additions & 6 deletions steampipeconfig/modconfig/resource_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ package modconfig
// about each resource, used to populate the introspection tables
type ResourceMetadata struct {
ResourceName string `column:"resource_name,text"`
// mod name in the format mod.<modName>@<version?
// mod short name
ModName string `column:"mod_name,text"`
FileName string `column:"file_name,text"`
StartLineNumber int `column:"start_line_number,integer"`
EndLineNumber int `column:"end_line_number,integer"`
IsAutoGenerated bool `column:"auto_generated,bool"`
SourceDefinition string `column:"source_definition,text"`

// mod short name
ModShortName string
}

// SetMod sets the mod name and mod short name
Expand All @@ -22,8 +19,7 @@ func (m *ResourceMetadata) SetMod(mod *Mod) {
if mod.IsDefaultMod() {
return
}
m.ModShortName = mod.ShortName
m.ModName = mod.FullName
m.ModName = mod.ShortName
}

// TODO ADD PATH ltree
2 changes: 1 addition & 1 deletion steampipeconfig/modconfig/variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (v *Variable) Name() string {

// QualifiedName returns the name in format: '<modName>.var.<shortName>'
func (v *Variable) QualifiedName() string {
return fmt.Sprintf("%s.%s", v.metadata.ModShortName, v.FullName)
return fmt.Sprintf("%s.%s", v.metadata.ModName, v.FullName)
}

// GetMetadata implements ResourceWithMetadata
Expand Down

0 comments on commit 305ab87

Please sign in to comment.