Skip to content

Commit

Permalink
chore(go): update golang version to 1.23
Browse files Browse the repository at this point in the history
Signed-off-by: Yago Riveiro <[email protected]>
  • Loading branch information
yriveiro committed Sep 3, 2024
1 parent 4be7473 commit 2dcf3e9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module rover

go 1.21
go 1.23

require (
github.com/chromedp/cdproto v0.0.0-20211205231339-d2673e93eee4
Expand Down
17 changes: 6 additions & 11 deletions graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,17 @@ func (r *rover) GenerateGraph() error {
}

func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, resources map[string]*Resource) []string {

nmo := []string{}

for id, re := range resources {

if re.Type == ResourceTypeResource || re.Type == ResourceTypeData {

pid := parent

if nodeMap[parent].Data.Type == ResourceTypeFile {
pid = strings.TrimSuffix(pid, nodeMap[parent].Data.Label)
pid = strings.TrimSuffix(pid, ".")
//qfmt.Printf("%v\n", pid)
// qfmt.Printf("%v\n", pid)
}

mid := fmt.Sprintf("%v.%v", pid, re.ResourceType)
Expand All @@ -122,7 +120,7 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re
mid = fmt.Sprintf("%s {%s}", mid, nodeMap[parent].Data.Label)
}

//fmt.Printf(midParent + " - " + mid + "\n")
// fmt.Printf(midParent + " - " + mid + "\n")

// Append resource type
nmo = append(nmo, mid)
Expand Down Expand Up @@ -152,7 +150,7 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re
},
Classes: fmt.Sprintf("%s-name %s", re.Type, mrChange),
}
//fmt.Printf(id + " - " + mid + "\n")
// fmt.Printf(id + " - " + mid + "\n")

nmo = append(nmo, r.addNodes(base, id, nodeMap, re.Children)...)

Expand All @@ -161,7 +159,7 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re
if parent != base {
fid = fmt.Sprintf("%s.%s", parent, fid)
}
//fmt.Printf("%v\n", fid)
// fmt.Printf("%v\n", fid)
nmo = append(nmo, fid)
nodeMap[fid] = Node{
Data: NodeData{
Expand All @@ -187,7 +185,7 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re
ls := strings.Split(id, ".")
label := ls[len(ls)-1]

//fmt.Printf("%v - %v\n", id, re.Type)
// fmt.Printf("%v - %v\n", id, re.Type)

nmo = append(nmo, id)
nodeMap[id] = Node{
Expand All @@ -205,16 +203,13 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re
nmo = append(nmo, r.addNodes(base, id, nodeMap, re.Children)...)

}

}

return nmo

}

// GenerateNodes -
func (r *rover) GenerateNodes() []Node {

nodeMap := make(map[string]Node)
nmo := []string{}

Expand Down Expand Up @@ -336,7 +331,7 @@ func (r *rover) GenerateEdges() []Edge {
edgeMap := make(map[string]Edge)
emo := []string{}

//config := r.Plan.Config.RootModule
// config := r.Plan.Config.RootModule

emo = append(emo, r.addEdges("", "", edgeMap, r.Map.Root)...)

Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"errors"
"flag"
"fmt"
"io"
"io/fs"
"io/ioutil"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -174,7 +174,6 @@ func main() {
log.Fatalf("Could not start server: %s\n", err.Error())
}
}

}

func (r *rover) generateAssets() error {
Expand Down Expand Up @@ -204,7 +203,7 @@ func (r *rover) generateAssets() error {
}

func (r *rover) getPlan() error {
tmpDir, err := ioutil.TempDir("", "rover")
tmpDir, err := os.MkdirTemp("", "rover")
if err != nil {
return err
}
Expand Down Expand Up @@ -235,7 +234,7 @@ func (r *rover) getPlan() error {
}
defer planJsonFile.Close()

planJson, err := ioutil.ReadAll(planJsonFile)
planJson, err := io.ReadAll(planJsonFile)
if err != nil {
return errors.New(fmt.Sprintf("Unable to read Plan (%s): %s", r.PlanJSONPath, err))
}
Expand Down
11 changes: 4 additions & 7 deletions map.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
tfjson "github.com/hashicorp/terraform-json"
)

type Action string
type ResourceType string
type (
Action string
ResourceType string
)

const (
ResourceTypeFile ResourceType = "file"
Expand Down Expand Up @@ -84,7 +86,6 @@ type ModuleCall struct {
}

func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) {

childIndex := regexp.MustCompile(`\[[^[\]]*\]$`)
matchBrackets := regexp.MustCompile(`\[[^\[\]]*\]`)

Expand Down Expand Up @@ -239,7 +240,6 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) {
}

} else {

parent.Children[id] = re
}

Expand Down Expand Up @@ -290,7 +290,6 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) {

} else {
parent.Children[rid] = ref

}
}
}
Expand All @@ -301,9 +300,7 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) {
}

