Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <jcai@gitlab.com>2020-03-18 21:53:24 +0300
committerJohn Cai <jcai@gitlab.com>2020-03-26 02:29:43 +0300
commit345303d85b7671453e627a79d24125b25e8e0f3e (patch)
tree39b0defe2391f267a586927c2708e568af145cf0
parentc75c75c554acd51fa8394ae5579264aac9bf226c (diff)
Scrub token from node with custom json marshaller
-rw-r--r--internal/praefect/models/node.go13
-rw-r--r--internal/praefect/models/node_test.go16
2 files changed, 29 insertions, 0 deletions
diff --git a/internal/praefect/models/node.go b/internal/praefect/models/node.go
index 7c7144165..57cf3ac46 100644
--- a/internal/praefect/models/node.go
+++ b/internal/praefect/models/node.go
@@ -1,6 +1,7 @@
package models
import (
+ "encoding/json"
"fmt"
)
@@ -12,6 +13,18 @@ type Node struct {
DefaultPrimary bool `toml:"primary"`
}
+func (n Node) MarshalJSON() ([]byte, error) {
+ return json.Marshal(&struct {
+ Storage string `json:"storage"`
+ Address string `json:"address"`
+ Primary bool `json:"primary"`
+ }{
+ Storage: n.Storage,
+ Address: n.Address,
+ Primary: n.DefaultPrimary,
+ })
+}
+
// String prints out the node attributes but hiding the token
func (n Node) String() string {
return fmt.Sprintf("storage_name: %s, address: %s, primary: %v", n.Storage, n.Address, n.DefaultPrimary)
diff --git a/internal/praefect/models/node_test.go b/internal/praefect/models/node_test.go
index 64942711f..7cefdf7f1 100644
--- a/internal/praefect/models/node_test.go
+++ b/internal/praefect/models/node_test.go
@@ -1,6 +1,7 @@
package models
import (
+ "encoding/json"
"testing"
"github.com/stretchr/testify/require"
@@ -34,3 +35,18 @@ func TestRepository_Clone(t *testing.T) {
clone.Replicas[0].Address = "0.0.0.3"
require.Equal(t, "0.0.0.1", src.Replicas[0].Address)
}
+
+func TestNode_MarshalJSON(t *testing.T) {
+ token := "secretToken"
+ node := &Node{
+ Storage: "storage",
+ Address: "address",
+ Token: token,
+ DefaultPrimary: true,
+ }
+
+ b, err := json.Marshal(node)
+ require.NoError(t, err)
+ require.NotContains(t, string(b), "token")
+ require.NotContains(t, string(b), token)
+}