chore_: ignore sensitive fields of WalletConfig when logging
This commit is contained in:
parent
c5e7ca3827
commit
b38a447b1b
|
@ -583,6 +583,20 @@ type WalletConfig struct {
|
||||||
EnableCelerBridge bool `json:"EnableCelerBridge"`
|
EnableCelerBridge bool `json:"EnableCelerBridge"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON custom marshalling to avoid exposing sensitive data in log,
|
||||||
|
// there's a function called `startNode` will log NodeConfig which include WalletConfig
|
||||||
|
func (wc WalletConfig) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Enabled bool `json:"Enabled"`
|
||||||
|
StatusProxyEnabled bool `json:"StatusProxyEnabled"`
|
||||||
|
EnableCelerBridge bool `json:"EnableCelerBridge"`
|
||||||
|
}{
|
||||||
|
Enabled: wc.Enabled,
|
||||||
|
StatusProxyEnabled: wc.StatusProxyEnabled,
|
||||||
|
EnableCelerBridge: wc.EnableCelerBridge,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// LocalNotificationsConfig extra configuration for localnotifications.Service.
|
// LocalNotificationsConfig extra configuration for localnotifications.Service.
|
||||||
type LocalNotificationsConfig struct {
|
type LocalNotificationsConfig struct {
|
||||||
Enabled bool
|
Enabled bool
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package params_test
|
package params_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"path"
|
"path"
|
||||||
|
@ -338,3 +339,22 @@ func TestNodeConfigValidate(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMarshalWalletConfigJSON(t *testing.T) {
|
||||||
|
walletConfig := params.WalletConfig{
|
||||||
|
OpenseaAPIKey: "some-key",
|
||||||
|
RaribleMainnetAPIKey: "some-key2",
|
||||||
|
}
|
||||||
|
bytes, err := json.Marshal(walletConfig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
// check if sensitive fields are not present
|
||||||
|
require.NotContains(t, string(bytes), "OpenseaAPIKey")
|
||||||
|
require.Contains(t, string(bytes), "StatusProxyEnabled")
|
||||||
|
|
||||||
|
// check if deserializing are still working with sensitive fields
|
||||||
|
walletConfig = params.WalletConfig{}
|
||||||
|
err = json.Unmarshal([]byte(`{"OpenseaAPIKey":"some-key", "StatusProxyEnabled":true}`), &walletConfig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, "some-key", walletConfig.OpenseaAPIKey)
|
||||||
|
require.True(t, walletConfig.StatusProxyEnabled)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue