diff --git a/cmd/initializer.go b/cmd/initializer.go index b7f3a8db..63240f6b 100644 --- a/cmd/initializer.go +++ b/cmd/initializer.go @@ -9,6 +9,7 @@ import ( "github.com/mayswind/lab/pkg/datastore" "github.com/mayswind/lab/pkg/log" "github.com/mayswind/lab/pkg/settings" + "github.com/mayswind/lab/pkg/utils" "github.com/mayswind/lab/pkg/uuid" ) @@ -64,8 +65,22 @@ func initializeSystem(c *cli.Context) (*settings.Config, error) { return nil, err } - cfgJson, _ := json.Marshal(config) + cfgJson, _ := json.Marshal(getConfigWithNoSensitiveData(config)) log.BootInfof("[initializer.initializeSystem] has loaded configuration %s", cfgJson) return config, nil } + +func getConfigWithNoSensitiveData(config *settings.Config) *settings.Config { + clonedConfig := &settings.Config{} + err := utils.Clone(config, clonedConfig) + + if err != nil { + return config + } + + clonedConfig.DatabaseConfig.DatabasePassword = "****" + clonedConfig.SecretKey = "****" + + return clonedConfig +} diff --git a/pkg/utils/object.go b/pkg/utils/object.go new file mode 100644 index 00000000..bbcce1e6 --- /dev/null +++ b/pkg/utils/object.go @@ -0,0 +1,22 @@ +package utils + +import ( + "bytes" + "encoding/gob" +) + +func Clone(src, dst interface{}) error { + var buf bytes.Buffer + + if err := gob.NewEncoder(&buf).Encode(src); err != nil { + return err + } + + err := gob.NewDecoder(bytes.NewBuffer(buf.Bytes())).Decode(dst) + + if err != nil { + return err + } + + return nil +}