Browse Source

#36 Hotfix

dependabot/npm_and_yarn/web/prismjs-1.21.0
Max Schmitt 8 years ago
parent
commit
477cf2de16
  1. 9
      handlers/auth_test.go
  2. 12
      util/config.go
  3. 2
      util/private.go

9
handlers/auth_test.go

@ -42,14 +42,9 @@ var (
func TestCreateBackend(t *testing.T) {
secret = util.GetPrivateKey()
viper.SetConfigName("config")
viper.AddConfigPath("../")
util.SetConfigDefaults()
err := viper.ReadInConfig()
if err != nil {
t.Fatalf("could not reload config file: %v", err)
}
if err := util.CheckForDatadir(); err != nil {
viper.Set("General.DataDir", "../data")
if err := util.ReadInConfig(); err != nil {
t.Fatalf("could not reload config file: %v", err)
}
store, err := store.New(logrus.New())

12
util/config.go

@ -11,21 +11,23 @@ import (
var dataDirPath string
// ReadInConfig loads the configuration and other needed folders for further usage
func ReadInConfig() error {
viper.AutomaticEnv()
viper.SetEnvPrefix("gus")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetConfigName("config")
viper.AddConfigPath(".")
SetConfigDefaults()
setConfigDefaults()
err := viper.ReadInConfig()
if err != nil {
return errors.Wrap(err, "could not reload config file")
}
return CheckForDatadir()
return checkForDatadir()
}
func SetConfigDefaults() {
// setConfigDefaults sets the default values for the configuration
func setConfigDefaults() {
viper.SetDefault("http.ListenAddr", ":8080")
viper.SetDefault("http.BaseURL", "http://localhost:3000")
@ -34,11 +36,13 @@ func SetConfigDefaults() {
viper.SetDefault("General.ShortedIDLength", 4)
}
// GetDataDir returns the absolute path of the data directory
func GetDataDir() string {
return dataDirPath
}
func CheckForDatadir() error {
// checkForDatadir checks for the data dir and creates it if it not exists
func checkForDatadir() error {
var err error
dataDirPath, err = filepath.Abs(viper.GetString("General.DataDir"))
if err != nil {

2
util/private.go

@ -11,6 +11,7 @@ import (
var privateKey []byte
// CheckForPrivateKey checks if already an private key exists, if not one will be randomly generated
func CheckForPrivateKey() error {
privateDat := filepath.Join(GetDataDir(), "private.dat")
d, err := ioutil.ReadFile(privateDat)
@ -31,6 +32,7 @@ func CheckForPrivateKey() error {
return nil
}
// GetPrivateKey returns the private key from the memory
func GetPrivateKey() []byte {
return privateKey
}

Loading…
Cancel
Save