[vulndb] cmd/vulnreport, internal/database: export WriteJSON and re-use it in vulnreport

5 views
Skip to first unread message

Tatiana Bradley (Gerrit)

unread,
Sep 28, 2022, 6:15:55 PM9/28/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Tatiana Bradley has uploaded this change for review.

View Change

cmd/vulnreport, internal/database: export WriteJSON and re-use it in vulnreport

Change-Id: If607f602bf57207c490c680405a00aaa0855948d
---
M cmd/vulnreport/main.go
M internal/database/generate.go
2 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/cmd/vulnreport/main.go b/cmd/vulnreport/main.go
index 6b3af00..d66610e 100644
--- a/cmd/vulnreport/main.go
+++ b/cmd/vulnreport/main.go
@@ -551,12 +551,7 @@
// Write the OSV for non-excluded reports.
if r.Excluded == "" {
entry := database.GenerateOSVEntry(filename, time.Time{}, r)
- j, err := json.MarshalIndent(entry, "", " ")
- if err != nil {
- return err
- }
- jfilename := fmt.Sprintf("data/osv/%v.json", entry.ID)
- if err := os.WriteFile(jfilename, j, 0644); err != nil {
+ if err := database.WriteJSON(fmt.Sprintf("data/osv/%v.json", entry.ID), entry, true); err != nil {
return err
}
}
diff --git a/internal/database/generate.go b/internal/database/generate.go
index 6113cb8..4c7d3cb 100644
--- a/internal/database/generate.go
+++ b/internal/database/generate.go
@@ -86,7 +86,7 @@
}
}
}
- if err := writeJSON(filepath.Join(jsonDir, "index.json"), index, indent); err != nil {
+ if err := WriteJSON(filepath.Join(jsonDir, "index.json"), index, indent); err != nil {
return err
}
if err := writeAliasIndex(jsonDir, entries, indent); err != nil {
@@ -154,7 +154,7 @@
if err := os.MkdirAll(filepath.Dir(outPath), 0755); err != nil {
return fmt.Errorf("failed to create directory %q: %s", filepath.Dir(outPath), err)
}
- return writeJSON(outPath+".json", vulns, indent)
+ return WriteJSON(outPath+".json", vulns, indent)
}

func writeEntriesByID(idDir string, entries []osv.Entry, indent bool) error {
@@ -165,13 +165,13 @@
var idIndex []string
for _, e := range entries {
outPath := filepath.Join(idDir, e.ID+".json")
- if err := writeJSON(outPath, e, indent); err != nil {
+ if err := WriteJSON(outPath, e, indent); err != nil {
return err
}
idIndex = append(idIndex, e.ID)
}
// Write an index.json in the ID directory with a list of all the IDs.
- return writeJSON(filepath.Join(idDir, "index.json"), idIndex, indent)
+ return WriteJSON(filepath.Join(idDir, "index.json"), idIndex, indent)
}

// Write a JSON file containing a map from alias to GO IDs.
@@ -182,10 +182,10 @@
aliasToGoIDs[a] = append(aliasToGoIDs[a], e.ID)
}
}
- return writeJSON(filepath.Join(dir, "aliases.json"), aliasToGoIDs, indent)
+ return WriteJSON(filepath.Join(dir, "aliases.json"), aliasToGoIDs, indent)
}

