Skip to content

Commit 05e607c

Browse files
authored
redact password from url (#53)
1 parent 624ad55 commit 05e607c

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

jsonrpc.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ func (client *rpcClient) doCall(ctx context.Context, RPCRequest *RPCRequest) (*R
434434
}
435435
httpResponse, err := client.httpClient.Do(httpRequest)
436436
if err != nil {
437-
return nil, fmt.Errorf("rpc call %v() on %v: %w", RPCRequest.Method, httpRequest.URL.String(), err)
437+
return nil, fmt.Errorf("rpc call %v() on %v: %w", RPCRequest.Method, httpRequest.URL.Redacted(), err)
438438
}
439439
defer httpResponse.Body.Close()
440440

@@ -452,10 +452,10 @@ func (client *rpcClient) doCall(ctx context.Context, RPCRequest *RPCRequest) (*R
452452
if httpResponse.StatusCode >= 400 {
453453
return nil, &HTTPError{
454454
Code: httpResponse.StatusCode,
455-
err: fmt.Errorf("rpc call %v() on %v status code: %v. could not decode body to rpc response: %w", RPCRequest.Method, httpRequest.URL.String(), httpResponse.StatusCode, err),
455+
err: fmt.Errorf("rpc call %v() on %v status code: %v. could not decode body to rpc response: %w", RPCRequest.Method, httpRequest.URL.Redacted(), httpResponse.StatusCode, err),
456456
}
457457
}
458-
return nil, fmt.Errorf("rpc call %v() on %v status code: %v. could not decode body to rpc response: %w", RPCRequest.Method, httpRequest.URL.String(), httpResponse.StatusCode, err)
458+
return nil, fmt.Errorf("rpc call %v() on %v status code: %v. could not decode body to rpc response: %w", RPCRequest.Method, httpRequest.URL.Redacted(), httpResponse.StatusCode, err)
459459
}
460460

461461
// response body empty
@@ -464,23 +464,23 @@ func (client *rpcClient) doCall(ctx context.Context, RPCRequest *RPCRequest) (*R
464464
if httpResponse.StatusCode >= 400 {
465465
return nil, &HTTPError{
466466
Code: httpResponse.StatusCode,
467-
err: fmt.Errorf("rpc call %v() on %v status code: %v. rpc response missing", RPCRequest.Method, httpRequest.URL.String(), httpResponse.StatusCode),
467+
err: fmt.Errorf("rpc call %v() on %v status code: %v. rpc response missing", RPCRequest.Method, httpRequest.URL.Redacted(), httpResponse.StatusCode),
468468
}
469469
}
470-
return nil, fmt.Errorf("rpc call %v() on %v status code: %v. rpc response missing", RPCRequest.Method, httpRequest.URL.String(), httpResponse.StatusCode)
470+
return nil, fmt.Errorf("rpc call %v() on %v status code: %v. rpc response missing", RPCRequest.Method, httpRequest.URL.Redacted(), httpResponse.StatusCode)
471471
}
472472

473473
// if we have a response body, but also a http error situation, return both
474474
if httpResponse.StatusCode >= 400 {
475475
if rpcResponse.Error != nil {
476476
return rpcResponse, &HTTPError{
477477
Code: httpResponse.StatusCode,
478-
err: fmt.Errorf("rpc call %v() on %v status code: %v. rpc response error: %v", RPCRequest.Method, httpRequest.URL.String(), httpResponse.StatusCode, rpcResponse.Error),
478+
err: fmt.Errorf("rpc call %v() on %v status code: %v. rpc response error: %v", RPCRequest.Method, httpRequest.URL.Redacted(), httpResponse.StatusCode, rpcResponse.Error),
479479
}
480480
}
481481
return rpcResponse, &HTTPError{
482482
Code: httpResponse.StatusCode,
483-
err: fmt.Errorf("rpc call %v() on %v status code: %v. no rpc error available", RPCRequest.Method, httpRequest.URL.String(), httpResponse.StatusCode),
483+
err: fmt.Errorf("rpc call %v() on %v status code: %v. no rpc error available", RPCRequest.Method, httpRequest.URL.Redacted(), httpResponse.StatusCode),
484484
}
485485
}
486486

@@ -494,7 +494,7 @@ func (client *rpcClient) doBatchCall(ctx context.Context, rpcRequest []*RPCReque
494494
}
495495
httpResponse, err := client.httpClient.Do(httpRequest)
496496
if err != nil {
497-
return nil, fmt.Errorf("rpc batch call on %v: %w", httpRequest.URL.String(), err)
497+
return nil, fmt.Errorf("rpc batch call on %v: %w", httpRequest.URL.Redacted(), err)
498498
}
499499
defer httpResponse.Body.Close()
500500

@@ -512,10 +512,10 @@ func (client *rpcClient) doBatchCall(ctx context.Context, rpcRequest []*RPCReque
512512
if httpResponse.StatusCode >= 400 {
513513
return nil, &HTTPError{
514514
Code: httpResponse.StatusCode,
515-
err: fmt.Errorf("rpc batch call on %v status code: %v. could not decode body to rpc response: %w", httpRequest.URL.String(), httpResponse.StatusCode, err),
515+
err: fmt.Errorf("rpc batch call on %v status code: %v. could not decode body to rpc response: %w", httpRequest.URL.Redacted(), httpResponse.StatusCode, err),
516516
}
517517
}
518-
return nil, fmt.Errorf("rpc batch call on %v status code: %v. could not decode body to rpc response: %w", httpRequest.URL.String(), httpResponse.StatusCode, err)
518+
return nil, fmt.Errorf("rpc batch call on %v status code: %v. could not decode body to rpc response: %w", httpRequest.URL.Redacted(), httpResponse.StatusCode, err)
519519
}
520520

521521
// response body empty
@@ -524,17 +524,17 @@ func (client *rpcClient) doBatchCall(ctx context.Context, rpcRequest []*RPCReque
524524
if httpResponse.StatusCode >= 400 {
525525
return nil, &HTTPError{
526526
Code: httpResponse.StatusCode,
527-
err: fmt.Errorf("rpc batch call on %v status code: %v. rpc response missing", httpRequest.URL.String(), httpResponse.StatusCode),
527+
err: fmt.Errorf("rpc batch call on %v status code: %v. rpc response missing", httpRequest.URL.Redacted(), httpResponse.StatusCode),
528528
}
529529
}
530-
return nil, fmt.Errorf("rpc batch call on %v status code: %v. rpc response missing", httpRequest.URL.String(), httpResponse.StatusCode)
530+
return nil, fmt.Errorf("rpc batch call on %v status code: %v. rpc response missing", httpRequest.URL.Redacted(), httpResponse.StatusCode)
531531
}
532532

533533
// if we have a response body, but also a http error, return both
534534
if httpResponse.StatusCode >= 400 {
535535
return rpcResponses, &HTTPError{
536536
Code: httpResponse.StatusCode,
537-
err: fmt.Errorf("rpc batch call on %v status code: %v. check rpc responses for potential rpc error", httpRequest.URL.String(), httpResponse.StatusCode),
537+
err: fmt.Errorf("rpc batch call on %v status code: %v. check rpc responses for potential rpc error", httpRequest.URL.Redacted(), httpResponse.StatusCode),
538538
}
539539
}
540540

0 commit comments

Comments
 (0)