Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/csprofiles: default duration and type for partial configuration #3038

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions pkg/csprofiles/csprofiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
Logger *log.Entry `json:"-" yaml:"-"`
}

const defaultDuration = "4h"
const (
defaultDuration = "4h"
defaultType = "ban"
)

func NewProfile(profilesCfg []*csconfig.ProfileCfg) ([]*Runtime, error) {
var err error
Expand Down Expand Up @@ -77,7 +80,7 @@
for _, decision := range profile.Decisions {
if runtime.RuntimeDurationExpr == nil {
var duration string
if decision.Duration != nil {
if decision.Duration != nil && *decision.Duration != "" {
duration = *decision.Duration
} else {
runtime.Logger.Warningf("No duration specified for %s, using default duration %s", profile.Name, defaultDuration)
Expand Down Expand Up @@ -121,8 +124,10 @@
/*some fields are populated from the reference object : duration, scope, type*/

decision.Duration = new(string)
if refDecision.Duration != nil {
if refDecision.Duration != nil && *refDecision.Duration != "" {
*decision.Duration = *refDecision.Duration
} else {
*decision.Duration = defaultDuration
}

if Profile.Cfg.DurationExpr != "" && Profile.RuntimeDurationExpr != nil {
Expand All @@ -145,7 +150,11 @@
}

decision.Type = new(string)
*decision.Type = *refDecision.Type
if refDecision.Type != nil && *refDecision.Type != "" {
*decision.Type = *refDecision.Type
} else {
*decision.Type = defaultType
}

Check warning on line 157 in pkg/csprofiles/csprofiles.go

View check run for this annotation

Codecov / codecov/patch

pkg/csprofiles/csprofiles.go#L156-L157

Added lines #L156 - L157 were not covered by tests

/*for the others, let's populate it from the alert and its source*/
decision.Value = new(string)
Expand Down
Loading