Skip to content

Commit

Permalink
Rename from 'InfraView' to 'InfraMap'
Browse files Browse the repository at this point in the history
  • Loading branch information
xescugc committed Jul 13, 2020
1 parent 6e9184a commit 245b610
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 72 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You also need to install other code dependencies not mandatory in the runtime en

To add a new Provider you need to follow the `provider.Provider` interface and create it on the `provider/{provider_name}`, also add it to the `provider.Type` list and then run `make generate`. Basically you can also check any of the other providers that we already have.

To add a new test we recommend to run the `inframap prune --canonicals --tfstate [FILE]` and add the test to the `infraview/testdata/` and add a new test to the `infraview/graph_test.go`
To add a new test we recommend to run the `inframap prune --canonicals --tfstate [FILE]` and add the test to the `generate/testdata/` and add a new test to the `generate/graph_test.go`

#### Add a new Printer

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
BIN := infraview
BIN := inframap
TOOL_BIN := $(PWD)/bin

GOLINT := $(TOOL_BIN)/golint
Expand All @@ -8,7 +8,7 @@ ENUMER := $(TOOL_BIN)/enumer
VERSION= $(shell git describe --tags --always)

# Setup the -ldflags option for go build here, interpolate the variable values
LDFLAGS=-ldflags "-X github.com/cycloidio/infraview/cmd.Version=${VERSION}"
LDFLAGS=-ldflags "-X github.com/cycloidio/inframap/cmd.Version=${VERSION}"

.PHONY: help
help: Makefile ## This help dialog
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ You can build and install with the latest sources, you will enjoy the new featur
```shell
$ git clone https://github.com/cycloidio/inframap
$ cd inframap
$ go mod download
```

## Usage
Expand Down
10 changes: 5 additions & 5 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"strings"

"github.com/cycloidio/infraview/infraview"
"github.com/cycloidio/infraview/printer"
"github.com/cycloidio/inframap/generate"
"github.com/cycloidio/inframap/printer"
"github.com/spf13/cobra"
)

