Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add registered clients feature #86

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
18 changes: 15 additions & 3 deletions cli/tunnel/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package tunnel
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"

Expand All @@ -21,6 +22,7 @@ const (
DefaultBackoffMultiplier = 1.5
DefaultBackoffMaxInterval = 60 * time.Second
DefaultBackoffMaxTime = 15 * time.Minute
ConfigFileSTDIN = "-"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like it's not part of "Default backoff configuration."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only stdin file path reference.

)

// BackoffConfig defines behavior of staggering reconnection retries.
Expand Down Expand Up @@ -52,9 +54,19 @@ type ClientConfig struct {
}

func LoadClientConfigFromFile(file string) (*ClientConfig, error) {
buf, err := ioutil.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("failed to read file %q: %s", file, err)
var (
buf []byte
err error
)
if file == ConfigFileSTDIN {
if buf, err = ioutil.ReadAll(os.Stdin); err != nil {
return nil, fmt.Errorf("failed to read config from STDIN: ", err)
}
file = "STDIN"
} else {
if buf, err = ioutil.ReadFile(file); err != nil {
return nil, fmt.Errorf("failed to read file %q: %s", file, err)
}
}

c := ClientConfig{
Expand Down
3 changes: 2 additions & 1 deletion cli/tunnel/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func ParseArgs(hasConfig bool, args ...string) (*options, error) {
cli := flag.NewFlagSet(args[0], flag.ExitOnError)
args = args[1:]
if hasConfig {
config = cli.String("config", "tunnel.yaml", "Path to tunnel configuration file")
config = cli.String("config", "tunnel.yaml",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about Path to tunnel configuration file, for reading from STDIN use '-'.?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used as an example the "cat" command: cat -

"Path to tunnel configuration file. Use HYPHEN (-) for read STDIN.")
} else {
var s = ""
config = &s
Expand Down
2 changes: 1 addition & 1 deletion cli/tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func Main() {
MainArgs(os.Args[1:]...)
MainArgs(os.Args...)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Author

@moisespsena moisespsena Nov 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old version, the ParseArgs function uses the os.Args[0], for command name, now, uses the first passed argument.

}

func MainArgs(args ...string) {
Expand Down