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