-func writeJSON(filename string, value any, indent bool) (err error) {
+func WriteJSON(filename string, value any, indent bool) (err error) {
defer derrors.Wrap(&err, "writeJSON(%s)", filename)

j, err := jsonMarshal(value, indent)

To view, visit change 435464. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: vulndb
Gerrit-Branch: master
Gerrit-Change-Id: If607f602bf57207c490c680405a00aaa0855948d
Gerrit-Change-Number: 435464
Gerrit-PatchSet: 1
Gerrit-Owner: Tatiana Bradley <tat...@golang.org>
Gerrit-MessageType: newchange

Tatiana Bradley (Gerrit)

unread,
Sep 28, 2022, 6:17:00 PM9/28/22
to goph...@pubsubhelper.golang.org, Damien Neil, golang-co...@googlegroups.com

Attention is currently required from: Damien Neil.

Patch set 1:Run-TryBot +1

View Change

    To view, visit change 435464. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: vulndb
    Gerrit-Branch: master
    Gerrit-Change-Id: If607f602bf57207c490c680405a00aaa0855948d
    Gerrit-Change-Number: 435464
    Gerrit-PatchSet: 1
    Gerrit-Owner: Tatiana Bradley <tat...@golang.org>
    Gerrit-Reviewer: Damien Neil <dn...@google.com>
    Gerrit-Reviewer: Tatiana Bradley <tat...@golang.org>
    Gerrit-Attention: Damien Neil <dn...@google.com>
    Gerrit-Comment-Date: Wed, 28 Sep 2022 22:16:56 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Tatiana Bradley (Gerrit)

    unread,
    Sep 29, 2022, 11:03:25 AM9/29/22
    to goph...@pubsubhelper.golang.org, Gopher Robot, Damien Neil, golang-co...@googlegroups.com

    Attention is currently required from: Damien Neil.

    Patch set 2:Run-TryBot +1

    View Change

      To view, visit change 435464. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: vulndb
      Gerrit-Branch: master
      Gerrit-Change-Id: If607f602bf57207c490c680405a00aaa0855948d
      Gerrit-Change-Number: 435464
      Gerrit-PatchSet: 2
      Gerrit-Owner: Tatiana Bradley <tat...@golang.org>
      Gerrit-Reviewer: Damien Neil <dn...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Tatiana Bradley <tat...@golang.org>
      Gerrit-Attention: Damien Neil <dn...@google.com>
      Gerrit-Comment-Date: Thu, 29 Sep 2022 15:03:19 +0000

      Tatiana Bradley (Gerrit)

      unread,
      Sep 29, 2022, 12:42:57 PM9/29/22
      to goph...@pubsubhelper.golang.org, Gopher Robot, Damien Neil, golang-co...@googlegroups.com

      Attention is currently required from: Damien Neil.

      Patch set 2:Code-Review +1

      View Change

        To view, visit change 435464. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: vulndb
        Gerrit-Branch: master
        Gerrit-Change-Id: If607f602bf57207c490c680405a00aaa0855948d
        Gerrit-Change-Number: 435464
        Gerrit-PatchSet: 2
        Gerrit-Owner: Tatiana Bradley <tat...@golang.org>
        Gerrit-Reviewer: Damien Neil <dn...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Tatiana Bradley <tat...@golang.org>
        Gerrit-Attention: Damien Neil <dn...@google.com>
        Gerrit-Comment-Date: Thu, 29 Sep 2022 16:42:53 +0000

        Tatiana Bradley (Gerrit)

        unread,
        Sep 29, 2022, 12:43:22 PM9/29/22
        to goph...@pubsubhelper.golang.org, Gopher Robot, Damien Neil, golang-co...@googlegroups.com

        Attention is currently required from: Damien Neil.

        Patch set 2:-Code-Review

        View Change

          To view, visit change 435464. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: vulndb
          Gerrit-Branch: master
          Gerrit-Change-Id: If607f602bf57207c490c680405a00aaa0855948d
          Gerrit-Change-Number: 435464
          Gerrit-PatchSet: 2
          Gerrit-Owner: Tatiana Bradley <tat...@golang.org>
          Gerrit-Reviewer: Damien Neil <dn...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Tatiana Bradley <tat...@golang.org>
          Gerrit-Attention: Damien Neil <dn...@google.com>
          Gerrit-Comment-Date: Thu, 29 Sep 2022 16:43:18 +0000

          Damien Neil (Gerrit)

          unread,
          Sep 29, 2022, 1:29:28 PM9/29/22
          to Tatiana Bradley, goph...@pubsubhelper.golang.org, Gopher Robot, golang-co...@googlegroups.com

          Attention is currently required from: Tatiana Bradley.

          Patch set 2:Code-Review +2

          View Change

            To view, visit change 435464. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: vulndb
            Gerrit-Branch: master
            Gerrit-Change-Id: If607f602bf57207c490c680405a00aaa0855948d
            Gerrit-Change-Number: 435464
            Gerrit-PatchSet: 2
            Gerrit-Owner: Tatiana Bradley <tat...@golang.org>
            Gerrit-Reviewer: Damien Neil <dn...@google.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            Gerrit-Reviewer: Tatiana Bradley <tat...@golang.org>
            Gerrit-Attention: Tatiana Bradley <tat...@golang.org>
            Gerrit-Comment-Date: Thu, 29 Sep 2022 17:29:21 +0000

            Tatiana Bradley (Gerrit)

            unread,
            Sep 29, 2022, 1:59:09 PM9/29/22
            to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Damien Neil, Gopher Robot, golang-co...@googlegroups.com

            Tatiana Bradley submitted this change.

            View Change


            Approvals: Gopher Robot: TryBots succeeded Tatiana Bradley: Run TryBots Damien Neil: Looks good to me, approved
            cmd/vulnreport, internal/database: export WriteJSON and re-use it in vulnreport

            Change-Id: If607f602bf57207c490c680405a00aaa0855948d
            Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/435464
            TryBot-Result: Gopher Robot <go...@golang.org>
            Reviewed-by: Damien Neil <dn...@google.com>
            Run-TryBot: Tatiana Bradley <tat...@golang.org>

            ---
            M cmd/vulnreport/main.go
            M internal/database/generate.go
            2 files changed, 20 insertions(+), 12 deletions(-)

            To view, visit change 435464. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: vulndb
            Gerrit-Branch: master
            Gerrit-Change-Id: If607f602bf57207c490c680405a00aaa0855948d
            Gerrit-Change-Number: 435464
            Gerrit-PatchSet: 3
            Gerrit-Owner: Tatiana Bradley <tat...@golang.org>
            Gerrit-Reviewer: Damien Neil <dn...@google.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            Gerrit-Reviewer: Tatiana Bradley <tat...@golang.org>
            Gerrit-MessageType: merged
            Reply all
            Reply to author
            Forward
            0 new messages