The client/local package doc said its API is not necessarily stable, but that caveat was easy to miss and only a few cert methods said anything explicit either way. People have been surprised by IPN bus changes between releases. Add explicit "API maturity" notes, matching the existing wording on the cert methods, marking stable: BugReport, BugReportWithOpts, CertDomains, CheckUpdate, CurrentDERPMap, DialTCP, UserDial, DisconnectControl, GetPrefs, EditPrefs, Status, StatusWithoutPeers, SetUseExitNode, SwitchProfile, UserProfile, and the WhoIs* methods. Mark unstable: ipn.Notify, WatchIPNBus, DoLocalRequest, the Debug*, Drive*, Check*, EventBus*, and Stream* methods, SetComponentDebugLogging, TailDaemonLogs, ShutdownTailscaled, GetDNSOSConfig, GetEffectivePolicy, GetServeConfig, and GetAppConnectorRouteInfo. Also note on tailcfg.DERPMap that the type is subject to minor changes over time though its general shape is stable, document that ipn.Prefs.CorpDNS is the internal name for "tailscale set --accept-dns", and add a package doc paragraph to client/local saying that methods without an explicit API maturity note should be assumed unstable. Updates #20406 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Change-Id: I9333c58ae312e392c61d7de77987282e84ce2aeb
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !ts_omit_serve
|
|
|
|
package local
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"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) {
|
|
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 {
|
|
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
|
|
}
|