TUN-3995: Optional --features flag for tunnel run.
These features will be included in the ClientInfo.Features field when running a named tunnel.
This commit is contained in:
parent
b73c039070
commit
5c7b451e17
|
@ -0,0 +1,13 @@
|
||||||
|
package tunnel
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDedup(t *testing.T) {
|
||||||
|
expected := []string{"a", "b"}
|
||||||
|
actual := dedup([]string{"a", "b", "a"})
|
||||||
|
require.Equal(t, expected, actual)
|
||||||
|
}
|
|
@ -201,9 +201,10 @@ func prepareTunnelConfig(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ingress.Ingress{}, errors.Wrap(err, "can't generate clientUUID")
|
return nil, ingress.Ingress{}, errors.Wrap(err, "can't generate clientUUID")
|
||||||
}
|
}
|
||||||
|
features := append(c.StringSlice("features"), origin.FeatureSerializedHeaders)
|
||||||
namedTunnel.Client = tunnelpogs.ClientInfo{
|
namedTunnel.Client = tunnelpogs.ClientInfo{
|
||||||
ClientID: clientUUID[:],
|
ClientID: clientUUID[:],
|
||||||
Features: []string{origin.FeatureSerializedHeaders},
|
Features: dedup(features),
|
||||||
Version: version,
|
Version: version,
|
||||||
Arch: fmt.Sprintf("%s_%s", buildInfo.GoOS, buildInfo.GoArch),
|
Arch: fmt.Sprintf("%s_%s", buildInfo.GoOS, buildInfo.GoArch),
|
||||||
}
|
}
|
||||||
|
@ -301,3 +302,22 @@ func isWarpRoutingEnabled(warpConfig config.WarpRoutingConfig, isNamedTunnel boo
|
||||||
func isRunningFromTerminal() bool {
|
func isRunningFromTerminal() bool {
|
||||||
return terminal.IsTerminal(int(os.Stdout.Fd()))
|
return terminal.IsTerminal(int(os.Stdout.Fd()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove any duplicates from the slice
|
||||||
|
func dedup(slice []string) []string {
|
||||||
|
|
||||||
|
// Convert the slice into a set
|
||||||
|
set := make(map[string]bool, 0)
|
||||||
|
for _, str := range slice {
|
||||||
|
set[str] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert the set back into a slice
|
||||||
|
keys := make([]string, len(set))
|
||||||
|
i := 0
|
||||||
|
for str := range set {
|
||||||
|
keys[i] = str
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
|
@ -87,6 +87,11 @@ var (
|
||||||
"overwrite the previous tunnel. If you want to use a single hostname with multiple " +
|
"overwrite the previous tunnel. If you want to use a single hostname with multiple " +
|
||||||
"tunnels, you can do so with Cloudflare's Load Balancer product.",
|
"tunnels, you can do so with Cloudflare's Load Balancer product.",
|
||||||
})
|
})
|
||||||
|
featuresFlag = altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
|
||||||
|
Name: "features",
|
||||||
|
Aliases: []string{"F"},
|
||||||
|
Usage: "Opt into various features that are still being developed or tested.",
|
||||||
|
})
|
||||||
credentialsFileFlag = altsrc.NewStringFlag(&cli.StringFlag{
|
credentialsFileFlag = altsrc.NewStringFlag(&cli.StringFlag{
|
||||||
Name: CredFileFlag,
|
Name: CredFileFlag,
|
||||||
Aliases: []string{CredFileFlagAlias},
|
Aliases: []string{CredFileFlagAlias},
|
||||||
|
@ -370,6 +375,7 @@ func buildRunCommand() *cli.Command {
|
||||||
forceFlag,
|
forceFlag,
|
||||||
credentialsFileFlag,
|
credentialsFileFlag,
|
||||||
selectProtocolFlag,
|
selectProtocolFlag,
|
||||||
|
featuresFlag,
|
||||||
}
|
}
|
||||||
flags = append(flags, configureProxyFlags(false)...)
|
flags = append(flags, configureProxyFlags(false)...)
|
||||||
return &cli.Command{
|
return &cli.Command{
|
||||||
|
|
Loading…
Reference in New Issue