platform: Add tailscale device name and logout

This commit is contained in:
世界
2026-06-02 11:29:06 +08:00
parent 1ee172f6af
commit dcbb8271f8
15 changed files with 299 additions and 121 deletions
+12
View File
@@ -881,6 +881,18 @@ func (c *CommandClient) SetTailscaleExitNode(endpointTag string, stableID string
return nil
}
func (c *CommandClient) TailscaleLogout(endpointTag string) error {
_, err := callWithResult(c, func(ctx context.Context, client daemon.StartedServiceClient) (*emptypb.Empty, error) {
return client.TailscaleLogout(ctx, &daemon.TailscaleLogoutRequest{
EndpointTag: endpointTag,
})
})
if err != nil {
return E.Cause(err, "tailscale logout")
}
return nil
}
func (c *CommandClient) StartTailscalePing(endpointTag string, peerIP string, handler TailscalePingHandler) (*TailscalePingSession, error) {
client, parentCtx, err := c.getClientForCall()
if err != nil {
@@ -23,6 +23,7 @@ type TailscaleEndpointStatus struct {
MagicDNSSuffix string
Self *TailscalePeer
ExitNode *TailscalePeer
KeyAuth bool
userGroups []*TailscaleUserGroup
}
@@ -107,6 +108,7 @@ func tailscaleEndpointStatusFromGRPC(status *daemon.TailscaleEndpointStatus) *Ta
AuthURL: status.AuthURL,
NetworkName: status.NetworkName,
MagicDNSSuffix: status.MagicDNSSuffix,
KeyAuth: status.GetKeyAuth(),
userGroups: userGroups,
}
if status.Self != nil {
+4
View File
@@ -187,6 +187,10 @@ func (s *platformInterfaceStub) ReadSystemSSHHostKey() ([]byte, error) {
return nil, os.ErrInvalid
}
func (s *platformInterfaceStub) TailscaleHostname() string {
return ""
}
func (s *platformInterfaceStub) LookupUser(username string) (*adapter.PlatformUser, error) {
return nil, os.ErrInvalid
}
+3 -2
View File
@@ -25,8 +25,9 @@ type PlatformInterface interface {
CheckPlatformShell() error
OpenShellSession(user *PlatformUser, command string, environ StringIterator, term string, rows int32, cols int32) (ShellSession, error)
LookupUser(username string) (*PlatformUser, error)
LookupSFTPServer() (*StringBox, error)
ReadSystemSSHHostKey() (*StringBox, error)
LookupSFTPServer() (string, error)
ReadSystemSSHHostKey() (string, error)
TailscaleHostname() string
}
type PlatformUser struct {
+6 -6
View File
@@ -274,11 +274,7 @@ func (w *platformInterfaceWrapper) OpenShellSession(user *adapter.PlatformUser,
}
func (w *platformInterfaceWrapper) LookupSFTPServer() (string, error) {
result, err := w.iif.LookupSFTPServer()
if err != nil {
return "", err
}
return result.Value, nil
return w.iif.LookupSFTPServer()
}
func (w *platformInterfaceWrapper) ReadSystemSSHHostKey() ([]byte, error) {
@@ -286,7 +282,11 @@ func (w *platformInterfaceWrapper) ReadSystemSSHHostKey() ([]byte, error) {
if err != nil {
return nil, err
}
return []byte(result.Value), nil
return []byte(result), nil
}
func (w *platformInterfaceWrapper) TailscaleHostname() string {
return w.iif.TailscaleHostname()
}
func (w *platformInterfaceWrapper) LookupUser(username string) (*adapter.PlatformUser, error) {