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.
|
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
package database
|
|
|
|
|
2016-01-22 20:59:46 +00:00
|
|
|
import (
|
2016-02-01 23:41:40 +00:00
|
|
|
"database/sql/driver"
|
|
|
|
"encoding/json"
|
2016-01-22 20:59:46 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/coreos/clair/utils/types"
|
|
|
|
)
|
2015-12-28 20:03:29 +00:00
|
|
|
|
2016-01-12 15:40:46 +00:00
|
|
|
// ID is only meant to be used by database implementations and should never be used for anything else.
|
2015-12-28 20:03:29 +00:00
|
|
|
type Model struct {
|
2016-01-26 22:57:32 +00:00
|
|
|
ID int
|
2015-12-28 20:03:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Layer struct {
|
|
|
|
Model
|
|
|
|
|
|
|
|
Name string
|
2016-01-22 20:59:46 +00:00
|
|
|
EngineVersion int
|
|
|
|
Parent *Layer
|
|
|
|
Namespace *Namespace
|
|
|
|
Features []FeatureVersion
|
2015-12-28 20:03:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Namespace struct {
|
|
|
|
Model
|
|
|
|
|
2016-12-28 01:45:11 +00:00
|
|
|
Name string
|
|
|
|
VersionFormat string
|
2015-12-28 20:03:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Feature struct {
|
|
|
|
Model
|
|
|
|
|
|
|
|
Name string
|
|
|
|
Namespace Namespace
|
|
|
|
}
|
|
|
|
|
|
|
|
type FeatureVersion struct {
|
|
|
|
Model
|
|
|
|
|
|
|
|
Feature Feature
|
2016-12-28 01:45:11 +00:00
|
|
|
Version string
|
2016-01-22 20:59:46 +00:00
|
|
|
AffectedBy []Vulnerability
|
2016-02-18 16:04:16 +00:00
|
|
|
|
|
|
|
// For output purposes. Only make sense when the feature version is in the context of an image.
|
|
|
|
AddedBy Layer
|
2015-12-28 20:03:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Vulnerability struct {
|
|
|
|
Model
|
|
|
|
|
2016-02-04 16:34:01 +00:00
|
|
|
Name string
|
|
|
|
Namespace Namespace
|
|
|
|
|
2015-12-28 20:03:29 +00:00
|
|
|
Description string
|
|
|
|
Link string
|
|
|
|
Severity types.Priority
|
2016-01-12 15:40:46 +00:00
|
|
|
|
2016-02-01 23:41:40 +00:00
|
|
|
Metadata MetadataMap
|
|
|
|
|
2016-01-22 20:59:46 +00:00
|
|
|
FixedIn []FeatureVersion
|
|
|
|
LayersIntroducingVulnerability []Layer
|
2015-12-28 20:03:29 +00:00
|
|
|
|
|
|
|
// For output purposes. Only make sense when the vulnerability
|
|
|
|
// is already about a specific Feature/FeatureVersion.
|
2016-12-28 01:45:11 +00:00
|
|
|
FixedBy string `json:",omitempty"`
|
2015-12-28 20:03:29 +00:00
|
|
|
}
|
2016-01-21 23:09:23 +00:00
|
|
|
|
2016-02-01 23:41:40 +00:00
|
|
|
type MetadataMap map[string]interface{}
|
|
|
|
|
|
|
|
func (mm *MetadataMap) Scan(value interface{}) error {
|
|
|
|
val, ok := value.([]byte)
|
|
|
|
if !ok {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return json.Unmarshal(val, mm)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (mm *MetadataMap) Value() (driver.Value, error) {
|
|
|
|
json, err := json.Marshal(*mm)
|
|
|
|
return string(json), err
|
|
|
|
}
|
|
|
|
|
2016-01-22 20:59:46 +00:00
|
|
|
type VulnerabilityNotification struct {
|
2016-01-26 22:57:32 +00:00
|
|
|
Model
|
|
|
|
|
2016-01-22 20:59:46 +00:00
|
|
|
Name string
|
2016-01-21 23:09:23 +00:00
|
|
|
|
2016-01-22 20:59:46 +00:00
|
|
|
Created time.Time
|
|
|
|
Notified time.Time
|
|
|
|
Deleted time.Time
|
2016-01-21 23:09:23 +00:00
|
|
|
|
2016-01-22 20:59:46 +00:00
|
|
|
OldVulnerability *Vulnerability
|
2016-02-04 16:34:01 +00:00
|
|
|
NewVulnerability *Vulnerability
|
2016-01-22 20:59:46 +00:00
|
|
|
}
|
2016-01-26 22:57:32 +00:00
|
|
|
|
|
|
|
type VulnerabilityNotificationPageNumber struct {
|
|
|
|
// -1 means that we reached the end already.
|
|
|
|
OldVulnerability int
|
|
|
|
NewVulnerability int
|
|
|
|
}
|
|
|
|
|
|
|
|
var VulnerabilityNotificationFirstPage = VulnerabilityNotificationPageNumber{0, 0}
|
|
|
|
var NoVulnerabilityNotificationPage = VulnerabilityNotificationPageNumber{-1, -1}
|