mirror of
https://github.com/mudler/LocalAI.git
synced 2024-12-19 04:37:53 +00:00
c8dd8e5ef4
quiet more security scanner issues: pass one of chmod restriction to remove group and other permissions Signed-off-by: Dave Lee <dave@gray101.com>
43 lines
1.0 KiB
Go
43 lines
1.0 KiB
Go
package utils
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
)
|
|
|
|
func SaveConfig(filePath, fileName string, obj any) {
|
|
file, err := json.MarshalIndent(obj, "", " ")
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("failed to JSON marshal the uploadedFiles")
|
|
}
|
|
|
|
absolutePath := filepath.Join(filePath, fileName)
|
|
err = os.WriteFile(absolutePath, file, 0600)
|
|
if err != nil {
|
|
log.Error().Err(err).Str("filepath", absolutePath).Msg("failed to save configuration file")
|
|
}
|
|
}
|
|
|
|
func LoadConfig(filePath, fileName string, obj interface{}) {
|
|
uploadFilePath := filepath.Join(filePath, fileName)
|
|
|
|
_, err := os.Stat(uploadFilePath)
|
|
if os.IsNotExist(err) {
|
|
log.Debug().Msgf("No configuration file found at %s", uploadFilePath)
|
|
return
|
|
}
|
|
|
|
file, err := os.ReadFile(uploadFilePath)
|
|
if err != nil {
|
|
log.Error().Err(err).Str("filepath", uploadFilePath).Msg("failed to read file")
|
|
} else {
|
|
err = json.Unmarshal(file, &obj)
|
|
if err != nil {
|
|
log.Error().Err(err).Str("filepath", uploadFilePath).Msg("failed to parse file as JSON")
|
|
}
|
|
}
|
|
}
|