Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
tprelle committed Mar 27, 2024
1 parent b626f84 commit 7f26aa4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions pkg/stanza/fileconsumer/attrs/attrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func TestResolver(t *testing.T) {
IncludeFilePath: bitString[1] == '1',
IncludeFileNameResolved: bitString[2] == '1',
IncludeFilePathResolved: bitString[3] == '1',
IncludeFileOwnerName: bitString[4] == '1',
IncludeFileOwnerGroupName: bitString[5] == '1',
IncludeFileOwnerName: bitString[4] == '1' && runtime.GOOS != "windows",
IncludeFileOwnerGroupName: bitString[5] == '1' && runtime.GOOS != "windows",
}

t.Run(bitString, func(t *testing.T) {
Expand Down Expand Up @@ -70,15 +70,15 @@ func TestResolver(t *testing.T) {
} else {
assert.Empty(t, attributes[LogFilePathResolved])
}
if runtime.GOOS != "windows" && r.IncludeFileOwnerName {
if r.IncludeFileOwnerName {
expectLen++
assert.NotNil(t, attributes[LogFileOwnerName])
assert.IsType(t, "", attributes[LogFileOwnerName])
} else {
assert.Empty(t, attributes[LogFileOwnerName])
assert.Empty(t, attributes[LogFileOwnerName])
}
if runtime.GOOS != "windows" && r.IncludeFileOwnerGroupName {
if r.IncludeFileOwnerGroupName {
expectLen++
assert.NotNil(t, attributes[LogFileOwnerGroupName])
assert.IsType(t, "", attributes[LogFileOwnerGroupName])
Expand Down
12 changes: 6 additions & 6 deletions pkg/stanza/fileconsumer/attrs/owner_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ import (
"syscall"
)

func (r *Resolver) addOwnerInfo(file *os.File, attributes map[string]any) (err error) {
var fileInfo, errStat = file.Stat()
func (r *Resolver) addOwnerInfo(file *os.File, attributes map[string]any) error {
fileInfo, errStat := file.Stat()
if errStat != nil {
return fmt.Errorf("resolve file stat: %w", err)
return fmt.Errorf("resolve file stat: %w", errStat)
}
var fileStat = fileInfo.Sys().(*syscall.Stat_t)
fileStat := fileInfo.Sys().(*syscall.Stat_t)

if r.IncludeFileOwnerName {
var fileOwner, errFileUser = user.LookupId(fmt.Sprint(fileStat.Uid))
fileOwner, errFileUser := user.LookupId(fmt.Sprint(fileStat.Uid))
if errFileUser != nil {
return fmt.Errorf("resolve file owner name: %w", errFileUser)
}
attributes[LogFileOwnerName] = fileOwner.Username
}
if r.IncludeFileOwnerGroupName {
var fileGroup, errFileGroup = user.LookupGroupId(fmt.Sprint(fileStat.Gid))
fileGroup, errFileGroup := user.LookupGroupId(fmt.Sprint(fileStat.Gid))
if errFileGroup != nil {
return fmt.Errorf("resolve file group name: %w", errFileGroup)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/stanza/fileconsumer/attrs/owner_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (
"os"
)

func (r *Resolver) addOwnerInfo(file *os.File, attributes map[string]any) (err error) {
return fmt.Errorf("addOwnerInfo it's not implemented for windows: %w", err)
func (r *Resolver) addOwnerInfo(file *os.File, attributes map[string]any) error {
return fmt.Errorf("owner info not implemented for windows: %w")
}
2 changes: 1 addition & 1 deletion pkg/stanza/fileconsumer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (c Config) validate() error {
}

if runtime.GOOS == "windows" && (c.Resolver.IncludeFileOwnerName || c.Resolver.IncludeFileOwnerGroupName) {
return fmt.Errorf("include_file_owner_name or include_file_owner_group_name it's not supported for windows: %w", err)
return fmt.Errorf("'include_file_owner_name' or 'include_file_owner_group_name' it's not supported for windows: %w", err)
}

return nil
Expand Down

0 comments on commit 7f26aa4

Please sign in to comment.