raft_internal_stringer.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2018 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package etcdserverpb
  15. import "fmt"
  16. // InternalRaftStringer implements custom proto Stringer:
  17. // redact password, shorten output(TODO).
  18. type InternalRaftStringer struct {
  19. Request *InternalRaftRequest
  20. }
  21. func (as *InternalRaftStringer) String() string {
  22. switch {
  23. case as.Request.LeaseGrant != nil:
  24. return fmt.Sprintf("header:<%s> lease_grant:<ttl:%d-second id:%016x>",
  25. as.Request.Header.String(),
  26. as.Request.LeaseGrant.TTL,
  27. as.Request.LeaseGrant.ID,
  28. )
  29. case as.Request.LeaseRevoke != nil:
  30. return fmt.Sprintf("header:<%s> lease_revoke:<id:%016x>",
  31. as.Request.Header.String(),
  32. as.Request.LeaseRevoke.ID,
  33. )
  34. case as.Request.Authenticate != nil:
  35. return fmt.Sprintf("header:<%s> authenticate:<name:%s simple_token:%s>",
  36. as.Request.Header.String(),
  37. as.Request.Authenticate.Name,
  38. as.Request.Authenticate.SimpleToken,
  39. )
  40. case as.Request.AuthUserAdd != nil:
  41. return fmt.Sprintf("header:<%s> auth_user_add:<name:%s>",
  42. as.Request.Header.String(),
  43. as.Request.AuthUserAdd.Name,
  44. )
  45. case as.Request.AuthUserChangePassword != nil:
  46. return fmt.Sprintf("header:<%s> auth_user_change_password:<name:%s>",
  47. as.Request.Header.String(),
  48. as.Request.AuthUserChangePassword.Name,
  49. )
  50. default:
  51. // nothing to redact
  52. }
  53. return as.Request.String()
  54. }