db

package
v1.0.1-0...-373c8f8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CVE status available values
	CVEStatusUnprocessed = "unprocessed" // 未处理
	CVEStatusProcessing  = "processing"  // 处理中
	CVEStatusPostpone    = "postpone"    // 延后
	CVEStatusHold        = "hold"        // 搁置
	CVEStatusCanceled    = "canceled"    // 取消
	CVEStatusFixed       = "fixed"       // 完成
)
View Source
const (
	// Filter tracker filter
	FilterUrgencyHigh           FilterUrgency = "high_urgency"
	FilterUrgencyMedium                       = "medium_urgency"
	FilterUrgencyLow                          = "low_urgency"
	FilterUrgencyUnimportant                  = "unimportant_urgency"
	FilterUrgencyNotYetAssigned               = "unassigned_urgency"
	FilterUrgencyEndOfLife                    = "endoflife_urgency"
)
View Source
const (
	// Filter scope list
	FilterScopeHideRemote   FilterScope = "remote"
	FilterScopeHideLocal                = "locale"
	FilterScopeHideUnclear              = "unclear"
	FilterScopeUndetermined             = "undetermined_issues"
	FilterScopeNoDSA                    = "nodsa"
	FilterScopeIgnore                   = "noignored"
	FilterScopePostponed                = "nopostponed"
)
View Source
const (
	// DefaultExpires 10 hours
	DefaultExpires = 10 * 60 * 60
)

Variables

View Source
var (
	// CommonDB session, version, log db handler
	CommonDB *gorm.DB
)

Functions

func DeleteDBHandler

func DeleteDBHandler(version string) error

DeleteDBHandler delete db handler

func GenToken

func GenToken() []byte

GenToken generate token

func GetDBHandler

func GetDBHandler(version string) *gorm.DB

GetDBHandler return db handler by version

func Init

func Init(dbDir string)

Init init db

func IsSourceExists

func IsSourceExists(source, dbVersion string) bool

IsSourceExists query whether source exists

func SessionClean

func SessionClean() error

SessionClean clean expired session

func SetDBHander

func SetDBHander(version string) error

SetDBHandler init db handler

func ValidAction

func ValidAction(action int) bool

ValidAction validity action

func ValidColumn

func ValidColumn(name string) bool

ValidColumn validity cve table whether has this column name

func ValidStatus

func ValidStatus(status string) bool

ValidStatus validity status whether right

Types

type ActionType

type ActionType int

ActionType action types

const (
	LogActionInitPackage ActionType = iota + 1
	LogActionFecthDebian
	LogActionPatchCVE
	LogActionLogin
	LogActionLogout
	LogActionNewVersion
	LogActionPatchVersion
	LogActionDeleteVersion
	LogActionFetchScore
)

func (ActionType) String

func (action ActionType) String() string

String action description

type CVE

type CVE struct {
	DebianCVE
	Status      string `json:"status"`
	Patch       string `json:"patch"`
	Description string `json:"description"`
	CVSS        string `json:"cvss"`

	PreInstalled bool `json:"pre_installed"`
	Archived     bool `json:"archived"`

	Score float64 `json:"score"` // jump to nvd

	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
	DeletedAt *time.Time `json:"-"`
}

CVE store cve bug for tracking

func NewCVE

func NewCVE(id, version string) (*CVE, error)

NewCVE query cve by id

func (*CVE) Save

func (cve *CVE) Save(version string) error

Save save cve info

func (*CVE) Update

func (cve *CVE) Update(diff map[string]interface{}, version string) error

UpdateCVE update cve info with values

type CVEList

type CVEList []*CVE

CVEList an array for CVE

func (CVEList) Create

func (list CVEList) Create(version string) error

Create insert cve record, if exists, ignore

type CVEScore

type CVEScore struct {
	ID            string  `gorm:"primary_key;index" json:"id"`
	ScoreSeverity string  `json:"score_severity"`
	CVSS          string  `json:"cvss"`
	Score         float64 `json:"score"`
}

CVEScore CVSS 3.0 score from NVD

func (*CVEScore) Get

func (score *CVEScore) Get(version string) error

Get get cve score by id

type CVEScoreList

type CVEScoreList []*CVEScore

