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

Fix file flag handling #860

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions bind/file.go

This file was deleted.

4 changes: 3 additions & 1 deletion bind/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"net/netip"
"net/url"
"os"
"strings"

"github.com/mmatczuk/anyflag"
Expand Down Expand Up @@ -381,7 +382,8 @@ func TLSServerConfig(fs *pflag.FlagSet, cfg *forwarder.TLSServerConfig, namePref
}

func LogConfig(fs *pflag.FlagSet, cfg *log.Config) {
fs.VarP(NewFileFlag(&cfg.File, forwarder.OpenFileParser(log.DefaultFileFlags, log.DefaultFileMode, log.DefaultDirMode)),
fs.VarP(anyflag.NewValueWithRedact[*os.File](cfg.File, &cfg.File,
forwarder.OpenFileParser(log.DefaultFileFlags, log.DefaultFileMode, log.DefaultDirMode), DisplayFileName),
"log-file", "", "<path>"+
"Path to the log file, if empty, logs to stdout. "+
"The file is reopened on SIGHUP to allow log rotation using external tools. ")
Expand Down
8 changes: 8 additions & 0 deletions bind/redact.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package bind
import (
"fmt"
"net/url"
"os"
"strings"

"github.com/saucelabs/forwarder/header"
Expand Down Expand Up @@ -39,3 +40,10 @@ func RedactBase64(s string) string {

return s
}

func DisplayFileName(f *os.File) string {
if f == nil {
return ""
}
return f.Name()
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/google/go-github/v56 v56.0.0
github.com/gorilla/websocket v1.5.3
github.com/mitchellh/go-wordwrap v1.0.1
github.com/mmatczuk/anyflag v0.0.0-20240105091245-c64b70bf5d41
github.com/mmatczuk/anyflag v0.0.0-20240709090339-eb9e24cd1b44
github.com/prometheus/client_golang v1.19.1
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.55.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mmatczuk/anyflag v0.0.0-20240105091245-c64b70bf5d41 h1:YRrHzEpNLEEpefVq2Ve9hOj/jA3QdYwoJhPGOqdAhnw=
github.com/mmatczuk/anyflag v0.0.0-20240105091245-c64b70bf5d41/go.mod h1:PT22bA6vWBzPL8tAeK2XCMvWOQ4e19yY3MJIgnTZRaE=
github.com/mmatczuk/anyflag v0.0.0-20240709090339-eb9e24cd1b44 h1:Ds9W8Yj5ti4kQXITpCozfNNibS1fUA8+aK2T5th0vXE=
github.com/mmatczuk/anyflag v0.0.0-20240709090339-eb9e24cd1b44/go.mod h1:PT22bA6vWBzPL8tAeK2XCMvWOQ4e19yY3MJIgnTZRaE=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
Expand Down
Loading