diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index af4391a3..7d9ba98a 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -29,7 +29,6 @@ import ( ) const ( - PermissionFallback = 0o700 HeadscaleDateTimeFormat = "2006-01-02 15:04:05" ) @@ -570,17 +569,6 @@ func (tokenAuth) RequireTransportSecurity() bool { return true } -func GetFileMode(key string) fs.FileMode { - modeStr := viper.GetString(key) - - mode, err := strconv.ParseUint(modeStr, headscale.Base8, headscale.BitSize64) - if err != nil { - return PermissionFallback - } - - return fs.FileMode(mode) -} - func contains[T string](ts []T, t T) bool { for _, v := range ts { if reflect.DeepEqual(v, t) { diff --git a/utils.go b/utils.go index 6dddf4c5..8d9dec5b 100644 --- a/utils.go +++ b/utils.go @@ -11,10 +11,12 @@ import ( "encoding/base64" "encoding/json" "fmt" + "io/fs" "net" "os" "path/filepath" "reflect" + "strconv" "strings" "github.com/rs/zerolog/log" @@ -55,6 +57,8 @@ const ( // privateKey prefix. privateHexPrefix = "privkey:" + + PermissionFallback = 0o700 ) func MachinePublicKeyStripPrefix(machineKey key.MachinePublic) string { @@ -350,3 +354,14 @@ func AbsolutePathFromConfigPath(path string) string { return path } + +func GetFileMode(key string) fs.FileMode { + modeStr := viper.GetString(key) + + mode, err := strconv.ParseUint(modeStr, Base8, BitSize64) + if err != nil { + return PermissionFallback + } + + return fs.FileMode(mode) +}