dao

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NonExistUserID : if a user does not exist, the ID of the user will be 0.
	NonExistUserID = 0
	// ClairDBAlias ...
	ClairDBAlias = "clair-db"
)
View Source
const (
	// SchemaVersion is the version of database schema
	SchemaVersion = "1.6.0"
)

Variables

This section is empty.

Functions

func AddAccessLog

func AddAccessLog(accessLog models.AccessLog) error

AddAccessLog persists the access logs

func AddAdminJob added in v1.6.0

func AddAdminJob(job *models.AdminJob) (int64, error)

AddAdminJob ...

func AddLabel added in v1.5.0

func AddLabel(label *models.Label) (int64, error)

AddLabel creates a label

func AddProject

func AddProject(project models.Project) (int64, error)

AddProject adds a project to the database along with project roles information and access log records.

func AddProjectMetadata

func AddProjectMetadata(meta *models.ProjectMetadata) error

AddProjectMetadata adds metadata for a project

func AddRepJob

func AddRepJob(job models.RepJob) (int64, error)

AddRepJob ...

func AddRepPolicy

func AddRepPolicy(policy models.RepPolicy) (int64, error)

AddRepPolicy ...

func AddRepTarget

func AddRepTarget(target models.RepTarget) (int64, error)

AddRepTarget ...

func AddRepository

func AddRepository(repo models.RepoRecord) error

AddRepository adds a repo to the database.

func AddResourceLabel added in v1.5.0

func AddResourceLabel(rl *models.ResourceLabel) (int64, error)

AddResourceLabel add a label to a resource

func AddScanJob

func AddScanJob(job models.ScanJob) (int64, error)

AddScanJob ...

func ArrayEqual added in v1.6.0

func ArrayEqual(arrayA, arrayB []int) bool

ArrayEqual ...

func AuthModeCanBeModified

func AuthModeCanBeModified() (bool, error)

AuthModeCanBeModified determines whether auth mode can be modified or not. Auth mode can modified when there is only admin user in database.

func ChangeUserPassword

func ChangeUserPassword(u models.User) error

ChangeUserPassword ...

func ChangeUserProfile

func ChangeUserProfile(user models.User, cols ...string) error

ChangeUserProfile - Update user in local db, cols to specify the columns need to update, Email, and RealName, Comment are updated by default.

func CleanUser

func CleanUser(id int64) error

CleanUser - Clean this user information from DB

func ClearTable

func ClearTable(table string) error

ClearTable is the shortcut for test cases, it should be called only in test cases.

func CountPull

func CountPull(repoName string) (int64, error)

CountPull ...

func CreatePagination added in v1.6.0

func CreatePagination(query *models.ProjectQueryParam, sql string, params []interface{}) (string, []interface{})

CreatePagination ...

func DeleteAdminJob added in v1.6.0

func DeleteAdminJob(id int64) error

DeleteAdminJob ...

func DeleteLabel added in v1.5.0

func DeleteLabel(id int64) error

DeleteLabel ...

func DeleteLabelsOfResource added in v1.5.0

func DeleteLabelsOfResource(rType string, rIDOrName interface{}) error

DeleteLabelsOfResource removes all labels of the resource

func DeleteProject

func DeleteProject(id int64) error

DeleteProject ...

func DeleteProjectMetadata

func DeleteProjectMetadata(projectID int64, name ...string) error

DeleteProjectMetadata deleted metadata of a project. If name is absent all metadatas will be deleted, otherwise only the metadatas specified by name will be deleted

func DeleteRepJob

func DeleteRepJob(id int64) error

DeleteRepJob ...

func DeleteRepPolicy

func DeleteRepPolicy(id int64) error

DeleteRepPolicy ...

func DeleteRepTarget

func DeleteRepTarget(id int64) error

DeleteRepTarget ...

func DeleteRepository

func DeleteRepository(name string) error

DeleteRepository ...

func DeleteResourceLabel added in v1.5.0

func DeleteResourceLabel(id int64) error

