-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. New debian source will added in new buckets, called debain-salsa 7/ debian-salsa 8 etc 2. CVE and advisory relation is captured in advisory bucket. If a CVE is fixed inside a advisory, that advisory ID is saved along with CVE. 3. All advisory details are saved in vulnerability bucket. 4. In ubuntu needs-traiged status CVEs are also captured into bolt DB now. 5. Added advisory details for Amazon Linux
- Loading branch information
Showing
11 changed files
with
406 additions
and
24 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
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,82 @@ | ||
package db | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/aquasecurity/trivy-db/pkg/types" | ||
bolt "go.etcd.io/bbolt" | ||
"golang.org/x/xerrors" | ||
) | ||
|
||
const ( | ||
securityAdvisoryBucket = "security-advisory" | ||
) | ||
|
||
func (dbc Config) GetSecurityAdvisoryDetails(cveId string) (types.SecurityAdvisories, error) { | ||
SecurityAdvisories := types.SecurityAdvisories{} | ||
err := db.View(func(tx *bolt.Tx) error { | ||
root := tx.Bucket([]byte(securityAdvisoryBucket)) | ||
if root == nil { | ||
return nil | ||
} | ||
cveBucket := root.Bucket([]byte(cveId)) | ||
if cveBucket == nil { | ||
return nil | ||
} | ||
err := cveBucket.ForEach(func(platform, v []byte) error { | ||
securityAdvisory := make(map[string]types.SecurityAdvisory) | ||
advisoryBucket := cveBucket.Bucket(platform) | ||
if advisoryBucket == nil { | ||
return nil | ||
} | ||
err := advisoryBucket.ForEach(func(advisoryID, v []byte) error { | ||
detail := types.SecurityAdvisory{} | ||
if err := json.Unmarshal(v, &detail); err != nil { | ||
return xerrors.Errorf("failed to unmarshall advisory_detail: %w", err) | ||
} | ||
securityAdvisory[string(advisoryID)] = detail | ||
return nil | ||
}) | ||
SecurityAdvisories[string(platform)] = securityAdvisory | ||
return err | ||
}) | ||
if err != nil { | ||
return xerrors.Errorf("error in db foreach: %w", err) | ||
} | ||
return nil | ||
}) | ||
return SecurityAdvisories, err | ||
} | ||
|
||
func (dbc Config) PutSecurityAdvisoryDetails(tx *bolt.Tx, cveId string, osName string, securityAdvisory map[string]types.SecurityAdvisory) error { | ||
root, err := tx.CreateBucketIfNotExists([]byte(securityAdvisoryBucket)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cveBucket, err := root.CreateBucketIfNotExists([]byte(cveId)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
osBucket, err := cveBucket.CreateBucketIfNotExists([]byte(osName)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for secAdvId, advisoryDetail := range securityAdvisory { | ||
jsonVal, err := json.Marshal(advisoryDetail) | ||
if err != nil { | ||
return xerrors.Errorf("failed to marshal JSON: %w", err) | ||
} | ||
err = osBucket.Put([]byte(secAdvId), jsonVal) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (dbc Config) DeleteSecurityAdvisoryBucket() error { | ||
return dbc.deleteBucket(securityAdvisoryBucket) | ||
} |
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
Oops, something went wrong.