Skip to content

Commit 4e0fc38

Browse files
committed
Psuedo discriminator for "params"
1 parent a918c46 commit 4e0fc38

File tree

1 file changed

+45
-31
lines changed
  • internal/kibana/security_detection_rule

1 file changed

+45
-31
lines changed

internal/kibana/security_detection_rule/models.go

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,40 +3946,54 @@ func convertEndpointResponseActionToModel(ctx context.Context, endpointAction kb
39463946
// Convert endpoint params
39473947
paramsModel := ResponseActionParamsModel{}
39483948

3949-
// TODO use discriminator
3950-
if processesParams, err := endpointAction.Params.AsSecurityDetectionsAPIProcessesParams(); err == nil && processesParams.Config.Field != "" {
3951-
paramsModel.Command = types.StringValue(string(processesParams.Command))
3952-
if processesParams.Comment != nil {
3953-
paramsModel.Comment = types.StringPointerValue(processesParams.Comment)
3954-
} else {
3955-
paramsModel.Comment = types.StringNull()
3956-
}
3949+
commandParams, err := endpointAction.Params.AsSecurityDetectionsAPIDefaultParams()
3950+
if err == nil {
3951+
switch commandParams.Command {
3952+
case "isolate":
3953+
defaultParams, err := endpointAction.Params.AsSecurityDetectionsAPIDefaultParams()
3954+
if err != nil {
3955+
diags.AddError("Failed to parse endpoint default params", fmt.Sprintf("Error: %s", err.Error()))
3956+
} else {
3957+
paramsModel.Command = types.StringValue(string(defaultParams.Command))
3958+
if defaultParams.Comment != nil {
3959+
paramsModel.Comment = types.StringPointerValue(defaultParams.Comment)
3960+
} else {
3961+
paramsModel.Comment = types.StringNull()
3962+
}
3963+
paramsModel.Config = types.ObjectNull(endpointProcessConfigElementType().AttrTypes)
3964+
}
3965+
case "kill-process", "suspend-process":
3966+
processesParams, err := endpointAction.Params.AsSecurityDetectionsAPIProcessesParams()
3967+
if err != nil {
3968+
diags.AddError("Failed to parse endpoint processes params", fmt.Sprintf("Error: %s", err.Error()))
3969+
} else {
3970+
paramsModel.Command = types.StringValue(string(processesParams.Command))
3971+
if processesParams.Comment != nil {
3972+
paramsModel.Comment = types.StringPointerValue(processesParams.Comment)
3973+
} else {
3974+
paramsModel.Comment = types.StringNull()
3975+
}
39573976

3958-
// Convert config
3959-
configModel := EndpointProcessConfigModel{
3960-
Field: types.StringValue(processesParams.Config.Field),
3961-
}
3962-
if processesParams.Config.Overwrite != nil {
3963-
configModel.Overwrite = types.BoolPointerValue(processesParams.Config.Overwrite)
3964-
} else {
3965-
configModel.Overwrite = types.BoolNull()
3966-
}
3977+
// Convert config
3978+
configModel := EndpointProcessConfigModel{
3979+
Field: types.StringValue(processesParams.Config.Field),
3980+
}
3981+
if processesParams.Config.Overwrite != nil {
3982+
configModel.Overwrite = types.BoolPointerValue(processesParams.Config.Overwrite)
3983+
} else {
3984+
configModel.Overwrite = types.BoolNull()
3985+
}
39673986

3968-
configObjectValue, configDiags := types.ObjectValueFrom(ctx, endpointProcessConfigElementType().AttrTypes, configModel)
3969-
if configDiags.HasError() {
3970-
diags.Append(configDiags...)
3971-
} else {
3972-
paramsModel.Config = configObjectValue
3973-
}
3974-
} else if defaultParams, err := endpointAction.Params.AsSecurityDetectionsAPIDefaultParams(); err == nil {
3975-
paramsModel.Command = types.StringValue(string(defaultParams.Command))
3976-
if defaultParams.Comment != nil {
3977-
paramsModel.Comment = types.StringPointerValue(defaultParams.Comment)
3978-
} else {
3979-
paramsModel.Comment = types.StringNull()
3987+
configObjectValue, configDiags := types.ObjectValueFrom(ctx, endpointProcessConfigElementType().AttrTypes, configModel)
3988+
if configDiags.HasError() {
3989+
diags.Append(configDiags...)
3990+
} else {
3991+
paramsModel.Config = configObjectValue
3992+
}
3993+
}
39803994
}
3981-
paramsModel.Config = types.ObjectNull(endpointProcessConfigElementType().AttrTypes)
3982-
3995+
} else {
3996+
diags.AddError("Unknown endpoint command", fmt.Sprintf("Unsupported endpoint command: %s. Error: %s", commandParams.Command, err.Error()))
39833997
}
39843998

39853999
// Set osquery fields to null since this is endpoint

0 commit comments

Comments
 (0)