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

DNM: cga check #1079

Draft
wants to merge 1 commit into
base: main
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
16 changes: 10 additions & 6 deletions pkg/advisory/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"slices"
"strings"

"github.com/samber/lo"

Expand All @@ -26,20 +27,23 @@ func (req Request) Validate() error {
return errors.New("package cannot be empty")
}

if len(req.Aliases) == 0 {
aliases := req.Aliases
if id := req.VulnerabilityID; id != "" {
if strings.HasPrefix(id, "CGA-") {
return errors.New("vulnerability should be empty (or not start with CGA)")
}
aliases = append(aliases, id)
}
if len(aliases) == 0 {
return errors.New("aliases should have at least one vulnerability ID")
}

if err := errors.Join(lo.Map(req.Aliases, func(alias string, _ int) error {
if err := errors.Join(lo.Map(aliases, func(alias string, _ int) error {
return vuln.ValidateID(alias)
})...); err != nil {
return err
}

if req.VulnerabilityID != "" {
return errors.New("vulnerability should be empty")
}

if req.Event.IsZero() {
return errors.New("event cannot be zero")
}
Expand Down