diff --git a/libs/wallet/provider/uphold/uphold.go b/libs/wallet/provider/uphold/uphold.go index 4acf95185..f860b47c0 100644 --- a/libs/wallet/provider/uphold/uphold.go +++ b/libs/wallet/provider/uphold/uphold.go @@ -17,6 +17,7 @@ import ( "net/http/httputil" "net/url" "os" + "regexp" "strconv" "strings" "time" @@ -236,6 +237,7 @@ func submit( if err != nil { return nil, resp, fmt.Errorf("%w: %s", errorutils.ErrFailedBodyRead, err.Error()) } + sbody := redactUnneededContent(string(body)) if logger != nil { logger.Debug(). @@ -243,18 +245,18 @@ func submit( Str("type", "http.Response"). Int("status", resp.StatusCode). Str("headers", string(jsonHeaders)). - Msg(string(body)) + Msg(sbody) } if resp.StatusCode/100 != 2 { var uhErr upholdError - if json.Unmarshal(body, &uhErr) != nil { - return nil, resp, fmt.Errorf("Error %d, %s", resp.StatusCode, body) + if json.Unmarshal([]byte(sbody), &uhErr) != nil { + return nil, resp, fmt.Errorf("Error %d, %s", resp.StatusCode, sbody) } uhErr.RequestID = resp.Header.Get("Request-Id") return nil, resp, uhErr } - return body, resp, nil + return []byte(sbody), resp, nil } type createCardRequest struct { @@ -1180,3 +1182,14 @@ func FundWallet(ctx context.Context, destWallet *Wallet, amount decimal.Decimal) return balance.TotalProbi, nil } + +var redactRegexp = []regexp.Regexp{ + *regexp.MustCompile(`"description":\s*"[^"]+"\s*,?`), + *regexp.MustCompile(`"\w+Country":\s*"[^"]+"\s*,?`), +} +func redactUnneededContent(sbody string) string { + for _, re := range redactRegexp { + sbody = re.ReplaceAllString(sbody, "") + } + return strings.ReplaceAll(sbody, ",}", "}") +} diff --git a/libs/wallet/provider/uphold/uphold_test.go b/libs/wallet/provider/uphold/uphold_test.go index 84d5f023f..16bcaf918 100644 --- a/libs/wallet/provider/uphold/uphold_test.go +++ b/libs/wallet/provider/uphold/uphold_test.go @@ -3,6 +3,7 @@ package uphold import ( "context" "encoding/hex" + "encoding/json" "errors" "net/http" "net/url" @@ -351,3 +352,14 @@ func requireDonorWallet(t *testing.T) *Wallet { return &Wallet{Info: info, PrivKey: privateKey, PubKey: publicKey} } + +func TestRedactUnneeded(t *testing.T) { + response := `{"description":"some unneeded content","OKCountry":"foo","TestCountry":"bar","NoMatch": true}` + result := `{"NoMatch": true}` + testValue := redactUnneededContent(response) + assert.Equal(t, result, testValue) + var dat map[string]interface{} + if err := json.Unmarshal([]byte(testValue), &dat); err != nil { + t.Fatal(err) + } +}