diff --git a/cmd/tunnel/main.go b/cmd/tunnel/main.go index 4346bae..4b18e44 100644 --- a/cmd/tunnel/main.go +++ b/cmd/tunnel/main.go @@ -2,6 +2,7 @@ package main import ( "context" + b64 "encoding/base64" "fmt" "io" "log" @@ -11,6 +12,7 @@ import ( "os/signal" "time" + "github.com/dchest/uniuri" "github.com/urfave/cli/v2" "golang.org/x/xerrors" @@ -47,8 +49,9 @@ func main() { &cli.StringFlag{ Name: "wireguard-key", Aliases: []string{"wg-key"}, - Usage: "The private key for the wireguard client. It should be base64 encoded. You must specify this or wireguard-key-file.", + Usage: "The private key for the wireguard client. It should be base64 encoded. Defaults to a new random key. wireguard-key-file will over-ride this option.", EnvVars: []string{"TUNNEL_WIREGUARD_KEY"}, + Value: b64.StdEncoding.EncodeToString([]byte(uniuri.NewLen(32))), }, &cli.StringFlag{ Name: "wireguard-key-file", @@ -76,12 +79,6 @@ func runApp(ctx *cli.Context) error { if apiURL == "" { return xerrors.New("api-url is required. See --help for more information.") } - if wireguardKey == "" && wireguardKeyFile == "" { - return xerrors.New("wireguard-key or wireguard-key-file is required. See --help for more information.") - } - if wireguardKey != "" && wireguardKeyFile != "" { - return xerrors.New("Only one of wireguard-key or wireguard-key-file can be specified. See --help for more information.") - } if ctx.Args().Len() != 1 { return xerrors.New("exactly one argument (target-address) is required. See --help for more information.") diff --git a/go.mod b/go.mod index 0cb150a..4a9988a 100644 --- a/go.mod +++ b/go.mod @@ -30,6 +30,7 @@ require ( github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dchest/uniuri v1.2.0 // indirect github.com/dlclark/regexp2 v1.8.1 // indirect github.com/fatih/color v1.14.1 // indirect github.com/felixge/httpsnoop v1.0.3 // indirect diff --git a/go.sum b/go.sum index 05725f3..aa8f2ee 100644 --- a/go.sum +++ b/go.sum @@ -80,6 +80,8 @@ github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964/go.mod h1:Xd9 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dchest/uniuri v1.2.0 h1:koIcOUdrTIivZgSLhHQvKgqdWZq5d7KdMEWF1Ud6+5g= +github.com/dchest/uniuri v1.2.0/go.mod h1:fSzm4SLHzNZvWLvWJew423PhAzkpNQYq+uNLq4kxhkY= github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= github.com/dlclark/regexp2 v1.8.1 h1:6Lcdwya6GjPUNsBct8Lg/yRPwMhABj269AAzdGSiR+0= github.com/dlclark/regexp2 v1.8.1/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=