-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/vulnreport: add command vulnreport withdraw
Adds a command that makes it easier to withdraw an existing report. Usage: $ vulnreport -reason="..." withdraw NNN Change-Id: Iabe6c1a4b0d0ce15692bb6be743876a790dec437 Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/595996 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
- Loading branch information
Showing
5 changed files
with
81 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"time" | ||
|
||
"golang.org/x/vulndb/internal/osv" | ||
"golang.org/x/vulndb/internal/report" | ||
) | ||
|
||
var reason = flag.String("reason", "", "the reason this report is being withdrawn") | ||
|
||
type withdraw struct { | ||
*fixer | ||
*filenameParser | ||
} | ||
|
||
func (withdraw) name() string { return "withdraw" } | ||
|
||
func (withdraw) usage() (string, string) { | ||
const desc = "withdraws a report" | ||
return filenameArgs, desc | ||
} | ||
|
||
func (w *withdraw) setup(ctx context.Context, env environment) error { | ||
if *reason == "" { | ||
return fmt.Errorf("flag -reason must be provided") | ||
} | ||
w.fixer = new(fixer) | ||
w.filenameParser = new(filenameParser) | ||
return setupAll(ctx, env, w.fixer, w.filenameParser) | ||
} | ||
|
||
func (w *withdraw) close() error { | ||
return nil | ||
} | ||
|
||
func (w *withdraw) skip(input any) string { | ||
r := input.(*yamlReport) | ||
|
||
if r.IsExcluded() { | ||
return "excluded; can't be withdrawn" | ||
} | ||
|
||
if r.Withdrawn != nil { | ||
return "already withdrawn" | ||
} | ||
|
||
if r.CVEMetadata != nil { | ||
return "withdrawing Go-published report not yet supported" | ||
} | ||
|
||
return "" | ||
} | ||
|
||
func (w *withdraw) run(ctx context.Context, input any) (err error) { | ||
r := input.(*yamlReport) | ||
r.Withdrawn = &osv.Time{Time: time.Now()} | ||
r.Summary = "WITHDRAWN: " + r.Summary | ||
r.Description = report.Description( | ||
fmt.Sprintf("(This report has been withdrawn with reason: %q). %s", | ||
*reason, r.Description)) | ||
return w.fixAndWriteAll(ctx, r, false) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters