mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-24 02:31:18 -08:00
tsnet called the serve LocalAPI client and LocalBackend methods unconditionally, so it didn't build with ts_omit_serve, which every minimal feature set includes. Make those methods return feature.ErrUnavailable when serve is omitted, as ListenFunnel and ListenService now do too. Declare tsnet's minimum feature set (netstack) as featuretags.TSNetMin, add cmd/featuretags --tsnet to keep it, and add a test that type-checks tsnet with it and a few other small feature sets. Fixes #22282 Updates #22283 Change-Id: I866fa34d052bfd437b1c9d3309063999d7ebb02c Co-Authored-By: Fredrik Fornwall <[email protected]> Signed-off-by: Brad Fitzpatrick <[email protected]>
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package local
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"tailscale.com/feature"
|
|
"tailscale.com/feature/buildfeatures"
|
|
"tailscale.com/ipn"
|
|
)
|
|
|
|
// GetServeConfig return the current serve config.
|
|
//
|
|
// If the serve config is empty, it returns (nil, nil).
|
|
//
|
|
// API maturity: this method is not considered a stable API and is
|
|
// subject to change between releases.
|
|
func (lc *Client) GetServeConfig(ctx context.Context) (*ipn.ServeConfig, error) {
|
|
if !buildfeatures.HasServe {
|
|
return nil, feature.ErrUnavailable
|
|
}
|
|
body, h, err := lc.sendWithHeaders(ctx, "GET", "/localapi/v0/serve-config", 200, nil, nil)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("getting serve config: %w", err)
|
|
}
|
|
sc, err := getServeConfigFromJSON(body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if sc == nil {
|
|
sc = new(ipn.ServeConfig)
|
|
}
|
|
sc.ETag = h.Get("Etag")
|
|
return sc, nil
|
|
}
|
|
|
|
func getServeConfigFromJSON(body []byte) (sc *ipn.ServeConfig, err error) {
|
|
if err := json.Unmarshal(body, &sc); err != nil {
|
|
return nil, err
|
|
}
|
|
return sc, nil
|
|
}
|
|
|
|
// SetServeConfig sets or replaces the serving settings.
|
|
// If config is nil, settings are cleared and serving is disabled.
|
|
func (lc *Client) SetServeConfig(ctx context.Context, config *ipn.ServeConfig) error {
|
|
if !buildfeatures.HasServe {
|
|
return feature.ErrUnavailable
|
|
}
|
|
h := make(http.Header)
|
|
if config != nil {
|
|
h.Set("If-Match", config.ETag)
|
|
}
|
|
_, _, err := lc.sendWithHeaders(ctx, "POST", "/localapi/v0/serve-config", 200, jsonBody(config), h)
|
|
if err != nil {
|
|
return fmt.Errorf("sending serve config: %w", err)
|
|
}
|
|
return nil
|
|
}
|