@@ -17,6 +17,7 @@ limitations under the License.
17
17
package types
18
18
19
19
import (
20
+ "iter"
20
21
"slices"
21
22
"strings"
22
23
"time"
@@ -43,6 +44,16 @@ type SessionRecordingConfig interface {
43
44
// SetProxyChecksHostKeys sets if the proxy will check host keys.
44
45
SetProxyChecksHostKeys (bool )
45
46
47
+ // GetEncrypted gets if session recordings should be encrypted or not.
48
+ GetEncrypted () bool
49
+
50
+ // GetEncryptionKeys gets the encryption keys for the session recording config.
51
+ GetEncryptionKeys () []* AgeEncryptionKey
52
+
53
+ // SetEncryptionKeys sets the encryption keys for the session recording config.
54
+ // It returns true if there was a change applied and false otherwise.
55
+ SetEncryptionKeys (iter.Seq [* AgeEncryptionKey ]) bool
56
+
46
57
// Clone returns a copy of the resource.
47
58
Clone () SessionRecordingConfig
48
59
}
@@ -163,6 +174,56 @@ func (c *SessionRecordingConfigV2) SetProxyChecksHostKeys(t bool) {
163
174
c .Spec .ProxyChecksHostKeys = NewBoolOption (t )
164
175
}
165
176
177
+ // GetEncrypted gets if session recordings should be encrypted or not.
178
+ func (c * SessionRecordingConfigV2 ) GetEncrypted () bool {
179
+ encryption := c .Spec .Encryption
180
+ if encryption == nil {
181
+ return false
182
+ }
183
+
184
+ return encryption .Enabled
185
+ }
186
+
187
+ // GetEncryptionKeys gets the encryption keys for the session recording config.
188
+ func (c * SessionRecordingConfigV2 ) GetEncryptionKeys () []* AgeEncryptionKey {
189
+ if c .Status != nil {
190
+ return c .Status .EncryptionKeys
191
+ }
192
+
193
+ return nil
194
+ }
195
+
196
+ // SetEncryptionKeys sets the encryption keys for the session recording config.
197
+ // It returns true if there was a change applied and false otherwise.
198
+ func (c * SessionRecordingConfigV2 ) SetEncryptionKeys (keys iter.Seq [* AgeEncryptionKey ]) bool {
199
+ existingKeys := make (map [string ]struct {})
200
+ for _ , key := range c .GetEncryptionKeys () {
201
+ existingKeys [string (key .PublicKey )] = struct {}{}
202
+ }
203
+
204
+ var keysChanged bool
205
+ var newKeys []* AgeEncryptionKey
206
+ addedKeys := make (map [string ]struct {})
207
+ for key := range keys {
208
+ if _ , exists := existingKeys [string (key .PublicKey )]; ! exists {
209
+ keysChanged = true
210
+ }
211
+
212
+ if _ , added := addedKeys [string (key .PublicKey )]; ! added {
213
+ addedKeys [string (key .PublicKey )] = struct {}{}
214
+ newKeys = append (newKeys , key )
215
+ }
216
+
217
+ }
218
+
219
+ if c .Status == nil {
220
+ c .Status = & SessionRecordingConfigStatus {}
221
+ }
222
+ c .Status .EncryptionKeys = newKeys
223
+
224
+ return keysChanged || len (existingKeys ) != len (addedKeys )
225
+ }
226
+
166
227
// Clone returns a copy of the resource.
167
228
func (c * SessionRecordingConfigV2 ) Clone () SessionRecordingConfig {
168
229
return utils .CloneProtoMsg (c )
0 commit comments