2018-09-19 18:57:15 +02:00
|
|
|
// Copyright Project Harbor Authors
|
2017-05-11 15:41:57 +02:00
|
|
|
//
|
|
|
|
// 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 models
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// ScanJobTable is the name of the table whose data is mapped by ScanJob struct.
|
2017-05-23 07:33:20 +02:00
|
|
|
const ScanJobTable = "img_scan_job"
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// ScanOverviewTable is the name of the table whose data is mapped by ImgScanOverview struct.
|
2017-06-13 15:46:52 +02:00
|
|
|
const ScanOverviewTable = "img_scan_overview"
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// ScanJob is the model to represent a job for image scan in DB.
|
2017-05-11 15:41:57 +02:00
|
|
|
type ScanJob struct {
|
|
|
|
ID int64 `orm:"pk;auto;column(id)" json:"id"`
|
|
|
|
Status string `orm:"column(status)" json:"status"`
|
|
|
|
Repository string `orm:"column(repository)" json:"repository"`
|
|
|
|
Tag string `orm:"column(tag)" json:"tag"`
|
|
|
|
Digest string `orm:"column(digest)" json:"digest"`
|
2018-03-26 12:07:21 +02:00
|
|
|
UUID string `orm:"column(job_uuid)" json:"-"`
|
2017-05-11 15:41:57 +02:00
|
|
|
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
|
|
|
|
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
|
|
|
|
}
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// TableName is required by by beego orm to map ScanJob to table img_scan_job
|
2017-05-11 15:41:57 +02:00
|
|
|
func (s *ScanJob) TableName() string {
|
2017-05-23 07:33:20 +02:00
|
|
|
return ScanJobTable
|
2017-05-11 15:41:57 +02:00
|
|
|
}
|
2017-06-13 15:46:52 +02:00
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// ImgScanOverview mapped to a record of image scan overview.
|
2017-06-13 15:46:52 +02:00
|
|
|
type ImgScanOverview struct {
|
2017-07-09 06:37:08 +02:00
|
|
|
ID int64 `orm:"pk;auto;column(id)" json:"-"`
|
|
|
|
Digest string `orm:"column(image_digest)" json:"image_digest"`
|
2017-06-13 15:46:52 +02:00
|
|
|
Status string `orm:"-" json:"scan_status"`
|
|
|
|
JobID int64 `orm:"column(scan_job_id)" json:"job_id"`
|
|
|
|
Sev int `orm:"column(severity)" json:"severity"`
|
|
|
|
CompOverviewStr string `orm:"column(components_overview)" json:"-"`
|
2017-06-14 15:02:59 +02:00
|
|
|
CompOverview *ComponentsOverview `orm:"-" json:"components,omitempty"`
|
2017-06-13 15:46:52 +02:00
|
|
|
DetailsKey string `orm:"column(details_key)" json:"details_key"`
|
2017-06-14 15:02:59 +02:00
|
|
|
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time,omitempty"`
|
|
|
|
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time,omitempty"`
|
2017-06-13 15:46:52 +02:00
|
|
|
}
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// TableName ...
|
2017-06-13 15:46:52 +02:00
|
|
|
func (iso *ImgScanOverview) TableName() string {
|
|
|
|
return ScanOverviewTable
|
|
|
|
}
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// ComponentsOverview has the total number and a list of components number of different serverity level.
|
2017-06-13 15:46:52 +02:00
|
|
|
type ComponentsOverview struct {
|
|
|
|
Total int `json:"total"`
|
|
|
|
Summary []*ComponentsOverviewEntry `json:"summary"`
|
|
|
|
}
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// ComponentsOverviewEntry ...
|
2017-06-13 15:46:52 +02:00
|
|
|
type ComponentsOverviewEntry struct {
|
|
|
|
Sev int `json:"severity"`
|
|
|
|
Count int `json:"count"`
|
|
|
|
}
|
2017-06-15 14:23:55 +02:00
|
|
|
|
|
|
|
// ImageScanReq represents the request body to send to job service for image scan
|
|
|
|
type ImageScanReq struct {
|
|
|
|
Repo string `json:"repository"`
|
|
|
|
Tag string `json:"tag"`
|
|
|
|
}
|
2017-06-20 05:03:13 +02:00
|
|
|
|
2017-06-27 15:20:00 +02:00
|
|
|
// ScanAllPolicy is represent the json request and object for scan all policy, the parm is het
|
|
|
|
type ScanAllPolicy struct {
|
|
|
|
Type string `json:"type"`
|
2018-11-26 06:27:57 +01:00
|
|
|
Parm map[string]interface{} `json:"parameter,omitempty"`
|
2017-06-27 15:20:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
// ScanAllNone "none" for not doing any scan all
|
|
|
|
ScanAllNone = "none"
|
|
|
|
// ScanAllDaily for doing scan all daily
|
|
|
|
ScanAllDaily = "daily"
|
|
|
|
// ScanAllOnRefresh for doing scan all when the Clair DB is refreshed.
|
|
|
|
ScanAllOnRefresh = "on_refresh"
|
|
|
|
// ScanAllDailyTime the key for parm of daily scan all policy.
|
|
|
|
ScanAllDailyTime = "daily_time"
|
|
|
|
)
|
|
|
|
|
2018-09-05 10:16:31 +02:00
|
|
|
// DefaultScanAllPolicy ...
|
2017-06-27 15:20:00 +02:00
|
|
|
var DefaultScanAllPolicy = ScanAllPolicy{
|
2018-10-24 11:16:54 +02:00
|
|
|
Type: ScanAllNone,
|
2017-06-27 15:20:00 +02:00
|
|
|
}
|