visualize

package
v0.1.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2023 License: Apache-2.0 Imports: 20 Imported by: 1

Documentation

Index

Constants

View Source
const (
	NamespacesKey       = "namespaces"
	NamespacesShorthand = "n"
	GraphFormatKey      = "format"
	OutputPathKey       = "output-path"
	OutputPathShorthand = "o"
)

Variables

View Source
var VisualizeCmd = &cobra.Command{
	Use:   "visualize",
	Short: "Visualize an access graph for network mapper intents using go-graphviz",
	Args:  cobra.NoArgs,
	RunE: func(cmd *cobra.Command, args []string) error {
		return mapperclient.WithClient(func(c *mapperclient.Client) error {
			namespacesFilter := viper.GetStringSlice(NamespacesKey)
			format := viper.GetString(GraphFormatKey)
			graphFormat, err := getGraphvizFormat(format)
			if err != nil {
				return err
			}

			outputFilepath := viper.GetString(OutputPathKey)
			servicesIntents, err := c.ServiceIntents(context.Background(), namespacesFilter)
			if err != nil {
				return err
			}
			visualizer := NewVisualizer(graphFormat)
			defer func() {
				if err := visualizer.graph.Close(); err != nil {
					panic(err)
				}
				if err := visualizer.graphviz.Close(); err != nil {
					panic(err)
				}
			}()

			if err := visualizer.populateNodeCache(servicesIntents); err != nil {
				return err
			}
			if err := visualizer.buildEdges(servicesIntents); err != nil {
				return err
			}
			outputData, err := visualizer.renderOutputByFormat(graphFormat)
			if err != nil {
				return err
			}

			outputFile, err := os.Create(outputFilepath)
			if err != nil {
				return err
			}
			defer outputFile.Close()

			_, err = outputFile.Write(outputData)
			if err != nil {
				return err
			}

			output.PrintStderr("Exported graph as %s format to path %s", format, outputFilepath)
			return nil
		})
	},
}

Functions

This section is empty.

Types

type Visualizer

type Visualizer struct {
	// contains filtered or unexported fields
}

func NewVisualizer

func NewVisualizer(format graphviz.Format) *Visualizer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL