Move FilePerm function from cli to headscale

This commit is contained in:
Kristoffer Dalby 2022-06-03 09:24:36 +02:00
parent 533ecee252
commit 35722cd5aa
2 changed files with 15 additions and 12 deletions

View file

@ -29,7 +29,6 @@ import (
) )
const ( const (
PermissionFallback = 0o700
HeadscaleDateTimeFormat = "2006-01-02 15:04:05" HeadscaleDateTimeFormat = "2006-01-02 15:04:05"
) )
@ -570,17 +569,6 @@ func (tokenAuth) RequireTransportSecurity() bool {
return true 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 { func contains[T string](ts []T, t T) bool {
for _, v := range ts { for _, v := range ts {
if reflect.DeepEqual(v, t) { if reflect.DeepEqual(v, t) {

View file

@ -11,10 +11,12 @@ import (
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io/fs"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"strconv"
"strings" "strings"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -55,6 +57,8 @@ const (
// privateKey prefix. // privateKey prefix.
privateHexPrefix = "privkey:" privateHexPrefix = "privkey:"
PermissionFallback = 0o700
) )
func MachinePublicKeyStripPrefix(machineKey key.MachinePublic) string { func MachinePublicKeyStripPrefix(machineKey key.MachinePublic) string {
@ -350,3 +354,14 @@ func AbsolutePathFromConfigPath(path string) string {
return path 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)
}