@@ -11,7 +11,53 @@ import (
1111 "github.com/hashicorp/terraform-plugin-framework/types"
1212)
1313
14- func (d SecurityDetectionRuleData ) toEqlRuleCreateProps (ctx context.Context , client clients.MinVersionEnforceable ) (kbapi.SecurityDetectionsAPIRuleCreateProps , diag.Diagnostics ) {
14+ type EqlRuleProcessor struct {}
15+
16+ func (e EqlRuleProcessor ) HandlesRuleType (t string ) bool {
17+ return t == "eql"
18+ }
19+
20+ func (e EqlRuleProcessor ) ToCreateProps (ctx context.Context , client clients.MinVersionEnforceable , d SecurityDetectionRuleData ) (kbapi.SecurityDetectionsAPIRuleCreateProps , diag.Diagnostics ) {
21+ return toEqlRuleCreateProps (ctx , client , d )
22+ }
23+
24+ func (e EqlRuleProcessor ) ToUpdateProps (ctx context.Context , client clients.MinVersionEnforceable , d SecurityDetectionRuleData ) (kbapi.SecurityDetectionsAPIRuleUpdateProps , diag.Diagnostics ) {
25+ return toEqlRuleUpdateProps (ctx , client , d )
26+ }
27+
28+ func (e EqlRuleProcessor ) HandlesAPIRuleResponse (rule any ) bool {
29+ _ , ok := rule .(kbapi.SecurityDetectionsAPIEqlRule )
30+ return ok
31+ }
32+
33+ func (e EqlRuleProcessor ) UpdateFromResponse (ctx context.Context , rule any , d * SecurityDetectionRuleData ) diag.Diagnostics {
34+ var diags diag.Diagnostics
35+ value , ok := rule .(kbapi.SecurityDetectionsAPIEqlRule )
36+ if ! ok {
37+ diags .AddError (
38+ "Error extracting rule ID" ,
39+ "Could not extract rule ID from response" ,
40+ )
41+ return diags
42+ }
43+
44+ return updateFromEqlRule (ctx , & value , d )
45+ }
46+
47+ func (e EqlRuleProcessor ) ExtractId (response any ) (string , diag.Diagnostics ) {
48+ var diags diag.Diagnostics
49+ value , ok := response .(kbapi.SecurityDetectionsAPIEqlRule )
50+ if ! ok {
51+ diags .AddError (
52+ "Error extracting rule ID" ,
53+ "Could not extract rule ID from response" ,
54+ )
55+ return "" , diags
56+ }
57+ return value .Id .String (), diags
58+ }
59+
60+ func toEqlRuleCreateProps (ctx context.Context , client clients.MinVersionEnforceable , d SecurityDetectionRuleData ) (kbapi.SecurityDetectionsAPIRuleCreateProps , diag.Diagnostics ) {
1561 var diags diag.Diagnostics
1662 var createProps kbapi.SecurityDetectionsAPIRuleCreateProps
1763
@@ -77,7 +123,7 @@ func (d SecurityDetectionRuleData) toEqlRuleCreateProps(ctx context.Context, cli
77123
78124 return createProps , diags
79125}
80- func ( d SecurityDetectionRuleData ) toEqlRuleUpdateProps (ctx context.Context , client clients.MinVersionEnforceable ) (kbapi.SecurityDetectionsAPIRuleUpdateProps , diag.Diagnostics ) {
126+ func toEqlRuleUpdateProps (ctx context.Context , client clients.MinVersionEnforceable , d SecurityDetectionRuleData ) (kbapi.SecurityDetectionsAPIRuleUpdateProps , diag.Diagnostics ) {
81127 var diags diag.Diagnostics
82128 var updateProps kbapi.SecurityDetectionsAPIRuleUpdateProps
83129
@@ -162,7 +208,7 @@ func (d SecurityDetectionRuleData) toEqlRuleUpdateProps(ctx context.Context, cli
162208
163209 return updateProps , diags
164210}
165- func ( d * SecurityDetectionRuleData ) updateFromEqlRule (ctx context.Context , rule * kbapi.SecurityDetectionsAPIEqlRule ) diag.Diagnostics {
211+ func updateFromEqlRule (ctx context.Context , rule * kbapi.SecurityDetectionsAPIEqlRule , d * SecurityDetectionRuleData ) diag.Diagnostics {
166212 var diags diag.Diagnostics
167213
168214 compId := clients.CompositeId {
0 commit comments