roots.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c)2019 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2023-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. package cli
  14. import (
  15. "fmt"
  16. "os"
  17. "zerotier/pkg/zerotier"
  18. )
  19. // Roots CLI command
  20. func Roots(basePath, authToken string, args []string, jsonOutput bool) {
  21. var roots []zerotier.Root
  22. apiGet(basePath, authToken, "/root", &roots)
  23. if jsonOutput {
  24. fmt.Println(jsonDump(roots))
  25. } else {
  26. fmt.Printf("%32s <address> <physical/virtual>\n", "<name>")
  27. for _, r := range roots {
  28. rn := r.Name
  29. if len(rn) > 32 {
  30. rn = rn[len(rn)-32:]
  31. }
  32. if r.Locator != nil {
  33. if len(r.Locator.Physical) == 0 && len(r.Locator.Virtual) == 0 {
  34. fmt.Printf("%32s %.10x -\n", rn, uint64(r.Locator.Identity.Address()))
  35. } else {
  36. fmt.Printf("%32s %.10x ", rn, uint64(r.Locator.Identity.Address()))
  37. for i, a := range r.Locator.Physical {
  38. if i > 0 {
  39. fmt.Print(",")
  40. }
  41. fmt.Print(a.String())
  42. }
  43. for i, a := range r.Locator.Virtual {
  44. if i > 0 || len(r.Locator.Physical) > 0 {
  45. fmt.Print(",")
  46. }
  47. fmt.Print(a.String())
  48. }
  49. fmt.Printf("\n")
  50. }
  51. } else {
  52. fmt.Printf("%32s - -\n", rn)
  53. }
  54. }
  55. }
  56. os.Exit(0)
  57. }