Changing password and use cache when uploading

This commit is contained in:
Aurélie Delhaie
2022-05-29 17:56:03 +02:00
parent d0ee7df3f5
commit 7a8672ce80
7 changed files with 239 additions and 93 deletions

View File

@@ -2,6 +2,7 @@ package config
import (
"flag"
"golang.org/x/crypto/bcrypt"
"gopkg.in/yaml.v3"
"log"
"os"
@@ -31,7 +32,8 @@ type DatabaseConfiguration struct {
}
type FeaturesConfiguration struct {
AllowRegister bool `yaml:"allow_register"`
AllowRegister bool `yaml:"allow_register"`
PasswordHashCost *int `yaml:"password_hash_cost"`
}
var currentConfig *Configuration
@@ -47,6 +49,22 @@ func init() {
if err != nil {
log.Fatalf("error: %s", err)
}
checkConfig()
}
func checkConfig() {
if currentConfig.Features.PasswordHashCost == nil {
currentConfig.Features.PasswordHashCost = new(int)
*currentConfig.Features.PasswordHashCost = bcrypt.DefaultCost
} else if *currentConfig.Features.PasswordHashCost < bcrypt.MinCost && *currentConfig.Features.PasswordHashCost > bcrypt.MaxCost {
log.Fatalf("password_hash_cost is not on the supported range (%d < x < %d)", bcrypt.MinCost, bcrypt.MaxCost)
}
if _, err := os.Stat(currentConfig.Path.Storage); err != nil {
log.Fatal(err)
}
if _, err := os.Stat(currentConfig.Path.Cache); err != nil {
log.Fatal(err)
}
}
func Database() *DatabaseConfiguration {