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

SNOW-1825790 Implement safer file based token cache #1327

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
33 changes: 33 additions & 0 deletions os_specific_posix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//go:build darwin || linux

package gosnowflake

import (
"fmt"
"os"
"syscall"
)

func providePathOwner(filepath string) (uint32, error) {
info, err := os.Stat(filepath)
if err != nil {
return 0, err
}

Check warning on line 15 in os_specific_posix.go

View check run for this annotation

Codecov / codecov/patch

os_specific_posix.go#L14-L15

Added lines #L14 - L15 were not covered by tests
return provideOwnerFromStat(info, filepath)
}

func provideFileOwner(file *os.File) (uint32, error) {
info, err := file.Stat()
if err != nil {
return 0, err
}

Check warning on line 23 in os_specific_posix.go

View check run for this annotation

Codecov / codecov/patch

os_specific_posix.go#L22-L23

Added lines #L22 - L23 were not covered by tests
return provideOwnerFromStat(info, file.Name())
}

func provideOwnerFromStat(info os.FileInfo, filepath string) (uint32, error) {
nativeStat, ok := info.Sys().(*syscall.Stat_t)
if !ok {
return 0, fmt.Errorf("cannot cast file info for %v to *syscall.Stat_t", filepath)
}

Check warning on line 31 in os_specific_posix.go

View check run for this annotation

Codecov / codecov/patch

os_specific_posix.go#L30-L31

Added lines #L30 - L31 were not covered by tests
return nativeStat.Uid, nil
}
16 changes: 16 additions & 0 deletions os_specific_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// go:build windows

package gosnowflake

import (
"errors"
"os"
)

func providePathOwner(filepath string) (uint32, error) {
return 0, errors.New("providePathOwner is unsupported on windows")

Check warning on line 11 in os_specific_windows.go

View check run for this annotation

Codecov / codecov/patch

os_specific_windows.go#L10-L11

Added lines #L10 - L11 were not covered by tests
}

func provideFileOwner(file *os.File) (uint32, error) {
return 0, errors.New("provideFileOwner is unsupported on windows")

Check warning on line 15 in os_specific_windows.go

View check run for this annotation

Codecov / codecov/patch

os_specific_windows.go#L14-L15

Added lines #L14 - L15 were not covered by tests
}
Loading
Loading