DeleteResourceLabel ...

func DeleteResourceLabelByLabel added in v1.5.0

func DeleteResourceLabelByLabel(id int64) error

DeleteResourceLabelByLabel delete the mapping relationship by label ID

func DeleteUser

func DeleteUser(userID int) error

DeleteUser ...

func Escape added in v1.5.0

func Escape(str string) string

Escape ..

func FilterRepPolicies

func FilterRepPolicies(name string, projectID, page, pageSize int64) ([]*models.RepPolicy, error)

FilterRepPolicies filters policies by name and project ID

func FilterRepTargets

func FilterRepTargets(name string) ([]*models.RepTarget, error)

FilterRepTargets filters targets by name

func GetAccessLogs

func GetAccessLogs(query *models.LogQueryParam) ([]models.AccessLog, error)

GetAccessLogs gets access logs according to different conditions

func GetAdminJob added in v1.6.0

func GetAdminJob(id int64) (*models.AdminJob, error)

GetAdminJob ...

func GetAdminJobs added in v1.6.0

func GetAdminJobs(query *models.AdminJobQuery) ([]*models.AdminJob, error)

GetAdminJobs get admin jobs bases on query conditions

func GetConfigEntries

func GetConfigEntries() ([]*models.ConfigEntry, error)

GetConfigEntries Get configuration from database

func GetGroupProjects added in v1.6.0

func GetGroupProjects(groupDNCondition string, query *models.ProjectQueryParam) ([]*models.Project, error)

GetGroupProjects - Get user's all projects, including user is the user member of this project and the user is in the group which is a group member of this project.

func GetImgScanOverview

func GetImgScanOverview(digest string) (*models.ImgScanOverview, error)

GetImgScanOverview returns the ImgScanOverview based on the digest.

func GetLabel added in v1.5.0

func GetLabel(id int64) (*models.Label, error)

GetLabel specified by ID

func GetLabelsOfResource added in v1.5.0

func GetLabelsOfResource(rType string, rIDOrName interface{}) ([]*models.Label, error)

GetLabelsOfResource returns the label list of the resource Get the labels by ResourceID if rIDOrName is int, or get the labels by ResourceName

func GetOrmer

func GetOrmer() orm.Ormer

GetOrmer :set ormer singleton

func GetProjectByID

func GetProjectByID(id int64) (*models.Project, error)

GetProjectByID ...

func GetProjectByName

func GetProjectByName(name string) (*models.Project, error)

GetProjectByName ...

func GetProjectMetadata

func GetProjectMetadata(projectID int64, name ...string) ([]*models.ProjectMetadata, error)

GetProjectMetadata returns the metadata of a project. If name is absent all metadatas will be returned, otherwise only the metadatas specified by name will be returned

func GetProjects

func GetProjects(query *models.ProjectQueryParam) ([]*models.Project, error)

GetProjects returns a project list according to the query conditions

func GetRepJob

func GetRepJob(id int64) (*models.RepJob, error)

GetRepJob ...

func GetRepJobs added in v1.5.0

func GetRepJobs(query ...*models.RepJobQuery) ([]*models.RepJob, error)

GetRepJobs ...

func GetRepPolicy

func GetRepPolicy(id int64) (*models.RepPolicy, error)

GetRepPolicy ...

func GetRepPolicyByName

func GetRepPolicyByName(name string) (*models.RepPolicy, error)

GetRepPolicyByName ...

func GetRepPolicyByProject

func GetRepPolicyByProject(projectID int64) ([]*models.RepPolicy, error)

GetRepPolicyByProject ...

func GetRepPolicyByProjectAndTarget

func GetRepPolicyByProjectAndTarget(projectID, targetID int64) ([]*models.RepPolicy, error)

GetRepPolicyByProjectAndTarget ...

func GetRepPolicyByTarget

func GetRepPolicyByTarget(targetID int64) ([]*models.RepPolicy, error)

GetRepPolicyByTarget ...

func GetRepTarget

