list.go 1.2 KB

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