@@ -2,27 +2,29 @@ package cli
22
33import (
44 "fmt"
5- "regexp"
65 "strings"
76
87 "github.com/spf13/cobra"
98 v2 "github.com/wolfi-dev/wolfictl/pkg/configs/advisory/v2"
109 rwos "github.com/wolfi-dev/wolfictl/pkg/configs/rwfs/os"
1110)
1211
13- func cmdAdvisoryStream () * cobra.Command {
12+ func cmdAdvisoryMove () * cobra.Command {
1413 var dir string
1514 cmd := & cobra.Command {
16- Use : "stream < package-name> <version-streamed -package-name>" ,
17- Aliases : []string {"stream " },
18- Short : "Start version streaming for a package by moving its advisories into a new package." ,
19- Long : `Start version streaming for a package by moving its advisories into a new package.
15+ Use : "move <old- package-name> <new -package-name>" ,
16+ Aliases : []string {"mv " },
17+ Short : "Move a package's advisories into a new package." ,
18+ Long : `Move a package's advisories into a new package.
2019
2120This command will move most advisories for the given package into a new package. And rename the
2221package to the new package name. (i.e., from foo.advisories.yaml to foo-X.Y.advisories.yaml) If the
2322target file already exists, the command will try to merge the advisories. To ensure the advisories
2423are up-to-date, the command will start a scan for the new package.
2524
25+ This command is also useful to start version streaming for an existing package that has not been
26+ version streamed before. Especially that requires manual intervention to move the advisories.
27+
2628The command will move the latest event for each advisory, and will update the timestamp
2729of the event to now. The command will not copy events of type "detection", "fixed",
2830"analysis_not_planned", or "fix_not_planned".
@@ -36,10 +38,6 @@ of the event to now. The command will not copy events of type "detection", "fixe
3638 have = strings .TrimSuffix (have , ".advisories.yaml" )
3739 want = strings .TrimSuffix (want , ".advisories.yaml" )
3840
39- if err := checkPackageHasVersionStreamSuffix (want ); err != nil {
40- return err
41- }
42-
4341 advisoryFsys := rwos .DirFS (dir )
4442 advisoryCfgs , err := v2 .NewIndex (ctx , advisoryFsys )
4543 if err != nil {
@@ -71,8 +69,7 @@ of the event to now. The command will not copy events of type "detection", "fixe
7169 havePath := have + ".advisories.yaml"
7270 wantPath := want + ".advisories.yaml"
7371
74- // If automation already created the new advisory file before manual version streaming,
75- // respect the existing file and merge the advisories to it.
72+ // If the new file already exists, merge the old advisories to it and re-create.
7673 if shouldMergeExistings {
7774 newDoc := newEntry .Configuration ()
7875
@@ -102,16 +99,6 @@ of the event to now. The command will not copy events of type "detection", "fixe
10299 return cmd
103100}
104101
105- // checkPackageHasVersionStreamSuffix ensures the package name has the "-X" or "-X.Y" suffix.
106- // X and Y are positive integers.
107- func checkPackageHasVersionStreamSuffix (pkg string ) error {
108- re := regexp .MustCompile (`-\d+(\.\d+)?$` )
109- if re .MatchString (pkg ) {
110- return nil
111- }
112- return fmt .Errorf ("new package name %q does not have the version stream suffix" , pkg )
113- }
114-
115102// mergeExistingAdvisories merges the current advisories with the existing advisories.
116103func mergeExistingAdvisories (current , existing v2.Advisories ) v2.Advisories {
117104 res := make (v2.Advisories , 0 , len (current )+ len (existing ))
0 commit comments