()
| 12 | ) |
| 13 | |
| 14 | func GetConfig() { |
| 15 | MigrateConfigIfNeeded() |
| 16 | |
| 17 | fileData, err := os.ReadFile("./config.yml") |
| 18 | |
| 19 | if err != nil { |
| 20 | log.Fatalf("Error reading config file: %s", err) |
| 21 | } |
| 22 | |
| 23 | err = yaml.Unmarshal(fileData, &config.Config) |
| 24 | if err != nil { |
| 25 | log.Fatalf("Config.yml parse error: %v", err) |
| 26 | } |
| 27 | |
| 28 | config.Config.SizeBytes = ConvertStringToBytes(config.Config.StorageLimit) |
| 29 | |
| 30 | config.Config.Folder = strings.TrimPrefix(config.Config.Folder, "./") |
| 31 | |
| 32 | if config.Config.SecretJwtKey == "" || |
| 33 | config.Config.SecretJwtKey == "auto" || |
| 34 | config.Config.SecretJwtKey == "you must change it" { |
| 35 | jwtKey, err := GenerateJWTKey() |
| 36 | if err != nil { |
| 37 | fmt.Println("Error while generating jwt key, the easiest way to fix it is manually setting the secret jwt key property in config.yml") |
| 38 | panic(err) |
| 39 | } |
| 40 | fmt.Println("New JWT key has been generated!") |
| 41 | config.Config.SecretJwtKey = jwtKey |
| 42 | |
| 43 | err = UpdateConfigWithNewJWTKey(jwtKey) |
| 44 | |
| 45 | if err != nil { |
| 46 | fmt.Printf("Error while saving autogenerated JWT key to config.yml: %v\n", err) |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | func UpdateConfigWithNewJWTKey(jwtKey string) error { |
| 52 | file, err := os.Open("./config.yml") |
no test coverage detected