Skip to content

Commit

Permalink
fix(info): mask username on Windows (#2902)
Browse files Browse the repository at this point in the history
* fix(info): mask username on Windows

* chore: use `strings.Cut`

Co-authored-by: Shunsuke Suzuki <[email protected]>

---------

Co-authored-by: Shunsuke Suzuki <[email protected]>
  • Loading branch information
sapphi-red and suzuki-shunsuke authored May 18, 2024
1 parent aff9110 commit 5f9df45
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pkg/controller/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,28 @@ func maskUser(s, username string) string {
return strings.ReplaceAll(s, username, "(USER)")
}

func (c *Controller) Info(_ context.Context, _ *logrus.Entry, param *config.Param) error { //nolint:funlen
func getCurrentUserName() (string, error) {
currentUser, err := user.Current()
if err != nil {
return fmt.Errorf("get a current user: %w", err)
return "", fmt.Errorf("get a current user: %w", err)
}
userName := currentUser.Username
if runtime.GOOS == "windows" {
// On Windows, the user name is in the form of "domain\user".
domain, userName, ok := strings.Cut(userName, "\\")
if ok {
return userName, nil
}
return domain, nil
}
return userName, nil
}

func (c *Controller) Info(_ context.Context, _ *logrus.Entry, param *config.Param) error { //nolint:funlen
userName, err := getCurrentUserName()
if err != nil {
return fmt.Errorf("get a current user name: %w", err)
}

filePaths := c.finder.Finds(param.PWD, param.ConfigFilePath)
cfgs := make([]*Config, len(filePaths))
Expand Down

0 comments on commit 5f9df45

Please sign in to comment.