func GetRepTarget(id int64) (*models.RepTarget, error)

GetRepTarget ...

func GetRepTargetByEndpoint

func GetRepTargetByEndpoint(endpoint string) (*models.RepTarget, error)

GetRepTargetByEndpoint ...

func GetRepTargetByName

func GetRepTargetByName(name string) (*models.RepTarget, error)

GetRepTargetByName ...

func GetRepositories added in v1.5.0

func GetRepositories(query ...*models.RepositoryQuery) ([]*models.RepoRecord, error)

GetRepositories ...

func GetRepositoryByName

func GetRepositoryByName(name string) (*models.RepoRecord, error)

GetRepositoryByName ...

func GetResourceLabel added in v1.5.0

func GetResourceLabel(rType string, rIDOrName interface{}, labelID int64) (*models.ResourceLabel, error)

GetResourceLabel specified by resource ID or name Get the ResourceLabel by ResourceID if rIDOrName is int Get the ResourceLabel by ResourceName if rIDOrName is string

func GetRoleByID

func GetRoleByID(id int) (*models.Role, error)

GetRoleByID ...

func GetRolesByLDAPGroup added in v1.6.0

func GetRolesByLDAPGroup(projectID int64, groupDNCondition string) ([]int, error)

GetRolesByLDAPGroup - Get Project roles of the specified group DN is a member of current project

func GetScanJob

func GetScanJob(id int64) (*models.ScanJob, error)

GetScanJob ...

func GetScanJobsByDigest

func GetScanJobsByDigest(digest string, limit ...int) ([]*models.ScanJob, error)

GetScanJobsByDigest returns a list of scan jobs with given digest

func GetScanJobsByImage

func GetScanJobsByImage(repository, tag string, limit ...int) ([]*models.ScanJob, error)

GetScanJobsByImage returns a list of scan jobs with given repository and tag

func GetScanJobsByStatus

func GetScanJobsByStatus(status ...string) ([]*models.ScanJob, error)

GetScanJobsByStatus return a list of scan jobs with any of the given statuses in param

func GetSchemaVersion

func GetSchemaVersion() (*models.SchemaVersion, error)

GetSchemaVersion return the version of database schema

func GetTop10AdminJobs added in v1.6.0

func GetTop10AdminJobs() ([]*models.AdminJob, error)

GetTop10AdminJobs ...

func GetTopRepos

func GetTopRepos(projectIDs []int64, n int) ([]*models.RepoRecord, error)

GetTopRepos returns the most popular repositories whose project ID is in projectIDs

func GetTotalCountOfRepJobs added in v1.5.0

func GetTotalCountOfRepJobs(query ...*models.RepJobQuery) (int64, error)

GetTotalCountOfRepJobs ...

func GetTotalGroupProjects added in v1.6.0

func GetTotalGroupProjects(groupDNCondition string, query *models.ProjectQueryParam) (int, error)

GetTotalGroupProjects - Get the total count of projects, including user is the member of this project and the user is in the group, which is the group member of this project.

func GetTotalOfAccessLogs

func GetTotalOfAccessLogs(query *models.LogQueryParam) (int64, error)

GetTotalOfAccessLogs ...

func GetTotalOfLabels added in v1.5.0

func GetTotalOfLabels(query *models.LabelQuery) (int64, error)

GetTotalOfLabels returns the total count of labels

func GetTotalOfProjects

func GetTotalOfProjects(query *models.ProjectQueryParam) (int64, error)

GetTotalOfProjects returns the total count of projects according to the query conditions

func GetTotalOfRepPolicies

func GetTotalOfRepPolicies(name string, projectID int64) (int64, error)

GetTotalOfRepPolicies returns the total count of replication policies

func GetTotalOfRepositories

func GetTotalOfRepositories(query ...*models.RepositoryQuery) (int64, error)

GetTotalOfRepositories ...

func GetTotalOfUsers

func GetTotalOfUsers(query *models.UserQuery) (int64, error)

GetTotalOfUsers ...