Expand All @@ -20,16 +20,16 @@ var (
Use: "generate [FILE]",
Short: "Generates the Graph",
Long: "Generates the Graph from TFState or HCL",
Example: "infraview generate --tfstate state.json",
Example: "inframap generate --tfstate state.json",
Args: cobra.MaximumNArgs(1),
PreRunE: preRunFile,
RunE: func(cmd *cobra.Command, args []string) error {
if tfstate {
opt := infraview.GenerateOptions{
opt := generate.Options{
Raw: raw,
Clean: clean,
}
g, _, err := infraview.FromState(file, opt)
g, _, err := generate.FromState(file, opt)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"errors"
"fmt"

"github.com/cycloidio/infraview/infraview"
"github.com/cycloidio/inframap/prune"
"github.com/spf13/cobra"
)

Expand All @@ -14,12 +14,12 @@ var (
Use: "prune [FILE]",
Short: "Prunes the file",
Long: "Prunes the TFState or HCL file",
Example: "infraview prune --tfstate state.json",
Example: "inframap prune --tfstate state.json",
Args: cobra.MaximumNArgs(1),
PreRunE: preRunFile,
RunE: func(cmd *cobra.Command, args []string) error {
if tfstate {
s, err := infraview.Prune(file, canonicals)
s, err := prune.Prune(file, canonicals)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var (
file []byte

rootCmd = &cobra.Command{
Use: "infraview",
Use: "inframap",
Short: "Reads the TFState or HCL to generate a Graphical view",
Long: "Reads the TFState or HCL to generate a Graphical view with Nodes and Edges.",
}
Expand Down
10 changes: 5 additions & 5 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"regexp"
"strings"

"github.com/cycloidio/infraview/errcode"
"github.com/cycloidio/infraview/provider"
"github.com/cycloidio/infraview/provider/aws"
"github.com/cycloidio/infraview/provider/flexibleengine"
"github.com/cycloidio/infraview/provider/openstack"
"github.com/cycloidio/inframap/errcode"
"github.com/cycloidio/inframap/provider"
"github.com/cycloidio/inframap/provider/aws"
"github.com/cycloidio/inframap/provider/flexibleengine"
"github.com/cycloidio/inframap/provider/openstack"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions infraview/connection.go → generate/connection.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package infraview
package generate

import (
"github.com/cycloidio/infraview/graph"
"github.com/cycloidio/inframap/graph"
)

type direction int
Expand All @@ -26,7 +26,7 @@ type connection struct {

// findEdgeConnections for each edge on n returns the closest connection to a Node.
// The last 'connection' on the []*connection will be a valid provider Node
func findEdgeConnections(g *graph.Graph, n *graph.Node, visited map[string]struct{}, opt GenerateOptions) ([][]*connection, error) {
func findEdgeConnections(g *graph.Graph, n *graph.Node, visited map[string]struct{}, opt Options) ([][]*connection, error) {
res := make([][]*connection, 0)
edges := g.GetEdgesForNode(n.ID)
for _, e := range edges {
Expand Down Expand Up @@ -82,7 +82,7 @@ func findEdgeConnections(g *graph.Graph, n *graph.Node, visited map[string]struc
}

// getShortestNodePath get the shortest path to a Node starting from n
func getShortestNodePath(g *graph.Graph, n *graph.Node, visited map[string]struct{}, opt GenerateOptions) ([]*connection, error) {
func getShortestNodePath(g *graph.Graph, n *graph.Node, visited map[string]struct{}, opt Options) ([]*connection, error) {
edges, err := findEdgeConnections(g, n, visited, opt)
if err != nil {
return nil, err
Expand Down
28 changes: 14 additions & 14 deletions infraview/generate.go → generate/generate.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package infraview
package generate

import (
"bytes"
Expand All @@ -8,18 +8,18 @@ import (
"regexp"
"strings"

"github.com/cycloidio/infraview/errcode"
"github.com/cycloidio/infraview/factory"
"github.com/cycloidio/infraview/graph"
"github.com/cycloidio/infraview/provider"
"github.com/cycloidio/inframap/errcode"
"github.com/cycloidio/inframap/factory"
"github.com/cycloidio/inframap/graph"
"github.com/cycloidio/inframap/provider"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/states/statefile"
uuid "github.com/satori/go.uuid"
)

// GenerateOptions are the possible options
// Options are the possible options
// that can be used to generate a Graph
type GenerateOptions struct {
type Options struct {
// Raw means the RawProvider instead of the
// specific one
Raw bool
Expand All @@ -30,7 +30,7 @@ type GenerateOptions struct {
}

// FromState generate a graph.Graph from the tfstate applying the opt
func FromState(tfstate json.RawMessage, opt GenerateOptions) (*graph.Graph, map[string]interface{}, error) {
func FromState(tfstate json.RawMessage, opt Options) (*graph.Graph, map[string]interface{}, error) {
buf := bytes.NewBuffer(tfstate)
file, err := statefile.Read(buf)
if err != nil {
Expand Down Expand Up @@ -182,7 +182,7 @@ func FromState(tfstate json.RawMessage, opt GenerateOptions) (*graph.Graph, map[
// The only case in which this happens is when an Edge is connected to the internet
// in which then it has N->E without another Node to connect with (which would be internet)
// it is a usecase we do not support now so we remove them
func cleanHangingEdges(g *graph.Graph, opt GenerateOptions) error {
func cleanHangingEdges(g *graph.Graph, opt Options) error {
for _, n := range g.Nodes {
pv, rs, err := getProviderAndResource(n.Canonical, opt)
if err != nil {
Expand Down Expand Up @@ -278,7 +278,7 @@ var reSG = regexp.MustCompile(`\$\{(?P<type>[^\.][a-z0-9-_]+)\.(?P<name>[^\.][a-
// This would mean that in case of AWS it'll read the Config and if it's a SG it'll
// read the actual direction of it and apply it and potentially changing the Edges
// directions
func fixEdges(g *graph.Graph, cfg map[string]map[string]interface{}, opt GenerateOptions) error {
func fixEdges(g *graph.Graph, cfg map[string]map[string]interface{}, opt Options) error {
for _, n := range g.Nodes {
pv, rs, err := getProviderAndResource(n.Canonical, opt)
if err != nil {
Expand Down Expand Up @@ -365,7 +365,7 @@ func sumConnsDirection(conns []*connection) int {

// mutate will mutate the Graph by merging the Nodes that are Edges on the Provider they belong
// with the actual Nodes, at the end it'll leave a Graph with just Nodes (Provider Nodes)
func mutate(g *graph.Graph, opt GenerateOptions) error {
func mutate(g *graph.Graph, opt Options) error {
conns := make(map[string][]*connection)
var bestNode *graph.Node
var bestNodeConns []*connection
Expand Down Expand Up @@ -492,9 +492,9 @@ func instanceCurrentDependsOnToString(deps []addrs.Referenceable) []string {
return res
}

// getProviderAndResource uses factory.GenerateOptions but if the opt.Raw is defined
// getProviderAndResource uses factory.Options but if the opt.Raw is defined
// it'll return the RawProvider. It's a helper to not repeat all time the same logic
func getProviderAndResource(rk string, opt GenerateOptions) (provider.Provider, string, error) {
func getProviderAndResource(rk string, opt Options) (provider.Provider, string, error) {
var (
pv provider.Provider
rs string
Expand All @@ -513,7 +513,7 @@ func getProviderAndResource(rk string, opt GenerateOptions) (provider.Provider,

// checkProviders checks if we support any of the Providers from f, if not it'll set
// the opt.Raw to true so it can be used with Raw instead of returning an empty Graph
func checkProviders(f *statefile.File, opt GenerateOptions) (GenerateOptions, error) {
func checkProviders(f *statefile.File, opt Options) (Options, error) {
for _, v := range f.State.Modules {
for rk, rv := range v.Resources {
// If it's not a Resource we ignore it
Expand Down
22 changes: 11 additions & 11 deletions infraview/generate_test.go → generate/generate_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package infraview_test
package generate_test

import (
"io/ioutil"
"testing"

"github.com/cycloidio/infraview/graph"
"github.com/cycloidio/infraview/infraview"
"github.com/cycloidio/inframap/generate"
"github.com/cycloidio/inframap/graph"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -15,7 +15,7 @@ func TestFromState_AWS(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/aws_sg.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand Down Expand Up @@ -53,7 +53,7 @@ func TestFromState_AWS(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/aws_sgr.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestFromState_AWS(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/aws_with_count.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand All @@ -112,7 +112,7 @@ func TestFromState_OpenStack(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/openstack_lb.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestFromState_OpenStack(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/openstack_sg.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestFromState_FlexibelEngine(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/flexibleengine.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestFromState_FlexibelEngine(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/flexibleengine_tf_011.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestFromState_FlexibelEngine(t *testing.T) {
src, err := ioutil.ReadFile("./testdata/flexibleengine_attach.json")
require.NoError(t, err)

g, cfg, err := infraview.FromState(src, infraview.GenerateOptions{Clean: true})
g, cfg, err := generate.FromState(src, generate.Options{Clean: true})
require.NoError(t, err)
require.NotNil(t, g)
require.NotNil(t, cfg)
Expand Down
4 changes: 2 additions & 2 deletions infraview/helper_test.go → generate/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package infraview_test
package generate_test

import (
"fmt"
"sort"
"testing"

"github.com/cycloidio/infraview/graph"
"github.com/cycloidio/inframap/graph"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cycloidio/infraview
module github.com/cycloidio/inframap

go 1.14

Expand Down
2 changes: 1 addition & 1 deletion graph/edge.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package graph

import (
"github.com/cycloidio/infraview/errcode"
"github.com/cycloidio/inframap/errcode"
)

// Edge defines the standard format of an Edge
Expand Down
4 changes: 2 additions & 2 deletions graph/edge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package graph_test
import (
"testing"

"github.com/cycloidio/infraview/errcode"
"github.com/cycloidio/infraview/graph"
"github.com/cycloidio/inframap/errcode"
"github.com/cycloidio/inframap/graph"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package graph
import (
"fmt"

"github.com/cycloidio/infraview/errcode"
"github.com/cycloidio/inframap/errcode"
)

// Graph defines the standard format of a Graph
Expand Down
4 changes: 2 additions & 2 deletions graph/graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"sort"
"testing"

"github.com/cycloidio/infraview/errcode"
"github.com/cycloidio/infraview/graph"
"github.com/cycloidio/inframap/errcode"
"github.com/cycloidio/inframap/graph"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
Binary file added inframap
Binary file not shown.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/cycloidio/infraview/cmd"
"github.com/cycloidio/inframap/cmd"
)

func main() {
Expand Down
Loading

0 comments on commit 245b610

Please sign in to comment.