2016-01-19 20:16:45 +00:00
|
|
|
// Copyright 2015 clair authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// Package database defines the Clair's models and a common interface for database implementations.
|
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 {
|
2016-01-28 16:26:34 +00:00
|
|
|
// Namespace
|
|
|
|
ListNamespaces() ([]Namespace, error)
|
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
// Layer
|
|
|
|
InsertLayer(Layer) error
|
2016-01-21 23:09:38 +00:00
|
|
|
FindLayer(name string, withFeatures, withVulnerabilities bool) (Layer, error)
|
2015-12-28 20:03:29 +00:00
|
|
|
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
|
|
|
|
FindVulnerability(namespaceName, name string) (Vulnerability, error)
|
2016-01-28 18:35:07 +00:00
|
|
|
DeleteVulnerability(namespaceName, name string) error
|
2015-11-13 19:11:28 +00:00
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
// Notifications
|
2016-01-22 20:59:46 +00:00
|
|
|
GetAvailableNotification(renotifyInterval time.Duration) (VulnerabilityNotification, error) // Does not fill old/new Vulnerabilities.
|
2016-01-26 22:57:32 +00:00
|
|
|
GetNotification(name string, limit int, page VulnerabilityNotificationPageNumber) (VulnerabilityNotification, VulnerabilityNotificationPageNumber, error)
|
2016-01-21 23:09:23 +00:00
|
|
|
SetNotificationNotified(name string) error
|
|
|
|
DeleteNotification(name string) error
|
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
|
|
|
|
2016-01-22 20:57:57 +00:00
|
|
|
Ping() bool
|
2015-12-28 20:03:29 +00:00
|
|
|
Close()
|
2015-11-13 19:11:28 +00:00
|
|
|
}
|