-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
alter_user_scram_credentials_request.go
146 lines (123 loc) · 3.5 KB
/
alter_user_scram_credentials_request.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package sarama
type AlterUserScramCredentialsRequest struct {
Version int16
// Deletions represent list of SCRAM credentials to remove
Deletions []AlterUserScramCredentialsDelete
// Upsertions represent list of SCRAM credentials to update/insert
Upsertions []AlterUserScramCredentialsUpsert
}
type AlterUserScramCredentialsDelete struct {
Name string
Mechanism ScramMechanismType
}
type AlterUserScramCredentialsUpsert struct {
Name string
Mechanism ScramMechanismType
Iterations int32
Salt []byte
saltedPassword []byte
// This field is never transmitted over the wire
// @see: https://tools.ietf.org/html/rfc5802
Password []byte
}
func (r *AlterUserScramCredentialsRequest) encode(pe packetEncoder) error {
pe.putCompactArrayLength(len(r.Deletions))
for _, d := range r.Deletions {
if err := pe.putCompactString(d.Name); err != nil {
return err
}
pe.putInt8(int8(d.Mechanism))
pe.putEmptyTaggedFieldArray()
}
pe.putCompactArrayLength(len(r.Upsertions))
for _, u := range r.Upsertions {
if err := pe.putCompactString(u.Name); err != nil {
return err
}
pe.putInt8(int8(u.Mechanism))
pe.putInt32(u.Iterations)
if err := pe.putCompactBytes(u.Salt); err != nil {
return err
}
// do not transmit the password over the wire
formatter := scramFormatter{mechanism: u.Mechanism}
salted, err := formatter.saltedPassword(u.Password, u.Salt, int(u.Iterations))
if err != nil {
return err
}
if err := pe.putCompactBytes(salted); err != nil {
return err
}
pe.putEmptyTaggedFieldArray()
}
pe.putEmptyTaggedFieldArray()
return nil
}
func (r *AlterUserScramCredentialsRequest) decode(pd packetDecoder, version int16) error {
numDeletions, err := pd.getCompactArrayLength()
if err != nil {
return err
}
r.Deletions = make([]AlterUserScramCredentialsDelete, numDeletions)
for i := 0; i < numDeletions; i++ {
r.Deletions[i] = AlterUserScramCredentialsDelete{}
if r.Deletions[i].Name, err = pd.getCompactString(); err != nil {
return err
}
mechanism, err := pd.getInt8()
if err != nil {
return err
}
r.Deletions[i].Mechanism = ScramMechanismType(mechanism)
if _, err = pd.getEmptyTaggedFieldArray(); err != nil {
return err
}
}
numUpsertions, err := pd.getCompactArrayLength()
if err != nil {
return err
}
r.Upsertions = make([]AlterUserScramCredentialsUpsert, numUpsertions)
for i := 0; i < numUpsertions; i++ {
r.Upsertions[i] = AlterUserScramCredentialsUpsert{}
if r.Upsertions[i].Name, err = pd.getCompactString(); err != nil {
return err
}
mechanism, err := pd.getInt8()
if err != nil {
return err
}
r.Upsertions[i].Mechanism = ScramMechanismType(mechanism)
if r.Upsertions[i].Iterations, err = pd.getInt32(); err != nil {
return err
}
if r.Upsertions[i].Salt, err = pd.getCompactBytes(); err != nil {
return err
}
if r.Upsertions[i].saltedPassword, err = pd.getCompactBytes(); err != nil {
return err
}
if _, err = pd.getEmptyTaggedFieldArray(); err != nil {
return err
}
}
if _, err = pd.getEmptyTaggedFieldArray(); err != nil {
return err
}
return nil
}
func (r *AlterUserScramCredentialsRequest) key() int16 {
return 51
}
func (r *AlterUserScramCredentialsRequest) version() int16 {
return r.Version
}
func (r *AlterUserScramCredentialsRequest) headerVersion() int16 {
return 2
}
func (r *AlterUserScramCredentialsRequest) isValidVersion() bool {
return r.Version == 0
}
func (r *AlterUserScramCredentialsRequest) requiredVersion() KafkaVersion {
return V2_7_0_0
}