new: migrating config to toml

This commit is contained in:
Simone Margaritelli
2024-04-04 15:22:34 -04:00
parent 04f6fb7270
commit b3bed64938
3 changed files with 18 additions and 4 deletions

View File

@@ -11,10 +11,13 @@ import (
"encoding/json"
"errors"
"os"
"path"
"strings"
"github.com/evilsocket/arc/utils"
"github.com/evilsocket/islazy/log"
"github.com/evilsocket/islazy/tui"
"github.com/pelletier/go-toml"
"golang.org/x/crypto/bcrypt"
)
@@ -130,15 +133,23 @@ var Conf = Configuration{
// Load function convert a loaded JSON config file to a config struct
// return err if secret param is empty
func Load(filename string) error {
log.Info("Loading configuration from %s ...", tui.Bold(filename))
log.Info("loading configuration from %s ...", tui.Bold(filename))
raw, err := os.ReadFile(filename)
if err != nil {
return err
}
err = json.Unmarshal(raw, &Conf)
if err != nil {
return err
ext := strings.ToLower(path.Ext(filename))
if ext == ".json" {
log.Warning("the use of a json configuration file is deprecated, please migrate to toml")
if err = json.Unmarshal(raw, &Conf); err != nil {
return err
}
} else {
// default to toml
if err = toml.Unmarshal(raw, &Conf); err != nil {
return err
}
}
if Conf.Secret == "" {

1
go.mod
View File

@@ -9,6 +9,7 @@ require (
github.com/gin-gonic/contrib v0.0.0-20190923054218-35076c1b2bea
github.com/gin-gonic/gin v1.4.0
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/stretchr/testify v1.4.0
github.com/theckman/go-flock v0.7.1
golang.org/x/crypto v0.0.0-20191117063200-497ca9f6d64f

2
go.sum
View File

@@ -21,6 +21,8 @@ github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc
github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8=
github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=