filebrowser/settings/settings.go
Henrique Dias 58ff28f84d feat: export generate key
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

Former-commit-id: 3088476c44d4608e2b8c90d3c274b6db17ef30c0 [formerly e40d3ba193e0b54bccce8c13459032f51af84c7b] [formerly 33cabf26abee5ef4f1dd63e423fe1b0fa7ae4f7c [formerly a3daac84a2]]
Former-commit-id: fe022f36fc4d7d8442df8c0fa4a86e2ff3ec328e [formerly 1d949d0ae88b3b5a9b8e4da5c3b6ca814a319589]
Former-commit-id: 36207ddeb7eba335f5fe73ea9dcdf6bffc6265bf
2019-01-11 20:25:39 +00:00

57 lines
1.4 KiB
Go

package settings
import (
"crypto/rand"
"strings"
"github.com/filebrowser/filebrowser/v2/rules"
)
// AuthMethod describes an authentication method.
type AuthMethod string
// Settings contain the main settings of the application.
type Settings struct {
Key []byte `json:"key"`
Signup bool `json:"signup"`
Defaults UserDefaults `json:"defaults"`
AuthMethod AuthMethod `json:"authMethod"`
Branding Branding `json:"branding"`
Commands map[string][]string `json:"commands"`
Shell []string `json:"shell"`
Rules []rules.Rule `json:"rules"`
}
// GetRules implements rules.Provider.
func (s *Settings) GetRules() []rules.Rule {
return s.Rules
}
// Server specific settings.
type Server struct {
Root string `json:"root"`
BaseURL string `json:"baseURL"`
TLSKey string `json:"tlsKey"`
TLSCert string `json:"tlsCert"`
Port string `json:"port"`
Address string `json:"address"`
Log string `json:"log"`
}
// Clean cleans any variables that might need cleaning.
func (s *Server) Clean() {
s.BaseURL = strings.TrimSuffix(s.BaseURL, "/")
}
// GenerateKey generates a key of 256 bits.
func GenerateKey() ([]byte, error) {
b := make([]byte, 64)
_, err := rand.Read(b)
// Note that err == nil only if we read len(b) bytes.
if err != nil {
return nil, err
}
return b, nil
}