CVEScoreList cve score list

func (CVEScoreList) Create

func (list CVEScoreList) Create(version string) error

Create insert cve score list

func (CVEScoreList) UpdateCVE

func (list CVEScoreList) UpdateCVE(version string) error

type DebianCVE

type DebianCVE struct {
	ID      string `gorm:"primary_key" json:"id"` // jump to cve
	Package string `json:"package"`
	Urgency string `json:"urgency"`
	Remote  string `json:"remote"`
}

DebianCVE store cve bug from debian tracker

func (*DebianCVE) FixUrgency

func (info *DebianCVE) FixUrgency()

FixUrgency correct urgency

type DebianCVEList

type DebianCVEList []*DebianCVE

DebianCVEList an array for CVE

func (DebianCVEList) Dump

func (list DebianCVEList) Dump()

func (DebianCVEList) FixPackage

func (list DebianCVEList) FixPackage()

FixPackage fill package

type FilterScope

type FilterScope string

Filter scope

func (FilterScope) String

func (filter FilterScope) String() string

type FilterUrgency

type FilterUrgency string

Filter urgency level

func (FilterUrgency) String

func (filter FilterUrgency) String() string

type Log

type Log struct {
	ID          int        `gorm:"auto_increment;primary_key" json:"id"`
	Operator    string     `json:"operator"`
	Action      ActionType `json:"action"`
	ActionDesc  string     `gorm:"-" json:"action_desc"`
	Target      string     `json:"target"`
	Description string     `json:"description"`
	Content     string     `json:"content"`
}

Log operation records

func (*Log) Create

func (l *Log) Create() error

Create insert log

type LogList

type LogList []*Log

LogList log list

func QueryLogList

func QueryLogList(params map[string]interface{}, offset, limit int) (int64, LogList, error)

QueryLogList query log list, available params: operator, target

func (LogList) Len

func (list LogList) Len() int

func (LogList) Less

func (list LogList) Less(i, j int) bool

func (LogList) Swap

func (list LogList) Swap(i, j int)

type Package

type Package struct {
	Package       string `gorm:"primary_key" json:"package"` // package + ':' + architecture, unique key
	Source        string `json:"source"`
	Version       string `json:"version"`
	Architecture  string `json"architecture`
	SourceVersion string `json:"source_version"` // if empty, equal with version
}

Package store installed packages in ISO Image

func NewPackage

func NewPackage(pkg, arch, dbVersion string) (*Package, error)

NrePackage query package from db

type PackageList

type PackageList []*Package

PackageList package list

func (PackageList) Create

func (infos PackageList) Create(dbVersion string) error

Create insert package list

type Session

type Session struct {
	Token    string `gorm:"primary_key" json:"token"`
	Username string `json:"username"`
	Expires  int64  `json:"expires"`

	CreatedAt time.Time `json:"created_at"`
}

Session user login cookie

func (*Session) Create

func (s *Session) Create() error

Create save session

func (*Session) Delete

func (s *Session) Delete() error

Delete delete token

func (*Session) Expired

func (s *Session) Expired() bool

Expired token whether expired

func (*Session) Get

func (s *Session) Get() error

Get get session by token

type Version

type Version struct {
	Version       string `gorm:"primary_key;index" json:"version"`
	DebianVersion string `json:"debian_version"`
	TrackerURL    string `json:"tracker_url"`
	ReleaseURL    string `json:"release_url"`

	DebianSeq int `json:"debian_seq"`
}

Version deepin and debian version

func (*Version) Create

func (v *Version) Create() error

Create insert version

func (*Version) Delete

func (v *Version) Delete() error

Delete delete version

func (*Version) Equal

func (v *Version) Equal(target *Version) bool

Equal compare

func (*Version) Get

func (v *Version) Get() error

Get query by version

func (*Version) Update

func (v *Version) Update() error

Update update

type VersionList

type VersionList []*Version

VersionList version list

func QueryVersionList

func QueryVersionList() (VersionList, error)

QueryVersionList return version list

func (VersionList) Len

func (list VersionList) Len() int

func (VersionList) Less

func (list VersionList) Less(i, j int) bool

func (VersionList) Swap

func (list VersionList) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL