mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-20 13:24:09 -07:00
addroot
This commit is contained in:
parent
1711cced3e
commit
d1b780c7be
4 changed files with 99 additions and 9 deletions
|
@ -13,6 +13,49 @@
|
|||
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"zerotier/pkg/zerotier"
|
||||
)
|
||||
|
||||
// AddRoot CLI command
|
||||
func AddRoot(basePath, authToken string, args []string) {
|
||||
if len(args) == 0 {
|
||||
Help()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
locData, err := ioutil.ReadFile(args[0])
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: unable to read locator: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
loc, err := zerotier.NewLocatorFromBytes(locData)
|
||||
if err != nil {
|
||||
fmt.Printf("ERROR: invalid locator in file '%s': %s\n", args[0], err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var name string
|
||||
if len(args) > 1 {
|
||||
if len(args) > 2 {
|
||||
Help()
|
||||
os.Exit(1)
|
||||
}
|
||||
name = strings.TrimSpace(args[1])
|
||||
}
|
||||
|
||||
var result zerotier.Root
|
||||
apiPost(basePath, authToken, "/root/"+url.PathEscape(name), &zerotier.Root{
|
||||
Name: name,
|
||||
Locator: loc,
|
||||
}, &result)
|
||||
|
||||
fmt.Println(jsonDump(&result))
|
||||
os.Exit(0)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue