leave.go 1005 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c)2013-2020 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: 2025-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. "strconv"
  17. "zerotier/pkg/zerotier"
  18. )
  19. func Leave(basePath string, authTokenGenerator func() string, args []string) int {
  20. authToken := authTokenGenerator()
  21. if len(args) != 1 {
  22. Help()
  23. return 1
  24. }
  25. if len(args[0]) != zerotier.NetworkIDStringLength {
  26. fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
  27. return 1
  28. }
  29. nwid, err := strconv.ParseUint(args[0], 16, 64)
  30. if err != nil {
  31. fmt.Printf("ERROR: invalid network ID: %s\n", args[0])
  32. return 1
  33. }
  34. nwids := fmt.Sprintf("%.16x", nwid)
  35. apiDelete(basePath, authToken, "/network/"+nwids, nil)
  36. fmt.Printf("OK %s", nwids)
  37. return 0
  38. }