@@ -4,66 +4,41 @@ package encrypted
4
4
type EncryptionAction int
5
5
6
6
const (
7
- // EncryptNone indicates that no encryption should be applied.
8
- EncryptNone EncryptionAction = iota
9
- // EncryptStandard indicates the attribute should be encrypted using a standard algorithm.
10
- EncryptStandard
11
- // EncryptDeterministic indicates the attribute should be encrypted deterministically for consistent outcomes.
12
- EncryptDeterministic
7
+ EncryptNone EncryptionAction = iota // No encryption should be applied.
8
+ EncryptStandard // The attribute should be encrypted using a standard algorithm.
9
+ EncryptDeterministic // The attribute should be encrypted deterministically for consistent outcomes.
13
10
// Additional encryption actions can be defined here.
14
11
)
15
12
16
- // CompressionAction represents the compression action to be taken on a specific attribute.
17
- type CompressionAction int
18
-
19
- const (
20
- // CompressNone indicates no compression should be applied.
21
- CompressNone CompressionAction = iota
22
- // CompressGzip indicates the attribute should be compressed using GZip.
23
- CompressGzip
24
- // CompressZstd indicates the attribute should be compressed using Zstd.
25
- CompressZstd
26
- )
27
-
28
- // ClientConfig holds the configuration for client operations like encryption and compression.
13
+ // ClientConfig holds the configuration for client operations, focusing on encryption.
29
14
type ClientConfig struct {
30
- Encryption EncryptionConfig
31
- Compression CompressionConfig
15
+ Encryption EncryptionConfig
32
16
}
33
17
34
- // EncryptionConfig holds encryption-specific settings.
18
+ // EncryptionConfig holds encryption-specific settings, including a default action and specific actions for named attributes .
35
19
type EncryptionConfig struct {
36
- DefaultAction EncryptionAction
37
- SpecificActions map [string ]EncryptionAction
38
- }
39
-
40
- // CompressionConfig holds compression-specific settings.
41
- type CompressionConfig struct {
42
- DefaultAction CompressionAction
43
- SpecificActions map [string ]CompressionAction
20
+ DefaultAction EncryptionAction // The default encryption action if no specific action is provided.
21
+ SpecificActions map [string ]EncryptionAction // Map of attribute names to their specific encryption actions.
44
22
}
45
23
46
- // NewClientConfig creates a new ClientConfig with provided options.
24
+ // NewClientConfig initializes a new ClientConfig, applying any provided functional options.
47
25
func NewClientConfig (options ... Option ) * ClientConfig {
48
26
config := & ClientConfig {
49
27
Encryption : EncryptionConfig {
50
- DefaultAction : EncryptNone ,
28
+ DefaultAction : EncryptNone , // Default to no encryption unless specified.
51
29
SpecificActions : make (map [string ]EncryptionAction ),
52
30
},
53
- Compression : CompressionConfig {
54
- DefaultAction : CompressNone ,
55
- SpecificActions : make (map [string ]CompressionAction ),
56
- },
57
31
}
58
32
33
+ // Apply each provided option to the ClientConfig.
59
34
for _ , option := range options {
60
35
option (config )
61
36
}
62
37
63
38
return config
64
39
}
65
40
66
- // Option applies a configuration to a ClientConfig.
41
+ // Option defines a function signature for options that modify ClientConfig.
67
42
type Option func (* ClientConfig )
68
43
69
44
// WithDefaultEncryptionAction sets the default encryption action for the client.
@@ -73,12 +48,19 @@ func WithDefaultEncryption(action EncryptionAction) Option {
73
48
}
74
49
}
75
50
76
- // WithEncryption sets an encryption action for a specific attribute.
51
+ // WithEncryption sets a specific encryption action for a named attribute.
77
52
func WithEncryption (attributeName string , action EncryptionAction ) Option {
78
53
return func (c * ClientConfig ) {
79
- if c .Encryption .SpecificActions == nil {
80
- c .Encryption .SpecificActions = make (map [string ]EncryptionAction )
81
- }
82
54
c .Encryption .SpecificActions [attributeName ] = action
83
55
}
84
56
}
57
+
58
+ // EncryptedClientOption defines a function signature for options that modify an EncryptedClient.
59
+ type EncryptedClientOption func (* EncryptedClient )
60
+
61
+ // WithClientConfig sets the EncryptedClient's configuration.
62
+ func WithClientConfig (config * ClientConfig ) EncryptedClientOption {
63
+ return func (ec * EncryptedClient ) {
64
+ ec .ClientConfig = config
65
+ }
66
+ }
0 commit comments