Skip to content

Commit

Permalink
rename command to move
Browse files Browse the repository at this point in the history
Signed-off-by: Dentrax <[email protected]>
  • Loading branch information
Dentrax committed Jul 11, 2024
1 parent 3eeddb4 commit a844bf3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
## wolfictl advisory stream
## wolfictl advisory move

Start version streaming for a package by moving its advisories into a new package.
Move a package's advisories into a new package.

***Aliases**: stream*
***Aliases**: mv*

### Usage

```
wolfictl advisory stream <package-name> <version-streamed-package-name>
wolfictl advisory move <old-package-name> <new-package-name>
```

### Synopsis

Start version streaming for a package by moving its advisories into a new package.
Move a package's advisories into a new package.

This command will move most advisories for the given package into a new package. And rename the
package to the new package name. (i.e., from foo.advisories.yaml to foo-X.Y.advisories.yaml) If the
target file already exists, the command will try to merge the advisories. To ensure the advisories
are up-to-date, the command will start a scan for the new package.

This command is also useful to start version streaming for an existing package that has not been
version streamed before. Especially that requires manual intervention to move the advisories.

The command will move the latest event for each advisory, and will update the timestamp
of the event to now. The command will not copy events of type "detection", "fixed",
"analysis_not_planned", or "fix_not_planned".
Expand All @@ -28,7 +31,7 @@ of the event to now. The command will not copy events of type "detection", "fixe

```
-d, --dir string directory containing the advisories to copy (default ".")
-h, --help help for stream
-h, --help help for move
```

### Options inherited from parent commands
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
.TH "WOLFICTL\-ADVISORY\-STREAM" "1" "" "Auto generated by spf13/cobra" ""
.TH "WOLFICTL\-ADVISORY\-MOVE" "1" "" "Auto generated by spf13/cobra" ""
.nh
.ad l


.SH NAME
.PP
wolfictl\-advisory\-stream \- Start version streaming for a package by moving its advisories into a new package.
wolfictl\-advisory\-move \- Move a package's advisories into a new package.


.SH SYNOPSIS
.PP
\fBwolfictl advisory stream <package-name> <version-streamed-package-name>\fP
\fBwolfictl advisory move <old-package-name> <new-package-name>\fP


.SH DESCRIPTION
.PP
Start version streaming for a package by moving its advisories into a new package.
Move a package's advisories into a new package.

.PP
This command will move most advisories for the given package into a new package. And rename the
package to the new package name. (i.e., from foo.advisories.yaml to foo\-X.Y.advisories.yaml) If the
target file already exists, the command will try to merge the advisories. To ensure the advisories
are up\-to\-date, the command will start a scan for the new package.

.PP
This command is also useful to start version streaming for an existing package that has not been
version streamed before. Especially that requires manual intervention to move the advisories.

.PP
The command will move the latest event for each advisory, and will update the timestamp
of the event to now. The command will not copy events of type "detection", "fixed",
Expand All @@ -36,7 +40,7 @@ of the event to now. The command will not copy events of type "detection", "fixe

.PP
\fB\-h\fP, \fB\-\-help\fP[=false]
help for stream
help for move


.SH OPTIONS INHERITED FROM PARENT COMMANDS
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/advisory.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func cmdAdvisory() *cobra.Command {
cmdAdvisorySecDB(),
cmdAdvisoryUpdate(),
cmdAdvisoryValidate(),
cmdAdvisoryStream(),
cmdAdvisoryMove(),
)

return cmd
Expand Down
31 changes: 9 additions & 22 deletions pkg/cli/advisory_stream.go → pkg/cli/advisory_move.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ package cli

import (
"fmt"
"regexp"
"strings"

"github.com/spf13/cobra"
v2 "github.com/wolfi-dev/wolfictl/pkg/configs/advisory/v2"
rwos "github.com/wolfi-dev/wolfictl/pkg/configs/rwfs/os"
)

func cmdAdvisoryStream() *cobra.Command {
func cmdAdvisoryMove() *cobra.Command {
var dir string
cmd := &cobra.Command{
Use: "stream <package-name> <version-streamed-package-name>",
Aliases: []string{"stream"},
Short: "Start version streaming for a package by moving its advisories into a new package.",
Long: `Start version streaming for a package by moving its advisories into a new package.
Use: "move <old-package-name> <new-package-name>",
Aliases: []string{"mv"},
Short: "Move a package's advisories into a new package.",
Long: `Move a package's advisories into a new package.
This command will move most advisories for the given package into a new package. And rename the
package to the new package name. (i.e., from foo.advisories.yaml to foo-X.Y.advisories.yaml) If the
target file already exists, the command will try to merge the advisories. To ensure the advisories
are up-to-date, the command will start a scan for the new package.
This command is also useful to start version streaming for an existing package that has not been
version streamed before. Especially that requires manual intervention to move the advisories.
The command will move the latest event for each advisory, and will update the timestamp
of the event to now. The command will not copy events of type "detection", "fixed",
"analysis_not_planned", or "fix_not_planned".
Expand All @@ -36,10 +38,6 @@ of the event to now. The command will not copy events of type "detection", "fixe
have = strings.TrimSuffix(have, ".advisories.yaml")
want = strings.TrimSuffix(want, ".advisories.yaml")

if err := checkPackageHasVersionStreamSuffix(want); err != nil {
return err
}

advisoryFsys := rwos.DirFS(dir)
advisoryCfgs, err := v2.NewIndex(ctx, advisoryFsys)
if err != nil {
Expand Down Expand Up @@ -71,8 +69,7 @@ of the event to now. The command will not copy events of type "detection", "fixe
havePath := have + ".advisories.yaml"
wantPath := want + ".advisories.yaml"

// If automation already created the new advisory file before manual version streaming,
// respect the existing file and merge the advisories to it.
// If the new file already exists, merge the old advisories to it and re-create.
if shouldMergeExistings {
newDoc := newEntry.Configuration()

Expand Down Expand Up @@ -102,16 +99,6 @@ of the event to now. The command will not copy events of type "detection", "fixe
return cmd
}

// checkPackageHasVersionStreamSuffix ensures the package name has the "-X" or "-X.Y" suffix.
// X and Y are positive integers.
func checkPackageHasVersionStreamSuffix(pkg string) error {
re := regexp.MustCompile(`-\d+(\.\d+)?$`)
if re.MatchString(pkg) {
return nil
}
return fmt.Errorf("new package name %q does not have the version stream suffix", pkg)
}

// mergeExistingAdvisories merges the current advisories with the existing advisories.
func mergeExistingAdvisories(current, existing v2.Advisories) v2.Advisories {
res := make(v2.Advisories, 0, len(current)+len(existing))
Expand Down

0 comments on commit a844bf3

Please sign in to comment.