Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replacing credentials with asterisk #599

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ require (
github.com/aclements/go-moremath v0.0.0-20170210193428-033754ab1fee // indirect
github.com/atc0005/go-teams-notify/v2 v2.8.0
github.com/bluele/slack v0.0.0-20180528010058-b4b4d354a079 // indirect
github.com/buger/jsonparser v1.1.1 // indirect
github.com/coreos/go-oidc/v3 v3.6.0
github.com/dasrick/go-teams-notify/v2 v2.1.0 // indirect
github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect
Expand Down Expand Up @@ -133,6 +134,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.2 // indirect
github.com/hashicorp/vault/api v1.9.0
github.com/hashicorp/vault/api/auth/approle v0.4.0
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/jehiah/go-strftime v0.0.0-20171201141054-1d33003b3869 // indirect
github.com/juju/testing v0.0.0-20220203020004-a0ff61f03494 // indirect
github.com/klauspost/pgzip v1.2.6
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ github.com/bluele/slack v0.0.0-20180528010058-b4b4d354a079 h1:dm7wU6Dyf+rVGryOAB
github.com/bluele/slack v0.0.0-20180528010058-b4b4d354a079/go.mod h1:W679Ri2W93VLD8cVpEY/zLH1ow4zhJcCyjzrKxfM3QM=
github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d h1:7IjN4QP3c38xhg6wz8R3YjoU+6S9e7xBc0DAVLLIpHE=
github.com/bradfitz/gomemcache v0.0.0-20170208213004-1952afaa557d/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/bwesterb/go-ristretto v1.2.0/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cenkalti/backoff/v3 v3.0.0 h1:ske+9nBpD9qZsTBoF41nW5L+AIuFBKMeze18XQ3eG1c=
github.com/cenkalti/backoff/v3 v3.0.0/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
Expand Down Expand Up @@ -474,6 +476,8 @@ github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/hydrogen18/stalecucumber v0.0.0-20161215203336-0a94983f3e27 h1:gWNC2gGClIz7pzjw4zDXxDCgXw/KfPCWCnosj6s0Fj4=
github.com/hydrogen18/stalecucumber v0.0.0-20161215203336-0a94983f3e27/go.mod h1:KE5xQoh/IqNckSFoQXL5o5nEkrBiUDxatgac7TSMQ8Y=
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA=
Expand Down
38 changes: 30 additions & 8 deletions server/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ import (
"strings"
"time"

"github.com/buger/jsonparser"
"github.com/coreos/go-oidc/v3/oidc"
"github.com/iancoleman/strcase"
log "github.com/sirupsen/logrus"
"golang.org/x/oauth2"

Expand Down Expand Up @@ -505,17 +507,26 @@ func (repman *ReplicationManager) handlerMuxReplicationManager(w http.ResponseWr
cl = append(cl, cluster.Name)
}
}

mycopy.ClusterList = cl
e := json.NewEncoder(w)
e.SetIndent("", "\t")
err := e.Encode(mycopy)

//err := e.Encode(repman)
res, err := json.Marshal(mycopy)
if err != nil {
http.Error(w, "Error Marshal", 500)
return
}

for crkey, _ := range mycopy.Conf.Secrets {
res, err = jsonparser.Set(res, []byte(`"*:*" `), "config", strcase.ToLowerCamel(crkey))
}

if err != nil {
http.Error(w, "Encoding error", 500)
return
}

w.Header().Set("Content-Type", "application/json")
w.Write(res)
}

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

sort.Sort(cluster.ClusterSorter(clusters))

e := json.NewEncoder(w)
e.SetIndent("", "\t")
err := e.Encode(clusters)
cl, err := json.MarshalIndent(clusters, "", "\t")
if err != nil {
http.Error(w, "Encoding error", 500)
http.Error(w, "Error Marshal", 500)
return
}

for i, cluster := range clusters {
for crkey, _ := range cluster.Conf.Secrets {
cl, err = jsonparser.Set(cl, []byte(`"*:*" `), fmt.Sprintf("[%d]", i), "config", strcase.ToLowerCamel(crkey))
if err != nil {
http.Error(w, "Encoding error", 500)
return
}
}
}
w.Header().Set("Content-Type", "application/json")
w.Write(cl)

} else {
http.Error(w, "Unauthenticated", 401)
return
Expand Down
18 changes: 15 additions & 3 deletions server/api_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"strconv"
"strings"

"github.com/buger/jsonparser"
"github.com/codegangsta/negroni"
"github.com/iancoleman/strcase"
log "github.com/sirupsen/logrus"

"github.com/gorilla/mux"
Expand Down Expand Up @@ -1856,13 +1858,23 @@ func (repman *ReplicationManager) handlerMuxCluster(w http.ResponseWriter, r *ht
http.Error(w, "No valid ACL", 403)
return
}
e := json.NewEncoder(w)
e.SetIndent("", "\t")
err := e.Encode(mycluster)
cl, err := json.Marshal(mycluster)
if err != nil {
http.Error(w, "Error Marshal", 500)
return
}

for crkey, _ := range mycluster.Conf.Secrets {
cl, err = jsonparser.Set(cl, []byte(`"*:*" `), "config", strcase.ToLowerCamel(crkey))
}

if err != nil {
http.Error(w, "Encoding error", 500)
return
}

w.Header().Set("Content-Type", "application/json")
w.Write(cl)
} else {

http.Error(w, "No cluster", 500)
Expand Down