visualize

package
v0.1.15 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: Apache-2.0 Imports: 19 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.Close(); err != nil {
					panic(err)
				}
			}()

			if err := visualizer.populateNodeCache(servicesIntents); err != nil {
				return err
			}
			if err := visualizer.buildEdges(servicesIntents); err != nil {
				return err
			}
			outputImg, err := visualizer.RenderImage(visualizer.graph)
			if err != nil {
				return err
			}
			watermarkedImg, err := visualizer.addWatermark(outputImg)
			if err != nil {
				return err
			}

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

			_, err = outputFile.Write(outputImgBytes)
			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 {
	*graphviz.Graphviz
	// 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