2015-11-13 19:11:28 +00:00
|
|
|
package database
|
|
|
|
|
2016-01-08 19:42:07 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"time"
|
|
|
|
)
|
2015-11-13 19:11:28 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrTransaction is an error that occurs when a database transaction fails.
|
2016-01-08 16:17:32 +00:00
|
|
|
// ErrTransaction = errors.New("database: transaction failed (concurrent modification?)")
|
|
|
|
|
2015-11-13 19:11:28 +00:00
|
|
|
// ErrBackendException is an error that occurs when the database backend does
|
|
|
|
// not work properly (ie. unreachable).
|
2016-01-08 16:17:32 +00:00
|
|
|
ErrBackendException = errors.New("database: an error occured when querying the backend")
|
|
|
|
|
2015-11-13 19:11:28 +00:00
|
|
|
// ErrInconsistent is an error that occurs when a database consistency check
|
|
|
|
// fails (ie. when an entity which is supposed to be unique is detected twice)
|
|
|
|
ErrInconsistent = errors.New("database: inconsistent database")
|
2016-01-08 16:17:32 +00:00
|
|
|
|
2015-11-13 19:11:28 +00:00
|
|
|
// ErrCantOpen is an error that occurs when the database could not be opened
|
|
|
|
ErrCantOpen = errors.New("database: could not open database")
|
|
|
|
)
|
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
type Datastore interface {
|
|
|
|
// Layer
|
|
|
|
InsertLayer(Layer) error
|
|
|
|
FindLayer(name string, withFeatures, withVulnerabilities bool) (layer Layer, err error)
|
|
|
|
DeleteLayer(name string) error
|
2015-11-13 19:11:28 +00:00
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
// Vulnerability
|
2016-01-12 15:40:46 +00:00
|
|
|
InsertVulnerabilities([]Vulnerability) error
|
|
|
|
// DeleteVulnerability(id string) error
|
|
|
|
FindVulnerability(namespaceName, name string) (Vulnerability, error)
|
2015-11-13 19:11:28 +00:00
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
// Notifications
|
2016-01-08 16:17:32 +00:00
|
|
|
// InsertNotifications([]Notification) error
|
|
|
|
// FindNotificationToSend() (Notification, error)
|
2015-12-28 20:03:29 +00:00
|
|
|
// CountNotificationsToSend() (int, error)
|
|
|
|
// MarkNotificationAsSent(id string)
|
2015-11-16 21:22:16 +00:00
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
// Key/Value
|
|
|
|
InsertKeyValue(key, value string) error
|
|
|
|
GetKeyValue(key string) (string, error)
|
2015-11-13 19:11:28 +00:00
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
// Lock
|
2016-01-08 19:42:07 +00:00
|
|
|
Lock(name string, owner string, duration time.Duration, renew bool) (bool, time.Time)
|
|
|
|
Unlock(name, owner string)
|
|
|
|
FindLock(name string) (string, time.Time, error)
|
2015-11-13 19:11:28 +00:00
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
Close()
|
2015-11-13 19:11:28 +00:00
|
|
|
}
|