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

Cobra related patches #482

Merged
merged 2 commits into from
Oct 26, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions bind/file.go
Original file line number Diff line number Diff line change
@@ -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}
}
4 changes: 2 additions & 2 deletions bind/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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>"+
"Path to the log file, if empty, logs to stdout. ")

Expand Down
31 changes: 28 additions & 3 deletions credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down