removeroot.go 938 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. "net/http"
  17. "net/url"
  18. "os"
  19. "strings"
  20. "zerotier/pkg/zerotier"
  21. )
  22. // RemoveRoot CLI command
  23. func RemoveRoot(basePath, authToken string, args []string) {
  24. if len(args) != 1 {
  25. Help()
  26. os.Exit(1)
  27. }
  28. result, _ := zerotier.APIDelete(basePath, zerotier.APISocketName, authToken, "/root/"+url.PathEscape(strings.TrimSpace(args[0])), nil)
  29. if result == http.StatusOK {
  30. fmt.Printf("%s removed\n", args[0])
  31. os.Exit(0)
  32. }
  33. fmt.Printf("ERROR: root %s not found or another error occurred: status code %d\n", args[0], result)
  34. os.Exit(1)
  35. }