This commit is contained in:
Adam Ierymenko 2019-09-30 20:31:48 -07:00
parent 63e6693255
commit 1711cced3e
No known key found for this signature in database
GPG Key ID: C8877CF2D7A5D7F3
3 changed files with 50 additions and 2 deletions

View File

@ -13,6 +13,51 @@
package cli package cli
import (
"fmt"
"os"
"zerotier/pkg/zerotier"
)
// Roots CLI command // Roots CLI command
func Roots(basePath, authToken string, args []string) { func Roots(basePath, authToken string, args []string, jsonOutput bool) {
var roots []zerotier.Root
apiGet(basePath, authToken, "/root", &roots)
if jsonOutput {
fmt.Println(jsonDump(roots))
} else {
fmt.Printf("%32s <ztaddr> <address(es)>\n", "<name>")
for _, r := range roots {
rn := r.Name
if len(rn) > 32 {
rn = rn[len(rn)-32:]
}
if r.Locator != nil {
if len(r.Locator.Physical) == 0 && len(r.Locator.Virtual) == 0 {
fmt.Printf("%32s %.10x -\n", rn, uint64(r.Locator.Identity.Address()))
} else {
fmt.Printf("%32s %.10x ", rn, uint64(r.Locator.Identity.Address()))
for i, a := range r.Locator.Physical {
if i > 0 {
fmt.Print(',')
}
fmt.Print(a.String())
}
for i, a := range r.Locator.Virtual {
if i > 0 || len(r.Locator.Physical) > 0 {
fmt.Print(',')
}
fmt.Print(a.String())
}
fmt.Printf("\n")
}
} else {
fmt.Printf("%32s - -\n", rn)
}
}
}
os.Exit(0)
} }

View File

@ -115,7 +115,7 @@ func main() {
cli.Peers(basePath, authToken, cmdArgs, *jflag) cli.Peers(basePath, authToken, cmdArgs, *jflag)
case "roots", "listroots", "listmoons": case "roots", "listroots", "listmoons":
authTokenRequired(authToken) authTokenRequired(authToken)
cli.Roots(basePath, authToken, cmdArgs) cli.Roots(basePath, authToken, cmdArgs, *jflag)
case "addroot": case "addroot":
authTokenRequired(authToken) authTokenRequired(authToken)
cli.AddRoot(basePath, authToken, cmdArgs) cli.AddRoot(basePath, authToken, cmdArgs)

View File

@ -118,6 +118,9 @@ func NewIdentityFromString(s string) (*Identity, error) {
return &id, nil return &id, nil
} }
// Address returns this identity's address
func (id *Identity) Address() Address { return id.address }
// HasPrivate returns true if this identity has its own private portion. // HasPrivate returns true if this identity has its own private portion.
func (id *Identity) HasPrivate() bool { return len(id.privateKey) > 0 } func (id *Identity) HasPrivate() bool { return len(id.privateKey) > 0 }