func GetUser

func GetUser(query models.User) (*models.User, error)

GetUser ...

func GetUserProjectRoles

func GetUserProjectRoles(userID int, projectID int64, entityType string) ([]models.Role, error)

GetUserProjectRoles returns roles that the user has according to the project.

func IncreasePullCount

func IncreasePullCount(name string) (err error)

IncreasePullCount ...

func InitClairDB

func InitClairDB(clairDB *models.PostGreSQL) error

InitClairDB ...

func InitDatabase

func InitDatabase(database *models.Database) error

InitDatabase registers the database

func IsAdminRole

func IsAdminRole(userIDOrUsername interface{}) (bool, error)

IsAdminRole returns whether the user is admin.

func IsSuperUser

func IsSuperUser(username string) bool

IsSuperUser checks if the user is super user(conventionally id == 1) of Harbor

func ListClairVulnTimestamps

func ListClairVulnTimestamps() ([]*models.ClairVulnTimestamp, error)

ListClairVulnTimestamps return a list of all records in vuln timestamp table.

func ListImgScanOverviews

func ListImgScanOverviews() ([]*models.ImgScanOverview, error)

ListImgScanOverviews list all records in table img_scan_overview, it is called in notification handler when it needs to refresh the severity of all images.

func ListLabels added in v1.5.0

func ListLabels(query *models.LabelQuery) ([]*models.Label, error)

ListLabels list labels according to the query conditions

func ListProjectMetadata

func ListProjectMetadata(name, value string) ([]*models.ProjectMetadata, error)

ListProjectMetadata ...

func ListResourceLabels added in v1.5.0

func ListResourceLabels(query ...*models.ResourceLabelQuery) ([]*models.ResourceLabel, error)

ListResourceLabels lists ResourceLabel according to the query conditions

func ListUsers

func ListUsers(query *models.UserQuery) ([]models.User, error)

ListUsers lists all users according to different conditions.

func LoginByDb

func LoginByDb(auth models.AuthModel) (*models.User, error)

LoginByDb is used for user to login with database auth mode.

func OnBoardUser

func OnBoardUser(u *models.User) error

OnBoardUser will check if a user exists in user table, if not insert the user and put the id in the pointer of user model, if it does exist, return the user's profile. This is used for ldap and uaa authentication, such the user can have an ID in Harbor.

func PrepareTestData added in v1.5.0

func PrepareTestData(clearSqls []string, initSqls []string)

PrepareTestData -- Clean and Create data

func PrepareTestForMySQL

func PrepareTestForMySQL()

PrepareTestForMySQL is for test only.

func PrepareTestForPostgresSQL added in v1.6.0

func PrepareTestForPostgresSQL()

PrepareTestForPostgresSQL is for test only.

func PrepareTestForSQLite

func PrepareTestForSQLite()

PrepareTestForSQLite is for test only.

func Register

func Register(user models.User) (int64, error)

Register is used for user to register, the password is encrypted before the record is inserted into database.

func RepositoryExists

func RepositoryExists(name string) bool

RepositoryExists returns whether the repository exists according to its name.

func ResetUserPassword

func ResetUserPassword(u models.User) error

ResetUserPassword ...

func SaveConfigEntries

func SaveConfigEntries(entries []models.ConfigEntry) error

SaveConfigEntries Save configuration to database.

func SetAdminJobUUID added in v1.6.0

func SetAdminJobUUID(id int64, uuid string) error

SetAdminJobUUID ...

func SetClairVulnTimestamp

func SetClairVulnTimestamp(namespace string, timestamp time.Time) error

SetClairVulnTimestamp update the last_update of a namespace. If there's no record for this namespace, one will be created.

func SetRepJobUUID added in v1.5.0

func SetRepJobUUID(id int64, uuid string) error

SetRepJobUUID ...

func SetScanJobForImg

func SetScanJobForImg(digest string, jobID int64) error

SetScanJobForImg updates the scan_job_id based on the digest of image, if there's no data, it created one record.

