mirror of
https://github.com/tailscale/tailscale.git
synced 2026-09-20 10:42:17 -04:00
This patch pulls the printing and JSON-encoding out of feature/tailnetlock/tslockjsonv1 into their callers, so that this package only handles type conversions. In cmd/tailscale/cli/tailnet-lock.go, it extracts the printTailnetLockStatus function from runTailnetLockStatus to mirror printTailnetLockLog and runTailnetLockLog. Updates #17613 Signed-off-by: Simon Law <sfllaw@tailscale.com>
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !ts_omit_tailnetlock
|
|
|
|
package tslockjsonv1
|
|
|
|
import (
|
|
"tailscale.com/cmd/tailscale/jsonoutput"
|
|
"tailscale.com/cmd/tailscale/tslockjsonv1"
|
|
"tailscale.com/ipn/ipnstate"
|
|
"tailscale.com/tka"
|
|
)
|
|
|
|
// StatusResponse returns the current Tailnet Lock status as a JSON object to the CLI,
|
|
// in a stable "v1" format.
|
|
func StatusResponse(status *ipnstate.TailnetLockStatus) tslockjsonv1.StatusResponse {
|
|
out := tslockjsonv1.StatusResponse{
|
|
ResponseEnvelope: jsonoutput.ResponseEnvelope{
|
|
SchemaVersion: "1",
|
|
},
|
|
Enabled: status.Enabled,
|
|
}
|
|
if !status.PublicKey.IsZero() {
|
|
out.PublicKey = status.PublicKey.CLIString()
|
|
}
|
|
if nk := status.NodeKey; nk != nil {
|
|
out.NodeKey = nk.String()
|
|
}
|
|
if !status.Enabled {
|
|
return out // Tailnet Lock is disabled, omit the following fields
|
|
}
|
|
|
|
if status.Head != nil {
|
|
var head tka.AUMHash
|
|
h := status.Head
|
|
copy(head[:], h[:])
|
|
out.Head = head.String()
|
|
}
|
|
out.NodeKeySigned = &status.NodeKeySigned
|
|
if sig := status.NodeKeySignature; sig != nil {
|
|
out.NodeKeySignature = nodeKeySignature(sig)
|
|
}
|
|
out.TrustedKeys = []tslockjsonv1.Key{} // never omit this field when enabled
|
|
for _, key := range status.TrustedKeys {
|
|
out.TrustedKeys = append(out.TrustedKeys, ipnTKAKey(&key))
|
|
}
|
|
out.VisiblePeers = []tslockjsonv1.TrustedPeer{} // never omit this field when enabled
|
|
for _, vp := range status.VisiblePeers {
|
|
out.VisiblePeers = append(out.VisiblePeers, trustedPeer(vp))
|
|
}
|
|
out.FilteredPeers = []tslockjsonv1.Peer{} // never omit this field when enabled
|
|
for _, fp := range status.FilteredPeers {
|
|
out.FilteredPeers = append(out.FilteredPeers, peer(fp))
|
|
}
|
|
out.StateID = status.StateID
|
|
return out
|
|
}
|