leave.go 946 B

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