/
appmeshmeshroute.go
49 lines (45 loc) · 1.4 KB
/
appmeshmeshroute.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"github.com/ArjenSchwarz/awstools/config"
"github.com/ArjenSchwarz/awstools/helpers"
format "github.com/ArjenSchwarz/go-output"
"github.com/spf13/cobra"
)
// meshrouteCmd represents the meshroute command
var meshrouteCmd = &cobra.Command{
Use: "routelist",
Short: "Get an overview of all routes in the mesh",
Long: `This displays all the routes in the mesh`,
Run: meshroute,
}
func init() {
appmeshCmd.AddCommand(meshrouteCmd)
}
func meshroute(cmd *cobra.Command, args []string) {
resultTitle := "Overview of the routes in the mesh"
awsConfig := config.DefaultAwsConfig(*settings)
svc := awsConfig.AppmeshClient()
routes := helpers.GetAllAppMeshPaths(meshname, svc)
keys := []string{"Service", "Path", "Node"}
if settings.IsVerbose() {
keys = append(keys, "Weight")
keys = append(keys, "Router")
}
output := format.OutputArray{Keys: keys, Settings: settings.NewOutputSettings()}
output.Settings.Title = resultTitle
for _, route := range routes {
for _, path := range route.VirtualServiceRoutes {
content := make(map[string]interface{})
content["Service"] = route.VirtualServiceName
content["Path"] = path.Path
content["Node"] = path.DestinationNode
if settings.IsVerbose() {
content["Weight"] = int(path.Weight)
content["Router"] = path.Router
}
holder := format.OutputHolder{Contents: content}
output.AddHolder(holder)
}
}
output.Write()
}