mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-08 10:51:57 +01:00
feature/featuretags, ipn/conffile: make HuJSON support in config files optional
Saves 33 KB. Updates #12614 Change-Id: Ie701c230e0765281f409f29ed263910b9be9cc77 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
6c6a1d8341
commit
f7afb9b6ca
@ -24,7 +24,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
|||||||
💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
💣 github.com/mdlayher/netlink/nlenc from github.com/jsimonetti/rtnetlink+
|
||||||
💣 github.com/mdlayher/socket from github.com/mdlayher/netlink+
|
💣 github.com/mdlayher/socket from github.com/mdlayher/netlink+
|
||||||
💣 github.com/safchain/ethtool from tailscale.com/net/netkernelconf
|
💣 github.com/safchain/ethtool from tailscale.com/net/netkernelconf
|
||||||
github.com/tailscale/hujson from tailscale.com/ipn/conffile
|
|
||||||
github.com/tailscale/peercred from tailscale.com/ipn/ipnauth
|
github.com/tailscale/peercred from tailscale.com/ipn/ipnauth
|
||||||
💣 github.com/tailscale/wireguard-go/conn from github.com/tailscale/wireguard-go/device+
|
💣 github.com/tailscale/wireguard-go/conn from github.com/tailscale/wireguard-go/device+
|
||||||
💣 github.com/tailscale/wireguard-go/device from tailscale.com/net/tstun+
|
💣 github.com/tailscale/wireguard-go/device from tailscale.com/net/tstun+
|
||||||
|
|||||||
@ -36,7 +36,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de
|
|||||||
github.com/skip2/go-qrcode from tailscale.com/cmd/tailscale/cli
|
github.com/skip2/go-qrcode from tailscale.com/cmd/tailscale/cli
|
||||||
github.com/skip2/go-qrcode/bitset from github.com/skip2/go-qrcode+
|
github.com/skip2/go-qrcode/bitset from github.com/skip2/go-qrcode+
|
||||||
github.com/skip2/go-qrcode/reedsolomon from github.com/skip2/go-qrcode
|
github.com/skip2/go-qrcode/reedsolomon from github.com/skip2/go-qrcode
|
||||||
github.com/tailscale/hujson from tailscale.com/ipn/conffile
|
|
||||||
github.com/tailscale/peercred from tailscale.com/ipn/ipnauth
|
github.com/tailscale/peercred from tailscale.com/ipn/ipnauth
|
||||||
💣 github.com/tailscale/wireguard-go/conn from github.com/tailscale/wireguard-go/device+
|
💣 github.com/tailscale/wireguard-go/conn from github.com/tailscale/wireguard-go/device+
|
||||||
💣 github.com/tailscale/wireguard-go/device from tailscale.com/net/tstun+
|
💣 github.com/tailscale/wireguard-go/device from tailscale.com/net/tstun+
|
||||||
|
|||||||
@ -253,13 +253,19 @@ func TestMinTailscaledNoCLI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestMinTailscaledWithCLI(t *testing.T) {
|
func TestMinTailscaledWithCLI(t *testing.T) {
|
||||||
|
badSubstrs := []string{
|
||||||
|
"cbor",
|
||||||
|
"hujson",
|
||||||
|
}
|
||||||
deptest.DepChecker{
|
deptest.DepChecker{
|
||||||
GOOS: "linux",
|
GOOS: "linux",
|
||||||
GOARCH: "amd64",
|
GOARCH: "amd64",
|
||||||
Tags: minTags() + ",ts_include_cli",
|
Tags: minTags() + ",ts_include_cli",
|
||||||
OnDep: func(dep string) {
|
OnDep: func(dep string) {
|
||||||
if strings.Contains(dep, "cbor") {
|
for _, bad := range badSubstrs {
|
||||||
t.Errorf("unexpected dep: %q", dep)
|
if strings.Contains(dep, bad) {
|
||||||
|
t.Errorf("unexpected dep: %q", dep)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}.Check(t)
|
}.Check(t)
|
||||||
|
|||||||
13
feature/buildfeatures/feature_hujsonconf_disabled.go
Normal file
13
feature/buildfeatures/feature_hujsonconf_disabled.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
// Code generated by gen.go; DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build ts_omit_hujsonconf
|
||||||
|
|
||||||
|
package buildfeatures
|
||||||
|
|
||||||
|
// HasHuJSONConf is whether the binary was built with support for modular feature "HuJSON config file support".
|
||||||
|
// Specifically, it's whether the binary was NOT built with the "ts_omit_hujsonconf" build tag.
|
||||||
|
// It's a const so it can be used for dead code elimination.
|
||||||
|
const HasHuJSONConf = false
|
||||||
13
feature/buildfeatures/feature_hujsonconf_enabled.go
Normal file
13
feature/buildfeatures/feature_hujsonconf_enabled.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
|
// Code generated by gen.go; DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build !ts_omit_hujsonconf
|
||||||
|
|
||||||
|
package buildfeatures
|
||||||
|
|
||||||
|
// HasHuJSONConf is whether the binary was built with support for modular feature "HuJSON config file support".
|
||||||
|
// Specifically, it's whether the binary was NOT built with the "ts_omit_hujsonconf" build tag.
|
||||||
|
// It's a const so it can be used for dead code elimination.
|
||||||
|
const HasHuJSONConf = true
|
||||||
@ -113,6 +113,7 @@ var Features = map[FeatureTag]FeatureMeta{
|
|||||||
Desc: "Generic Receive Offload support (performance)",
|
Desc: "Generic Receive Offload support (performance)",
|
||||||
Deps: []FeatureTag{"netstack"},
|
Deps: []FeatureTag{"netstack"},
|
||||||
},
|
},
|
||||||
|
"hujsonconf": {"HuJSONConf", "HuJSON config file support", nil},
|
||||||
"iptables": {"IPTables", "Linux iptables support", nil},
|
"iptables": {"IPTables", "Linux iptables support", nil},
|
||||||
"kube": {"Kube", "Kubernetes integration", nil},
|
"kube": {"Kube", "Kubernetes integration", nil},
|
||||||
"linuxdnsfight": {"LinuxDNSFight", "Linux support for detecting DNS fights (inotify watching of /etc/resolv.conf)", nil},
|
"linuxdnsfight": {"LinuxDNSFight", "Linux support for detecting DNS fights (inotify watching of /etc/resolv.conf)", nil},
|
||||||
|
|||||||
@ -10,6 +10,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"tailscale.com/feature"
|
||||||
|
"tailscale.com/feature/buildfeatures"
|
||||||
"tailscale.com/omit"
|
"tailscale.com/omit"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -35,6 +37,9 @@ func getEC2MetadataToken() (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func readVMUserData() ([]byte, error) {
|
func readVMUserData() ([]byte, error) {
|
||||||
|
if !buildfeatures.HasAWS {
|
||||||
|
return nil, feature.ErrUnavailable
|
||||||
|
}
|
||||||
// TODO(bradfitz): support GCP, Azure, Proxmox/cloud-init
|
// TODO(bradfitz): support GCP, Azure, Proxmox/cloud-init
|
||||||
// (NoCloud/ConfigDrive ISO), etc.
|
// (NoCloud/ConfigDrive ISO), etc.
|
||||||
|
|
||||||
|
|||||||
@ -8,11 +8,11 @@ package conffile
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"tailscale.com/feature/buildfeatures"
|
||||||
"tailscale.com/ipn"
|
"tailscale.com/ipn"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,10 +51,6 @@ func Load(path string) (*Config, error) {
|
|||||||
// compile-time for deadcode elimination
|
// compile-time for deadcode elimination
|
||||||
return nil, fmt.Errorf("config file loading not supported on %q", runtime.GOOS)
|
return nil, fmt.Errorf("config file loading not supported on %q", runtime.GOOS)
|
||||||
}
|
}
|
||||||
if hujsonStandardize == nil {
|
|
||||||
// Build tags are wrong in conffile_hujson.go
|
|
||||||
return nil, errors.New("[unexpected] config file loading not wired up")
|
|
||||||
}
|
|
||||||
var c Config
|
var c Config
|
||||||
c.Path = path
|
c.Path = path
|
||||||
var err error
|
var err error
|
||||||
@ -68,14 +64,21 @@ func Load(path string) (*Config, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c.Std, err = hujsonStandardize(c.Raw)
|
if buildfeatures.HasHuJSONConf && hujsonStandardize != nil {
|
||||||
if err != nil {
|
c.Std, err = hujsonStandardize(c.Raw)
|
||||||
return nil, fmt.Errorf("error parsing config file %s HuJSON/JSON: %w", path, err)
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error parsing config file %s HuJSON/JSON: %w", path, err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
c.Std = c.Raw // config file must be valid JSON with ts_omit_hujsonconf
|
||||||
}
|
}
|
||||||
var ver struct {
|
var ver struct {
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
}
|
}
|
||||||
if err := json.Unmarshal(c.Std, &ver); err != nil {
|
if err := json.Unmarshal(c.Std, &ver); err != nil {
|
||||||
|
if !buildfeatures.HasHuJSONConf {
|
||||||
|
return nil, fmt.Errorf("error parsing config file %s, which must be valid standard JSON: %w", path, err)
|
||||||
|
}
|
||||||
return nil, fmt.Errorf("error parsing config file %s: %w", path, err)
|
return nil, fmt.Errorf("error parsing config file %s: %w", path, err)
|
||||||
}
|
}
|
||||||
switch ver.Version {
|
switch ver.Version {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
// Copyright (c) Tailscale Inc & AUTHORS
|
// Copyright (c) Tailscale Inc & AUTHORS
|
||||||
// SPDX-License-Identifier: BSD-3-Clause
|
// SPDX-License-Identifier: BSD-3-Clause
|
||||||
|
|
||||||
//go:build !ios && !android
|
//go:build !ios && !android && !ts_omit_hujsonconf
|
||||||
|
|
||||||
package conffile
|
package conffile
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user