Skip to content

Commit

Permalink
Add filters.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit91 committed Oct 2, 2023
1 parent 1497133 commit 7e557f3
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cmd/metal-api/internal/issues/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func AllIssueTypes() []IssueType {
}
}

func newIssueFromType(t IssueType) (issueImpl, error) {
func NewIssueFromType(t IssueType) (issueImpl, error) {
switch t {
case IssueTypeNoPartition:
return &IssueNoPartition{}, nil
Expand Down
57 changes: 49 additions & 8 deletions cmd/metal-api/internal/service/machine-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,55 @@ func (r *machineResource) issues(request *restful.Request, response *restful.Res
return
}

ms := metal.Machines{}
var (
ms = metal.Machines{}

severity = issues.IssueSeverityMinor
only []issues.IssueType
omit []issues.IssueType
lastErrorThreshold = issues.DefaultLastErrorThreshold()
)

if requestPayload.Severity != "" {
severity, err = issues.SeverityFromString(requestPayload.Severity)
if err != nil {
r.sendError(request, response, httperrors.BadRequest(err))
return
}
}

if len(requestPayload.Omit) > 0 {
for _, o := range requestPayload.Omit {
o := o

_, err := issues.NewIssueFromType(o)
if err != nil {
r.sendError(request, response, httperrors.BadRequest(err))
return
}

omit = append(omit, o)
}
}

if len(requestPayload.Only) > 0 {
for _, o := range requestPayload.Only {
o := o

_, err := issues.NewIssueFromType(o)
if err != nil {
r.sendError(request, response, httperrors.BadRequest(err))
return
}

only = append(only, o)
}
}

if requestPayload.LastErrorThreshold > 0 {
lastErrorThreshold = requestPayload.LastErrorThreshold
}

err = r.ds.SearchMachines(&requestPayload.MachineSearchQuery, &ms)
if err != nil {
r.sendError(request, response, defaultError(err))
Expand All @@ -516,13 +564,6 @@ func (r *machineResource) issues(request *restful.Request, response *restful.Res
return
}

var (
severity = issues.IssueSeverityMinor
only []issues.IssueType
omit []issues.IssueType
lastErrorThreshold = issues.DefaultLastErrorThreshold()
)

issues, err := issues.FindIssues(&issues.IssueConfig{
Machines: ms,
EventContainers: ecs,
Expand Down

0 comments on commit 7e557f3

Please sign in to comment.