func SetScanJobUUID added in v1.5.0

func SetScanJobUUID(id int64, uuid string) error

SetScanJobUUID set UUID to the record so it associates with the job in job service.

func ToggleUserAdminRole

func ToggleUserAdminRole(userID int, hasAdmin bool) error

ToggleUserAdminRole gives a user admin role.

func UpdateAdminJobStatus added in v1.6.0

func UpdateAdminJobStatus(id int64, status string) error

UpdateAdminJobStatus ...

func UpdateImgScanOverview

func UpdateImgScanOverview(digest, detailsKey string, sev models.Severity, compOverview *models.ComponentsOverview) error

UpdateImgScanOverview updates the serverity and components status of a record in img_scan_overview

func UpdateLabel added in v1.5.0

func UpdateLabel(label *models.Label) error

UpdateLabel ...

func UpdateProjectMetadata

func UpdateProjectMetadata(meta *models.ProjectMetadata) error

UpdateProjectMetadata updates metadata of a project

func UpdateRepJobStatus

func UpdateRepJobStatus(id int64, status string) error

UpdateRepJobStatus ...

func UpdateRepPolicy

func UpdateRepPolicy(policy *models.RepPolicy) error

UpdateRepPolicy ...

func UpdateRepTarget

func UpdateRepTarget(target models.RepTarget) error

UpdateRepTarget ...

func UpdateRepository

func UpdateRepository(repo models.RepoRecord) error

UpdateRepository ...

func UpdateScanJobStatus

func UpdateScanJobStatus(id int64, status string) error

UpdateScanJobStatus updates the status of a scan job.

func UpdateUserResetUUID

func UpdateUserResetUUID(u models.User) error

UpdateUserResetUUID ...

func UpgradeSchema added in v1.6.0

func UpgradeSchema(database *models.Database) error

UpgradeSchema will call the internal migrator to upgrade schema based on the setting of database.

func UserExists

func UserExists(user models.User, target string) (bool, error)

UserExists returns whether a user exists according username or Email.

Types

type Database

type Database interface {
	// Name returns the name of database
	Name() string
	// String returns the details of database
	String() string
	// Register registers the database which will be used
	Register(alias ...string) error
	// UpgradeSchema upgrades the DB schema to the latest version
	UpgradeSchema() error
}

Database is an interface of different databases

func NewMySQL

func NewMySQL(host, port, usr, pwd, database string) Database

NewMySQL returns an instance of mysql

func NewPGSQL added in v1.6.0

func NewPGSQL(host string, port string, usr string, pwd string, database string, sslmode bool) Database

NewPGSQL returns an instance of postgres

func NewSQLite

func NewSQLite(file string) Database

NewSQLite returns an instance of sqlite

type DatabaseWatchItemDAO

type DatabaseWatchItemDAO struct{}

DatabaseWatchItemDAO implements interface WatchItemDAO for database

func (*DatabaseWatchItemDAO) Add

func (d *DatabaseWatchItemDAO) Add(item *models.WatchItem) (int64, error)

Add a WatchItem

func (*DatabaseWatchItemDAO) DeleteByPolicyID

func (d *DatabaseWatchItemDAO) DeleteByPolicyID(policyID int64) error

DeleteByPolicyID deletes the WatchItem specified by policy ID

func (*DatabaseWatchItemDAO) Get

func (d *DatabaseWatchItemDAO) Get(namespace, operation string) ([]models.WatchItem, error)

Get returns WatchItem list according to the namespace and operation

type WatchItemDAO

type WatchItemDAO interface {
	Add(*models.WatchItem) (int64, error)
	DeleteByPolicyID(int64) error
	Get(namespace, operation string) ([]models.WatchItem, error)
}

WatchItemDAO defines operations about WatchItem

var DefaultDatabaseWatchItemDAO WatchItemDAO = &DatabaseWatchItemDAO{}

DefaultDatabaseWatchItemDAO is an instance of DatabaseWatchItemDAO

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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