func (r *rover) AddFileIfNotExists(module *Resource, parentModule string, fname string) {

if _, ok := module.Children[fname]; !ok {

module.Children[fname] = &Resource{
Type: ResourceTypeFile,
Name: fname,
Expand Down
24 changes: 11 additions & 13 deletions rso.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package main
import (
"encoding/json"
"fmt"
"github.com/hashicorp/terraform-config-inspect/tfconfig"
tfjson "github.com/hashicorp/terraform-json"
"io/ioutil"
"io"
"log"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/hashicorp/terraform-config-inspect/tfconfig"
tfjson "github.com/hashicorp/terraform-json"
)

// ResourcesOverview represents the root module
Expand Down Expand Up @@ -45,7 +46,7 @@ type ModuleLocations struct {
}

type ModuleLocation struct {
Key string `json:"Key,omitempty""`
Key string `json:"Key,omitempty"`
Source string `json:"Source,omitempty"`
Dir string `json:"Dir,omitempty"`
}
Expand All @@ -54,7 +55,6 @@ type ModuleLocation struct {
// The module locations are then added to rso.Locations and referenced when loading
// modules from the filesystem with tfconfig.LoadModule
func (r *rover) PopulateModuleLocations(moduleJSONFile string, locations map[string]string) {

moduleLocations := ModuleLocations{}

jsonFile, err := os.Open(moduleJSONFile)
Expand All @@ -64,20 +64,19 @@ func (r *rover) PopulateModuleLocations(moduleJSONFile string, locations map[str
defer jsonFile.Close()

// read our opened jsonFile as a byte array.
byteValue, _ := ioutil.ReadAll(jsonFile)
byteValue, _ := io.ReadAll(jsonFile)

// we unmarshal our byteArray which contains our
// jsonFile's content into 'users' which we defined above
json.Unmarshal(byteValue, &moduleLocations)

for _, loc := range moduleLocations.Locations {
locations[loc.Key] = fmt.Sprintf("%s/%s", r.WorkingDir, loc.Dir)
//fmt.Printf("%v\n", loc.Dir)
// fmt.Printf("%v\n", loc.Dir)
}
}

func (r *rover) PopulateConfigs(parent string, parentKey string, rso *ResourcesOverview, config *tfjson.ConfigModule) {

ml := rso.Locations
rc := rso.Configs

Expand Down Expand Up @@ -114,7 +113,7 @@ func (r *rover) PopulateConfigs(parent string, parentKey string, rso *ResourcesO
}

rc[address].ResourceConfig = resource
//rc[address].DependsOn = resource.DependsOn
// rc[address].DependsOn = resource.DependsOn

if _, ok := rc[parent]; !ok {
rc[parent] = &ConfigOverview{}
Expand Down Expand Up @@ -162,7 +161,7 @@ func (r *rover) PopulateModuleState(rso *ResourcesOverview, module *tfjson.State
for _, rst := range module.Resources {
id := rst.Address
parent := module.Address
//fmt.Printf("ID: %v\n", id)
// fmt.Printf("ID: %v\n", id)
if rst.AttributeValues != nil {

// Add resource to parent
Expand Down Expand Up @@ -203,7 +202,7 @@ func (r *rover) PopulateModuleState(rso *ResourcesOverview, module *tfjson.State

}

//fmt.Printf("%v - %v\n", id, parent)
// fmt.Printf("%v - %v\n", id, parent)
rs[parent].Children[id] = rs[id]

if prior {
Expand Down Expand Up @@ -257,7 +256,6 @@ func (r *rover) PopulateModuleState(rso *ResourcesOverview, module *tfjson.State

r.PopulateModuleState(rso, childModule, prior)
}

}

// GenerateResourceOverview - Overview of files and their resources
Expand Down Expand Up @@ -321,7 +319,7 @@ func (r *rover) GenerateResourceOverview() error {

// reIsChild := regexp.MustCompile(`^\w+\.\w+[\.\[]`)
// reGetParent := regexp.MustCompile(`^\w+\.\w+`)
//reIsChild := regexp.MustCompile(`^\w+\.[\w-]+[\.\[]`)
// reIsChild := regexp.MustCompile(`^\w+\.[\w-]+[\.\[]`)

// Loop through output changes
for outputName, output := range r.Plan.OutputChanges {
Expand Down
2 changes: 0 additions & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

func (ro *rover) startServer(ipPort string, frontendFS http.Handler) error {

m := http.NewServeMux()
s := http.Server{Addr: ipPort, Handler: m}

Expand Down Expand Up @@ -75,5 +74,4 @@ func (ro *rover) startServer(ipPort string, frontendFS http.Handler) error {

// Start the blocking server loop.
return s.Serve(l)

}

0 comments on commit 2dcf3e9

Please sign in to comment.