mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-19 19:38:40 +00:00
tailcfg,hostinfo: add App field to identify tsnet uses
This allows us to differentiate between the various tsnet apps that we have like `golinks` and `k8s-operator`. Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
780c56e119
commit
49c206fe1e
@ -99,9 +99,9 @@ func main() {
|
|||||||
tsClient.HTTPClient = credentials.Client(context.Background())
|
tsClient.HTTPClient = credentials.Client(context.Background())
|
||||||
|
|
||||||
if shouldRunAuthProxy {
|
if shouldRunAuthProxy {
|
||||||
hostinfo.SetPackage("k8s-operator-proxy")
|
hostinfo.SetApp("k8s-operator-proxy")
|
||||||
} else {
|
} else {
|
||||||
hostinfo.SetPackage("k8s-operator")
|
hostinfo.SetApp("k8s-operator")
|
||||||
}
|
}
|
||||||
|
|
||||||
s := &tsnet.Server{
|
s := &tsnet.Server{
|
||||||
|
@ -36,6 +36,7 @@ func New() *tailcfg.Hostinfo {
|
|||||||
return &tailcfg.Hostinfo{
|
return &tailcfg.Hostinfo{
|
||||||
IPNVersion: version.Long(),
|
IPNVersion: version.Long(),
|
||||||
Hostname: hostname,
|
Hostname: hostname,
|
||||||
|
App: appTypeCached(),
|
||||||
OS: version.OS(),
|
OS: version.OS(),
|
||||||
OSVersion: GetOSVersion(),
|
OSVersion: GetOSVersion(),
|
||||||
Container: lazyInContainer.Get(),
|
Container: lazyInContainer.Get(),
|
||||||
@ -112,6 +113,13 @@ func GetOSVersion() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func appTypeCached() string {
|
||||||
|
if v, ok := appType.Load().(string); ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func packageTypeCached() string {
|
func packageTypeCached() string {
|
||||||
if v, _ := packagingType.Load().(string); v != "" {
|
if v, _ := packagingType.Load().(string); v != "" {
|
||||||
return v
|
return v
|
||||||
@ -159,6 +167,7 @@ var (
|
|||||||
osVersionAtomic atomic.Value // of string
|
osVersionAtomic atomic.Value // of string
|
||||||
desktopAtomic atomic.Value // of opt.Bool
|
desktopAtomic atomic.Value // of opt.Bool
|
||||||
packagingType atomic.Value // of string
|
packagingType atomic.Value // of string
|
||||||
|
appType atomic.Value // of string
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetPushDeviceToken sets the device token for use in Hostinfo updates.
|
// SetPushDeviceToken sets the device token for use in Hostinfo updates.
|
||||||
@ -176,6 +185,11 @@ func SetOSVersion(v string) { osVersionAtomic.Store(v) }
|
|||||||
// F-Droid build) and tsnet (set to "tsnet").
|
// F-Droid build) and tsnet (set to "tsnet").
|
||||||
func SetPackage(v string) { packagingType.Store(v) }
|
func SetPackage(v string) { packagingType.Store(v) }
|
||||||
|
|
||||||
|
// SetApp sets the app type for the app.
|
||||||
|
// It is used by tsnet to specify what app is using it such as "golinks"
|
||||||
|
// and "k8s-operator".
|
||||||
|
func SetApp(v string) { appType.Store(v) }
|
||||||
|
|
||||||
func deviceModel() string {
|
func deviceModel() string {
|
||||||
s, _ := deviceModelAtomic.Load().(string)
|
s, _ := deviceModelAtomic.Load().(string)
|
||||||
return s
|
return s
|
||||||
|
@ -522,6 +522,9 @@ type Hostinfo struct {
|
|||||||
DistroVersion string `json:",omitempty"` // "20.04", ...
|
DistroVersion string `json:",omitempty"` // "20.04", ...
|
||||||
DistroCodeName string `json:",omitempty"` // "jammy", "bullseye", ...
|
DistroCodeName string `json:",omitempty"` // "jammy", "bullseye", ...
|
||||||
|
|
||||||
|
// App is used to disambiguate Tailscale clients that run using tsnet.
|
||||||
|
App string `json:",omitempty"` // "k8s-operator", "golinks", ...
|
||||||
|
|
||||||
Desktop opt.Bool `json:",omitempty"` // if a desktop was detected on Linux
|
Desktop opt.Bool `json:",omitempty"` // if a desktop was detected on Linux
|
||||||
Package string `json:",omitempty"` // Tailscale package to disambiguate ("choco", "appstore", etc; "" for unknown)
|
Package string `json:",omitempty"` // Tailscale package to disambiguate ("choco", "appstore", etc; "" for unknown)
|
||||||
DeviceModel string `json:",omitempty"` // mobile phone model ("Pixel 3a", "iPhone12,3")
|
DeviceModel string `json:",omitempty"` // mobile phone model ("Pixel 3a", "iPhone12,3")
|
||||||
|
@ -128,6 +128,7 @@ var _HostinfoCloneNeedsRegeneration = Hostinfo(struct {
|
|||||||
Distro string
|
Distro string
|
||||||
DistroVersion string
|
DistroVersion string
|
||||||
DistroCodeName string
|
DistroCodeName string
|
||||||
|
App string
|
||||||
Desktop opt.Bool
|
Desktop opt.Bool
|
||||||
Package string
|
Package string
|
||||||
DeviceModel string
|
DeviceModel string
|
||||||
|
@ -41,6 +41,7 @@ func TestHostinfoEqual(t *testing.T) {
|
|||||||
"Distro",
|
"Distro",
|
||||||
"DistroVersion",
|
"DistroVersion",
|
||||||
"DistroCodeName",
|
"DistroCodeName",
|
||||||
|
"App",
|
||||||
"Desktop",
|
"Desktop",
|
||||||
"Package",
|
"Package",
|
||||||
"DeviceModel",
|
"DeviceModel",
|
||||||
@ -216,6 +217,16 @@ func TestHostinfoEqual(t *testing.T) {
|
|||||||
&Hostinfo{},
|
&Hostinfo{},
|
||||||
false,
|
false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
&Hostinfo{App: "golink"},
|
||||||
|
&Hostinfo{App: "abc"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
&Hostinfo{App: "golink"},
|
||||||
|
&Hostinfo{App: "golink"},
|
||||||
|
true,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
got := tt.a.Equal(tt.b)
|
got := tt.a.Equal(tt.b)
|
||||||
|
@ -267,6 +267,7 @@ func (v HostinfoView) Env() string { return v.ж.Env }
|
|||||||
func (v HostinfoView) Distro() string { return v.ж.Distro }
|
func (v HostinfoView) Distro() string { return v.ж.Distro }
|
||||||
func (v HostinfoView) DistroVersion() string { return v.ж.DistroVersion }
|
func (v HostinfoView) DistroVersion() string { return v.ж.DistroVersion }
|
||||||
func (v HostinfoView) DistroCodeName() string { return v.ж.DistroCodeName }
|
func (v HostinfoView) DistroCodeName() string { return v.ж.DistroCodeName }
|
||||||
|
func (v HostinfoView) App() string { return v.ж.App }
|
||||||
func (v HostinfoView) Desktop() opt.Bool { return v.ж.Desktop }
|
func (v HostinfoView) Desktop() opt.Bool { return v.ж.Desktop }
|
||||||
func (v HostinfoView) Package() string { return v.ж.Package }
|
func (v HostinfoView) Package() string { return v.ж.Package }
|
||||||
func (v HostinfoView) DeviceModel() string { return v.ж.DeviceModel }
|
func (v HostinfoView) DeviceModel() string { return v.ж.DeviceModel }
|
||||||
@ -305,6 +306,7 @@ var _HostinfoViewNeedsRegeneration = Hostinfo(struct {
|
|||||||
Distro string
|
Distro string
|
||||||
DistroVersion string
|
DistroVersion string
|
||||||
DistroCodeName string
|
DistroCodeName string
|
||||||
|
App string
|
||||||
Desktop opt.Bool
|
Desktop opt.Bool
|
||||||
Package string
|
Package string
|
||||||
DeviceModel string
|
DeviceModel string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user