describe_client_quotas_request.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package sarama
  2. // DescribeClientQuotas Request (Version: 0) => [components] strict
  3. // components => entity_type match_type match
  4. // entity_type => STRING
  5. // match_type => INT8
  6. // match => NULLABLE_STRING
  7. // strict => BOOLEAN
  8. // A filter to be applied to matching client quotas.
  9. // Components: the components to filter on
  10. // Strict: whether the filter only includes specified components
  11. type DescribeClientQuotasRequest struct {
  12. Version int16
  13. Components []QuotaFilterComponent
  14. Strict bool
  15. }
  16. // Describe a component for applying a client quota filter.
  17. // EntityType: the entity type the filter component applies to ("user", "client-id", "ip")
  18. // MatchType: the match type of the filter component (any, exact, default)
  19. // Match: the name that's matched exactly (used when MatchType is QuotaMatchExact)
  20. type QuotaFilterComponent struct {
  21. EntityType QuotaEntityType
  22. MatchType QuotaMatchType
  23. Match string
  24. }
  25. func (d *DescribeClientQuotasRequest) encode(pe packetEncoder) error {
  26. // Components
  27. if err := pe.putArrayLength(len(d.Components)); err != nil {
  28. return err
  29. }
  30. for _, c := range d.Components {
  31. if err := c.encode(pe); err != nil {
  32. return err
  33. }
  34. }
  35. // Strict
  36. pe.putBool(d.Strict)
  37. return nil
  38. }
  39. func (d *DescribeClientQuotasRequest) decode(pd packetDecoder, version int16) error {
  40. // Components
  41. componentCount, err := pd.getArrayLength()
  42. if err != nil {
  43. return err
  44. }
  45. if componentCount > 0 {
  46. d.Components = make([]QuotaFilterComponent, componentCount)
  47. for i := range d.Components {
  48. c := QuotaFilterComponent{}
  49. if err = c.decode(pd, version); err != nil {
  50. return err
  51. }
  52. d.Components[i] = c
  53. }
  54. } else {
  55. d.Components = []QuotaFilterComponent{}
  56. }
  57. // Strict
  58. strict, err := pd.getBool()
  59. if err != nil {
  60. return err
  61. }
  62. d.Strict = strict
  63. return nil
  64. }
  65. func (d *QuotaFilterComponent) encode(pe packetEncoder) error {
  66. // EntityType
  67. if err := pe.putString(string(d.EntityType)); err != nil {
  68. return err
  69. }
  70. // MatchType
  71. pe.putInt8(int8(d.MatchType))
  72. // Match
  73. if d.MatchType == QuotaMatchAny {
  74. if err := pe.putNullableString(nil); err != nil {
  75. return err
  76. }
  77. } else if d.MatchType == QuotaMatchDefault {
  78. if err := pe.putString(""); err != nil {
  79. return err
  80. }
  81. } else {
  82. if err := pe.putString(d.Match); err != nil {
  83. return err
  84. }
  85. }
  86. return nil
  87. }
  88. func (d *QuotaFilterComponent) decode(pd packetDecoder, version int16) error {
  89. // EntityType
  90. entityType, err := pd.getString()
  91. if err != nil {
  92. return err
  93. }
  94. d.EntityType = QuotaEntityType(entityType)
  95. // MatchType
  96. matchType, err := pd.getInt8()
  97. if err != nil {
  98. return err
  99. }
  100. d.MatchType = QuotaMatchType(matchType)
  101. // Match
  102. match, err := pd.getNullableString()
  103. if err != nil {
  104. return err
  105. }
  106. if match != nil {
  107. d.Match = *match
  108. }
  109. return nil
  110. }
  111. func (d *DescribeClientQuotasRequest) key() int16 {
  112. return 48
  113. }
  114. func (d *DescribeClientQuotasRequest) version() int16 {
  115. return d.Version
  116. }
  117. func (d *DescribeClientQuotasRequest) headerVersion() int16 {
  118. return 1
  119. }
  120. func (d *DescribeClientQuotasRequest) isValidVersion() bool {
  121. return d.Version == 0
  122. }
  123. func (d *DescribeClientQuotasRequest) requiredVersion() KafkaVersion {
  124. return V2_6_0_0
  125. }