diff --git a/Dockerfile b/Dockerfile index 8c0b36c..6389016 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ COPY ./ui/src ./src RUN NODE_OPTIONS='--openssl-legacy-provider' npm run build # Build rover -FROM golang:1.21 AS rover +FROM golang:1.23 AS rover WORKDIR /src # Copy full source COPY . . diff --git a/go.mod b/go.mod index 60ff13c..15b50f2 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module rover -go 1.21 +go 1.23 require ( github.com/chromedp/cdproto v0.0.0-20211205231339-d2673e93eee4 diff --git a/graph.go b/graph.go index 2490d1f..abf3f2d 100644 --- a/graph.go +++ b/graph.go @@ -89,11 +89,9 @@ 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 @@ -101,7 +99,7 @@ func (r *rover) addNodes(base string, parent string, nodeMap map[string]Node, re 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) @@ -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) @@ -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)...) @@ -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{ @@ -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{ @@ -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{} @@ -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)...) diff --git a/main.go b/main.go index ccf5957..d44f689 100644 --- a/main.go +++ b/main.go @@ -7,8 +7,8 @@ import ( "errors" "flag" "fmt" + "io" "io/fs" - "io/ioutil" "log" "net/http" "os" @@ -174,7 +174,6 @@ func main() { log.Fatalf("Could not start server: %s\n", err.Error()) } } - } func (r *rover) generateAssets() error { @@ -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 } @@ -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)) } diff --git a/map.go b/map.go index 3bb3ba0..cf4e310 100644 --- a/map.go +++ b/map.go @@ -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" @@ -84,7 +86,6 @@ type ModuleCall struct { } func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) { - childIndex := regexp.MustCompile(`\[[^[\]]*\]$`) matchBrackets := regexp.MustCompile(`\[[^\[\]]*\]`) @@ -239,7 +240,6 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) { } } else { - parent.Children[id] = re } @@ -290,7 +290,6 @@ func (r *rover) GenerateModuleMap(parent *Resource, parentModule string) { } else { parent.Children[rid] = ref - } } } @@ -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, diff --git a/rso.go b/rso.go index be9deae..7014fd9 100644 --- a/rso.go +++ b/rso.go @@ -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 @@ -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"` } @@ -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) @@ -64,7 +64,7 @@ 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 @@ -72,12 +72,11 @@ func (r *rover) PopulateModuleLocations(moduleJSONFile string, locations map[str 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 @@ -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{} @@ -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 @@ -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 { @@ -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 @@ -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 { diff --git a/server.go b/server.go index 0c73023..1fcd429 100644 --- a/server.go +++ b/server.go @@ -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} @@ -75,5 +74,4 @@ func (ro *rover) startServer(ipPort string, frontendFS http.Handler) error { // Start the blocking server loop. return s.Serve(l) - }