This commit is contained in:
Adam Ierymenko 2019-09-24 16:44:29 -07:00
parent e3d47e588a
commit e5bd230fb0
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
15 changed files with 197 additions and 42 deletions

View file

@ -13,6 +13,37 @@
package cli
import (
"encoding/json"
"fmt"
"net/http"
"os"
"zerotier/pkg/zerotier"
)
// Status shows service status info
func Status(args []string) {
func Status(basePath, authToken string, args []string, jsonOutput bool) {
var status zerotier.APIStatus
statusCode, err := zerotier.APIGet(basePath, zerotier.APISocketName, authToken, "/status", &status)
if err != nil {
fmt.Printf("FATAL: API response code %d: %s\n", statusCode, err.Error())
os.Exit(1)
return
}
if statusCode != http.StatusOK {
if statusCode == http.StatusUnauthorized {
fmt.Printf("FATAL: API response code %d: unauthorized (authorization token incorrect)\n", statusCode)
}
fmt.Printf("FATAL: API response code %d\n", statusCode)
os.Exit(1)
return
}
if jsonOutput {
j, _ := json.MarshalIndent(&status, "", " ")
fmt.Println(string(j))
} else {
}
os.Exit(0)
}