diff --git a/bind/file.go b/bind/file.go new file mode 100644 index 00000000..12777a8d --- /dev/null +++ b/bind/file.go @@ -0,0 +1,33 @@ +// Copyright 2023 Sauce Labs Inc. All rights reserved. +// +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +package bind + +import ( + "os" + + "github.com/spf13/pflag" +) + +// osFileFlag allows to print the file name instead of the file descriptor. +type osFileFlag struct { + pflag.Value + f **os.File +} + +func (f *osFileFlag) String() string { + if *f.f == nil { + return "" + } + return (*f.f).Name() +} + +func newOSFileFlag(v pflag.Value, f **os.File) pflag.Value { + if f == nil { + panic("nil pointer") + } + return &osFileFlag{v, f} +} diff --git a/bind/flag.go b/bind/flag.go index 292ed8ea..f9b85615 100644 --- a/bind/flag.go +++ b/bind/flag.go @@ -315,8 +315,8 @@ func PromNamespace(fs *pflag.FlagSet, promNamespace *string) { } func LogConfig(fs *pflag.FlagSet, cfg *log.Config) { - fs.VarP(anyflag.NewValue[*os.File](nil, &cfg.File, - forwarder.OpenFileParser(os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600, 0o700)), + fs.VarP(newOSFileFlag(anyflag.NewValue[*os.File](nil, &cfg.File, + forwarder.OpenFileParser(os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o600, 0o700)), &cfg.File), "log-file", "", ""+ "Path to the log file, if empty, logs to stdout. ") diff --git a/credentials.go b/credentials.go index 7d454a11..10d3e77b 100644 --- a/credentials.go +++ b/credentials.go @@ -33,14 +33,39 @@ func (hpu *HostPortUser) Validate() error { return validatedUserInfo(hpu.Userinfo) } +func (hpu *HostPortUser) String() string { + if hpu == nil { + return "" + } + + port := hpu.Port + if port == "0" { + port = "*" + } + + p, ok := hpu.Password() + if !ok { + return fmt.Sprintf("%s@%s:%s", hpu.Username(), hpu.Host, port) + } + + return fmt.Sprintf("%s:%s@%s:%s", hpu.Username(), p, hpu.Host, port) +} + func RedactHostPortUser(hpu *HostPortUser) string { if hpu == nil { return "" } - if _, has := hpu.Password(); has { - return fmt.Sprintf("%s:xxxxx@%s:%s", hpu.Username(), hpu.Host, hpu.Port) + + port := hpu.Port + if port == "0" { + port = "*" } - return fmt.Sprintf("%s@%s:%s", hpu.Username(), hpu.Host, hpu.Port) + + if _, ok := hpu.Password(); !ok { + return fmt.Sprintf("%s@%s:%s", hpu.Username(), hpu.Host, port) + } + + return fmt.Sprintf("%s:xxxxx@%s:%s", hpu.Username(), hpu.Host, port) } type CredentialsMatcher struct {