Skip to content

Commit

Permalink
Revert "feat: modify metadata structure for providers' pull date (#1795
Browse files Browse the repository at this point in the history
…)" (#1846)

This reverts commit 4584423.

Signed-off-by: Arvind Somya <arvind.somya@anchore.com>
  • Loading branch information
asomya committed May 6, 2024
1 parent c6bbb6b commit 88b6139
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 51 deletions.
33 changes: 12 additions & 21 deletions grype/db/metadata.go
Expand Up @@ -18,23 +18,16 @@ const MetadataFileName = "metadata.json"
// Metadata represents the basic identifying information of a database flat file (built/version) and a way to
// verify the contents (checksum).
type Metadata struct {
Built time.Time
Version int
Checksum string
Providers []Provider
}

type Provider struct {
Name string `json:"name"`
LastSuccessfulRun time.Time `json:"lastSuccessfulRun"`
Built time.Time
Version int
Checksum string
}

// MetadataJSON is a helper struct for parsing and assembling Metadata objects to and from JSON.
type MetadataJSON struct {
Built string `json:"built"` // RFC 3339
Version int `json:"version"`
Checksum string `json:"checksum"`
Providers []Provider `json:"providers,omitempty"`
Built string `json:"built"` // RFC 3339
Version int `json:"version"`
Checksum string `json:"checksum"`
}

// ToMetadata converts a MetadataJSON object to a Metadata object.
Expand All @@ -45,10 +38,9 @@ func (m MetadataJSON) ToMetadata() (Metadata, error) {
}

metadata := Metadata{
Built: build.UTC(),
Version: m.Version,
Checksum: m.Checksum,
Providers: m.Providers,
Built: build.UTC(),
Version: m.Version,
Checksum: m.Checksum,
}

return metadata, nil
Expand Down Expand Up @@ -127,10 +119,9 @@ func (m Metadata) String() string {
// Write out a Metadata object to the given path.
func (m Metadata) Write(toPath string) error {
metadata := MetadataJSON{
Built: m.Built.UTC().Format(time.RFC3339),
Version: m.Version,
Checksum: m.Checksum,
Providers: m.Providers,
Built: m.Built.UTC().Format(time.RFC3339),
Version: m.Version,
Checksum: m.Checksum,
}

contents, err := json.MarshalIndent(&metadata, "", " ")
Expand Down
20 changes: 0 additions & 20 deletions grype/db/metadata_test.go
Expand Up @@ -20,16 +20,6 @@ func TestMetadataParse(t *testing.T) {
Built: time.Date(2020, 06, 15, 14, 02, 36, 0, time.UTC),
Version: 2,
Checksum: "sha256:dcd6a285c839a7c65939e20c251202912f64826be68609dfc6e48df7f853ddc8",
Providers: []Provider{
{
Name: "nvd",
LastSuccessfulRun: time.Date(2020, 05, 15, 12, 02, 45, 0, time.UTC),
},
{
Name: "alpine",
LastSuccessfulRun: time.Date(2020, 05, 15, 13, 02, 55, 0, time.UTC),
},
},
},
},
{
Expand All @@ -38,16 +28,6 @@ func TestMetadataParse(t *testing.T) {
Built: time.Date(2020, 06, 15, 18, 02, 36, 0, time.UTC),
Version: 2,
Checksum: "sha256:dcd6a285c839a7c65939e20c251202912f64826be68609dfc6e48df7f853ddc8",
Providers: []Provider{
{
Name: "nvd",
LastSuccessfulRun: time.Date(2020, 05, 15, 12, 02, 45, 0, time.UTC),
},
{
Name: "alpine",
LastSuccessfulRun: time.Date(2020, 05, 15, 13, 02, 55, 0, time.UTC),
},
},
},
},
{
Expand Down
6 changes: 1 addition & 5 deletions grype/db/test-fixtures/metadata-edt-timezone/metadata.json
Expand Up @@ -3,9 +3,5 @@
"updated": "2020-06-15T14:02:36-04:00",
"last-check": "2020-06-15T14:02:36-04:00",
"version": 2,
"checksum": "sha256:dcd6a285c839a7c65939e20c251202912f64826be68609dfc6e48df7f853ddc8",
"providers": [
{"name": "nvd", "lastSuccessfulRun": "2020-05-15T12:02:45Z"},
{"name": "alpine", "lastSuccessfulRun": "2020-05-15T13:02:55Z"}
]
"checksum": "sha256:dcd6a285c839a7c65939e20c251202912f64826be68609dfc6e48df7f853ddc8"
}
6 changes: 1 addition & 5 deletions grype/db/test-fixtures/metadata-gocase/metadata.json
@@ -1,9 +1,5 @@
{
"built": "2020-06-15T14:02:36Z",
"version": 2,
"checksum": "sha256:dcd6a285c839a7c65939e20c251202912f64826be68609dfc6e48df7f853ddc8",
"providers": [
{"name": "nvd", "lastSuccessfulRun": "2020-05-15T12:02:45Z"},
{"name": "alpine", "lastSuccessfulRun": "2020-05-15T13:02:55Z"}
]
"checksum": "sha256:dcd6a285c839a7c65939e20c251202912f64826be68609dfc6e48df7f853ddc8"
}

0 comments on commit 88b6139

Please sign in to comment.