Skip to content

Commit

Permalink
bind: remove newOSFileFlag
Browse files Browse the repository at this point in the history
Reimplement file binding with plain anyflag.NewValueWithRedact[*os.File]()
  • Loading branch information
mmatczuk committed Jul 9, 2024
1 parent f46a716 commit 28998dd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
33 changes: 0 additions & 33 deletions bind/file.go

This file was deleted.

4 changes: 2 additions & 2 deletions bind/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ func TLSServerConfig(fs *pflag.FlagSet, cfg *forwarder.TLSServerConfig, namePref
}

func LogConfig(fs *pflag.FlagSet, cfg *log.Config) {
fs.VarP(newOSFileFlag(anyflag.NewValue[*os.File](nil, &cfg.File,
forwarder.OpenFileParser(log.DefaultFileFlags, log.DefaultFileMode, log.DefaultDirMode)), &cfg.File),
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()
}

0 comments on commit 28998dd

Please sign in to comment.