Skip to content

Commit

Permalink
database: add Insert/DeleteVulnerabilityFix
Browse files Browse the repository at this point in the history
  • Loading branch information
jzelinskie committed Feb 24, 2016
1 parent 9b51f7f commit 99f3552
Show file tree
Hide file tree
Showing 4 changed files with 248 additions and 111 deletions.
3 changes: 3 additions & 0 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type Datastore interface {
FindVulnerability(namespaceName, name string) (Vulnerability, error)
DeleteVulnerability(namespaceName, name string) error

InsertVulnerabilityFixes(vulnerabilityNamespace, vulnerabilityName string, fixes []FeatureVersion) error
DeleteVulnerabilityFix(vulnerabilityNamespace, vulnerabilityName, featureName string) error

// Notifications
GetAvailableNotification(renotifyInterval time.Duration) (VulnerabilityNotification, error) // Does not fill old/new Vulnerabilities.
GetNotification(name string, limit int, page VulnerabilityNotificationPageNumber) (VulnerabilityNotification, VulnerabilityNotificationPageNumber, error)
Expand Down
5 changes: 5 additions & 0 deletions database/pgsql/pgsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func init() {
prometheus.MustRegister(promConcurrentLockVAFV)
}

type Queryer interface {
Query(query string, args ...interface{}) (*sql.Rows, error)
QueryRow(query string, args ...interface{}) *sql.Row
}

type pgSQL struct {
*sql.DB
cache *lru.ARCCache
Expand Down
8 changes: 8 additions & 0 deletions database/pgsql/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ func init() {
// vulnerability.go
queries["f_vulnerability"] = `
SELECT v.id, n.id, v.description, v.link, v.severity, v.metadata, vfif.version, f.id, f.Name
FROM Vulnerability v
JOIN Namespace n ON v.namespace_id = n.id
LEFT JOIN Vulnerability_FixedIn_Feature vfif ON v.id = vfif.vulnerability_id
LEFT JOIN Feature f ON vfif.feature_id = f.id
WHERE n.Name = $1 AND v.Name = $2`

queries["f_vulnerability_for_update"] = `
SELECT FOR UPDATE v.id, n.id, v.description, v.link, v.severity, v.metadata, vfif.version, f.id, f.Name
FROM Vulnerability v
JOIN Namespace n ON v.namespace_id = n.id
LEFT JOIN Vulnerability_FixedIn_Feature vfif ON v.id = vfif.vulnerability_id
Expand Down

0 comments on commit 99f3552

Please sign in to comment.