list.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package acl
  2. import (
  3. "os"
  4. "github.com/gravitl/netmaker/cli/functions"
  5. "github.com/gravitl/netmaker/logic/acls"
  6. "github.com/guumaster/tablewriter"
  7. "github.com/spf13/cobra"
  8. )
  9. var aclListCmd = &cobra.Command{
  10. Use: "list [NETWORK NAME]",
  11. Args: cobra.ExactArgs(1),
  12. Short: "List all ACLs associated with a network",
  13. Long: `List all ACLs associated with a network`,
  14. Run: func(cmd *cobra.Command, args []string) {
  15. aclSource := (map[acls.AclID]acls.ACL)(*functions.GetACL(args[0]))
  16. table := tablewriter.NewWriter(os.Stdout)
  17. table.SetHeader([]string{"From", "To", "Status"})
  18. for id, acl := range aclSource {
  19. for k, v := range (map[acls.AclID]byte)(acl) {
  20. row := []string{string(id), string(k)}
  21. switch v {
  22. case acls.NotAllowed:
  23. row = append(row, "Not Allowed")
  24. case acls.NotPresent:
  25. row = append(row, "Not Present")
  26. case acls.Allowed:
  27. row = append(row, "Allowed")
  28. }
  29. table.Append(row)
  30. }
  31. }
  32. table.Render()
  33. },
  34. }
  35. func init() {
  36. rootCmd.AddCommand(aclListCmd)
  37. }