Files
tailscale/feature/serviceclientprefs/serviceclient/serviceclient.go
T
Rollie MaandGitHub f4978b4b9b feature,client: add serviceclientprefs for desktop client service launch (#20501)
Add serviceclientprefs, an optional feature that stores and loads the
desktop clients' saved service launch preferences, one file per login
profile.

- Add GET|POST /localapi/v0/prefs/service-clients to load and save the
  current profile's service client prefs.
- Add local client GetServiceClientPrefs and SetServiceClientPref that
  call the new local api endpoint.
- Store the prefs with the ipn/store FileStore at
  TailscaleVarRoot()/profile-data/<profileID>/service-client-prefs/<hex-encoded-key>,
  so DeleteProfile cleans them up for free. Fall back to an in-memory
  store when there's no var root.
- Register the feature and its local api route from build tagged files
  so the whole thing drops out under ts_omit_serviceclientprefs.
- Add the serviceclient package holding Pref and Prefs (saved client,
  username, database name, and last used time), so the local api client
  and desktop apps can import the types without the feature machinery.

Change-Id: I340a99c1b332d181fb1556fbf3e8003bb3b95a08
Updates: https://github.com/tailscale/tailscale/issues/20429

Signed-off-by: Rollie Ma <rollie@tailscale.com>
2026-07-22 20:36:05 -07:00

36 lines
1.4 KiB
Go

// Copyright (c) Tailscale Inc & contributors
// SPDX-License-Identifier: BSD-3-Clause
// Package serviceclient holds the types for the desktop clients' saved service launch preferences.
// They're shared by the serviceclientprefs feature and the LocalAPI client.
package serviceclient
import (
"time"
)
// Prefs maps a service key to the user's saved preferences for that service.
// Keys are "<serviceName>:<port>" where serviceName is a [tailcfg.ServiceName]
// (e.g. key "svc:my-db:5432" for service "svc:my-db" on port 5432).
type Prefs map[string]Pref
// Pref captures the saved preferences for one service.
type Pref struct {
// Client is the saved client identifier the user picked in the last service launch,
// for example, terminal/putty/iterm2/... for SSH, and dbeaver/psql/mycli/... for
// database. Empty means no client has been saved for this service.
Client string `json:",omitzero"`
// Username is the saved login name for SSH and future services that require username.
// Empty means none saved.
Username string `json:",omitzero"`
// DatabaseName is the saved DB name (database service types). Empty means none saved.
DatabaseName string `json:",omitzero"`
// LastUsed is when this service was last launched. Zero means never.
// When the macOS and Windows apps generate a "recently used" list, they sort by
// LastUsed descending.
LastUsed time.Time `json:",omitzero"`
}