Skip to content

Commit

Permalink
cmd pf: only one target map to stdio
Browse files Browse the repository at this point in the history
  • Loading branch information
rkonfj committed May 26, 2023
1 parent 44e7ed2 commit 4aa3e4e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion cmd/pf/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
"github.com/sirupsen/logrus"
)

var errOnlyOnceMapToStdio error = errors.New(
"only one communication target can be mapped to stdio")

type Options struct {
Forwards []string
Server, Key string
Expand Down Expand Up @@ -63,6 +66,7 @@ func NewTunnelManager(opts Options) (*TunnelManager, error) {
}

var forwards []mapping
var stdioMapping *mapping

for _, f := range opts.Forwards {
rawMp := strings.Split(f, "/")
Expand All @@ -71,12 +75,20 @@ func NewTunnelManager(opts Options) (*TunnelManager, error) {
}
mp := mapping{network: rawMp[0], bo: backoff.NewExponentialBackOff()}
if len(rawMp) == 2 {
if stdioMapping != nil {
return nil, errOnlyOnceMapToStdio
}
mp.local = "stdio"
mp.remote = rawMp[1]
stdioMapping = &mp
logrus.SetOutput(os.Stderr)
} else {
if len(rawMp) == 0 {
if len(rawMp[1]) == 0 {
if stdioMapping != nil {
return nil, errOnlyOnceMapToStdio
}
mp.local = "stdio"
stdioMapping = &mp
} else {
mp.local = rawMp[1]
}
Expand Down

0 comments on commit 4aa3e4e

Please sign in to comment.