Skip to content

Commit aa89467

Browse files
authored
Merge pull request #599 from signal18/caff_dev
replacing credentials with asterisk
2 parents 83086cb + e2e5950 commit aa89467

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ require (
102102
github.com/aclements/go-moremath v0.0.0-20170210193428-033754ab1fee // indirect
103103
github.com/atc0005/go-teams-notify/v2 v2.8.0
104104
github.com/bluele/slack v0.0.0-20180528010058-b4b4d354a079 // indirect
105+
github.com/buger/jsonparser v1.1.1 // indirect
105106
github.com/coreos/go-oidc/v3 v3.6.0
106107
github.com/dasrick/go-teams-notify/v2 v2.1.0 // indirect
107108
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
@@ -133,6 +134,7 @@ require (
133134
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
134135
github.com/hashicorp/vault/api v1.9.0
135136
github.com/hashicorp/vault/api/auth/approle v0.4.0
137+
github.com/iancoleman/strcase v0.3.0 // indirect
136138
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
137139
github.com/juju/testing v0.0.0-20220203020004-a0ff61f03494 // indirect
138140
github.com/klauspost/pgzip v1.2.6

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ github.com/bluele/slack v0.0.0-20180528010058-b4b4d354a079 h1:dm7wU6Dyf+rVGryOAB
118118
github.com/bluele/slack v0.0.0-20180528010058-b4b4d354a079/go.mod h1:W679Ri2W93VLD8cVpEY/zLH1ow4zhJcCyjzrKxfM3QM=
119119
github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d h1:7IjN4QP3c38xhg6wz8R3YjoU+6S9e7xBc0DAVLLIpHE=
120120
github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
121+
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
122+
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
121123
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
122124
github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c=
123125
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
@@ -474,6 +476,8 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
474476
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
475477
github.com/hydrogen18/stalecucumber v0.0.0-20161215203336-0a94983f3e27 h1:gWNC2gGClIz7pzjw4zDXxDCgXw/KfPCWCnosj6s0Fj4=
476478
github.com/hydrogen18/stalecucumber v0.0.0-20161215203336-0a94983f3e27/go.mod h1:KE5xQoh/IqNckSFoQXL5o5nEkrBiUDxatgac7TSMQ8Y=
479+
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
480+
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
477481
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
478482
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
479483
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=

server/api.go

+30-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/buger/jsonparser"
2627
"github.com/coreos/go-oidc/v3/oidc"
28+
"github.com/iancoleman/strcase"
2729
log "github.com/sirupsen/logrus"
2830
"golang.org/x/oauth2"
2931

@@ -505,17 +507,26 @@ func (repman *ReplicationManager) handlerMuxReplicationManager(w http.ResponseWr
505507
cl = append(cl, cluster.Name)
506508
}
507509
}
510+
508511
mycopy.ClusterList = cl
509-
e := json.NewEncoder(w)
510-
e.SetIndent("", "\t")
511-
err := e.Encode(mycopy)
512512

513-
//err := e.Encode(repman)
513+
res, err := json.Marshal(mycopy)
514+
if err != nil {
515+
http.Error(w, "Error Marshal", 500)
516+
return
517+
}
518+
519+
for crkey, _ := range mycopy.Conf.Secrets {
520+
res, err = jsonparser.Set(res, []byte(`"*:*" `), "config", strcase.ToLowerCamel(crkey))
521+
}
522+
514523
if err != nil {
515524
http.Error(w, "Encoding error", 500)
516525
return
517526
}
518527

528+
w.Header().Set("Content-Type", "application/json")
529+
w.Write(res)
519530
}
520531

521532
func (repman *ReplicationManager) handlerMuxAddUser(w http.ResponseWriter, r *http.Request) {
@@ -549,13 +560,24 @@ func (repman *ReplicationManager) handlerMuxClusters(w http.ResponseWriter, r *h
549560

550561
sort.Sort(cluster.ClusterSorter(clusters))
551562

552-
e := json.NewEncoder(w)
553-
e.SetIndent("", "\t")
554-
err := e.Encode(clusters)
563+
cl, err := json.MarshalIndent(clusters, "", "\t")
555564
if err != nil {
556-
http.Error(w, "Encoding error", 500)
565+
http.Error(w, "Error Marshal", 500)
557566
return
558567
}
568+
569+
for i, cluster := range clusters {
570+
for crkey, _ := range cluster.Conf.Secrets {
571+
cl, err = jsonparser.Set(cl, []byte(`"*:*" `), fmt.Sprintf("[%d]", i), "config", strcase.ToLowerCamel(crkey))
572+
if err != nil {
573+
http.Error(w, "Encoding error", 500)
574+
return
575+
}
576+
}
577+
}
578+
w.Header().Set("Content-Type", "application/json")
579+
w.Write(cl)
580+
559581
} else {
560582
http.Error(w, "Unauthenticated", 401)
561583
return

server/api_cluster.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import (
1414
"strconv"
1515
"strings"
1616

17+
"github.com/buger/jsonparser"
1718
"github.com/codegangsta/negroni"
19+
"github.com/iancoleman/strcase"
1820
log "github.com/sirupsen/logrus"
1921

2022
"github.com/gorilla/mux"
@@ -1856,13 +1858,23 @@ func (repman *ReplicationManager) handlerMuxCluster(w http.ResponseWriter, r *ht
18561858
http.Error(w, "No valid ACL", 403)
18571859
return
18581860
}
1859-
e := json.NewEncoder(w)
1860-
e.SetIndent("", "\t")
1861-
err := e.Encode(mycluster)
1861+
cl, err := json.Marshal(mycluster)
1862+
if err != nil {
1863+
http.Error(w, "Error Marshal", 500)
1864+
return
1865+
}
1866+
1867+
for crkey, _ := range mycluster.Conf.Secrets {
1868+
cl, err = jsonparser.Set(cl, []byte(`"*:*" `), "config", strcase.ToLowerCamel(crkey))
1869+
}
1870+
18621871
if err != nil {
18631872
http.Error(w, "Encoding error", 500)
18641873
return
18651874
}
1875+
1876+
w.Header().Set("Content-Type", "application/json")
1877+
w.Write(cl)
18661878
} else {
18671879

18681880
http.Error(w, "No cluster", 500)

0 commit comments

Comments
 (0)