Documentation ¶
Index ¶
- Constants
- Variables
- func AddAccessLog(accessLog models.AccessLog) error
- func AddAdminJob(job *models.AdminJob) (int64, error)
- func AddLabel(label *models.Label) (int64, error)
- func AddProject(project models.Project) (int64, error)
- func AddProjectMetadata(meta *models.ProjectMetadata) error
- func AddRepository(repo models.RepoRecord) error
- func AddResourceLabel(rl *models.ResourceLabel) (int64, error)
- func AddRobot(robot *models.Robot) (int64, error)
- func AddScanJob(job models.ScanJob) (int64, error)
- func ArrayEqual(arrayA, arrayB []int) bool
- func AuthModeCanBeModified() (bool, error)
- func ChangeUserPassword(u models.User) error
- func ChangeUserProfile(user models.User, cols ...string) error
- func CheckSchemaVersion() error
- func CleanUser(id int64) error
- func ClearHTTPAuthProxyUsers() error
- func ClearTable(table string) error
- func CountPull(repoName string) (int64, error)
- func CountRobot(query *models.RobotQuery) (int64, error)
- func CreateOrUpdateJobLog(log *models.JobLog) (int64, error)
- func CreatePagination(query *models.ProjectQueryParam, sql string, params []interface{}) (string, []interface{})
- func DeleteAdminJob(id int64) error
- func DeleteJobLogsBefore(t time.Time) (int64, error)
- func DeleteLabel(id int64) error
- func DeleteLabelsOfResource(rType string, rIDOrName interface{}) error
- func DeleteOIDCUser(id int64) error
- func DeleteProject(id int64) error
- func DeleteProjectMetadata(projectID int64, name ...string) error
- func DeleteRepository(name string) error
- func DeleteResourceLabel(id int64) error
- func DeleteResourceLabelByLabel(id int64) error
- func DeleteRobot(id int64) error
- func DeleteUser(userID int) error
- func Escape(str string) string
- func ExecuteBatchSQL(sqls []string)
- func GetAccessLogs(query *models.LogQueryParam) ([]models.AccessLog, error)
- func GetAdminJob(id int64) (*models.AdminJob, error)
- func GetAdminJobs(query *models.AdminJobQuery) ([]*models.AdminJob, error)
- func GetConfigEntries() ([]*models.ConfigEntry, error)
- func GetGroupProjects(groupIDs []int, query *models.ProjectQueryParam) ([]*models.Project, error)
- func GetImgScanOverview(digest string) (*models.ImgScanOverview, error)
- func GetJobLog(uuid string) (*models.JobLog, error)
- func GetLabel(id int64) (*models.Label, error)
- func GetLabelsOfResource(rType string, rIDOrName interface{}) ([]*models.Label, error)
- func GetOIDCUserByID(id int64) (*models.OIDCUser, error)
- func GetOIDCUserByUserID(userID int) (*models.OIDCUser, error)
- func GetOrmer() orm.Ormer
- func GetProjectByID(id int64) (*models.Project, error)
- func GetProjectByName(name string) (*models.Project, error)
- func GetProjectMetadata(projectID int64, name ...string) ([]*models.ProjectMetadata, error)
- func GetProjects(query *models.ProjectQueryParam) ([]*models.Project, error)
- func GetRepositories(query ...*models.RepositoryQuery) ([]*models.RepoRecord, error)
- func GetRepositoryByName(name string) (*models.RepoRecord, error)
- func GetResourceLabel(rType string, rIDOrName interface{}, labelID int64) (*models.ResourceLabel, error)
- func GetRobotByID(id int64) (*models.Robot, error)
- func GetRoleByID(id int) (*models.Role, error)
- func GetRolesByGroupID(projectID int64, groupIDs []int) ([]int, error)
- func GetScanJob(id int64) (*models.ScanJob, error)
- func GetScanJobsByDigest(digest string, limit ...int) ([]*models.ScanJob, error)
- func GetScanJobsByImage(repository, tag string, limit ...int) ([]*models.ScanJob, error)
- func GetScanJobsByStatus(status ...string) ([]*models.ScanJob, error)
- func GetSchemaVersion() (*models.SchemaVersion, error)
- func GetTop10AdminJobsOfName(name string) ([]*models.AdminJob, error)
- func GetTopRepos(projectIDs []int64, n int) ([]*models.RepoRecord, error)
- func GetTotalGroupProjects(groupIDs []int, query *models.ProjectQueryParam) (int, error)
- func GetTotalOfAccessLogs(query *models.LogQueryParam) (int64, error)
- func GetTotalOfLabels(query *models.LabelQuery) (int64, error)
- func GetTotalOfProjects(query *models.ProjectQueryParam) (int64, error)
- func GetTotalOfRepositories(query ...*models.RepositoryQuery) (int64, error)
- func GetTotalOfUsers(query *models.UserQuery) (int64, error)
- func GetUser(query models.User) (*models.User, error)
- func GetUserBySubIss(sub, issuer string) (*models.User, error)
- func GetUserProjectRoles(userID int, projectID int64, entityType string) ([]models.Role, error)
- func IncreasePullCount(name string) (err error)
- func InitAndUpgradeDatabase(database *models.Database) error
- func InitClairDB(clairDB *models.PostGreSQL) error
- func InitDatabase(database *models.Database) error
- func IsAdminRole(userIDOrUsername interface{}) (bool, error)
- func IsSuperUser(username string) bool
- func JoinNumberConditions(ids []int) string
- func ListClairVulnTimestamps() ([]*models.ClairVulnTimestamp, error)
- func ListImgScanOverviews() ([]*models.ImgScanOverview, error)
- func ListLabels(query *models.LabelQuery) ([]*models.Label, error)
- func ListProjectMetadata(name, value string) ([]*models.ProjectMetadata, error)
- func ListResourceLabels(query ...*models.ResourceLabelQuery) ([]*models.ResourceLabel, error)
- func ListRobots(query *models.RobotQuery) ([]*models.Robot, error)
- func ListUsers(query *models.UserQuery) ([]models.User, error)
- func LoginByDb(auth models.AuthModel) (*models.User, error)
- func OnBoardOIDCUser(u *models.User) error
- func OnBoardUser(u *models.User) error
- func PrepareTestData(clearSqls []string, initSqls []string)
- func PrepareTestForMySQL()
- func PrepareTestForPostgresSQL()
- func PrepareTestForSQLite()
- func ProjectExistsByName(name string) bool
- func Register(user models.User) (int64, error)
- func RepositoryExists(name string) bool
- func ResetUserPassword(u models.User) error
- func SaveConfigEntries(entries []models.ConfigEntry) error
- func SetAdminJobUUID(id int64, uuid string) error
- func SetClairVulnTimestamp(namespace string, timestamp time.Time) error
- func SetScanJobForImg(digest string, jobID int64) error
- func SetScanJobUUID(id int64, uuid string) error
- func ToggleUserAdminRole(userID int, hasAdmin bool) error
- func UpdateAdminJobStatus(id int64, status string) error
- func UpdateImgScanOverview(digest, detailsKey string, sev models.Severity, ...) error
- func UpdateLabel(label *models.Label) error
- func UpdateOIDCUser(oidcUser *models.OIDCUser) error
- func UpdateOIDCUserSecret(oidcUser *models.OIDCUser) error
- func UpdateProjectMetadata(meta *models.ProjectMetadata) error
- func UpdateRepository(repo models.RepoRecord) error
- func UpdateRobot(robot *models.Robot) error
- func UpdateScanJobStatus(id int64, status string) error
- func UpdateUserResetUUID(u models.User) error
- func UpgradeSchema(database *models.Database) error
- func UserExists(user models.User, target string) (bool, error)
- type Database
Constants ¶
const ( // NonExistUserID : if a user does not exist, the ID of the user will be 0. NonExistUserID = 0 // ClairDBAlias ... ClairDBAlias = "clair-db" )
const (
// SchemaVersion is the version of database schema
SchemaVersion = "1.6.0"
)
Variables ¶
var ( // ErrDupUser ... ErrDupUser = errors.New("sql: duplicate user in harbor_user") // ErrRollBackUser ... ErrRollBackUser = errors.New("sql: transaction roll back error in harbor_user") // ErrDupOIDCUser ... ErrDupOIDCUser = errors.New("sql: duplicate user in oicd_user") // ErrRollBackOIDCUser ... ErrRollBackOIDCUser = errors.New("sql: transaction roll back error in oicd_user") )
var ErrDupRows = errors.New("sql: duplicate row in DB")
ErrDupRows is returned by DAO when inserting failed with error "duplicate key value violates unique constraint"
Functions ¶
func AddAccessLog ¶
AddAccessLog persists the access logs
func AddAdminJob ¶ added in v1.6.0
AddAdminJob ...
func AddProject ¶
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 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 AuthModeCanBeModified ¶
AuthModeCanBeModified determines whether auth mode can be modified or not. Auth mode can modified when there is only admin user in database.
func ChangeUserProfile ¶
ChangeUserProfile - Update user in local db, cols to specify the columns need to update, Email, and RealName, Comment are updated by default.
func CheckSchemaVersion ¶ added in v1.7.0
func CheckSchemaVersion() error
CheckSchemaVersion checks that whether the schema version matches with the expected one
func ClearHTTPAuthProxyUsers ¶ added in v1.8.0
func ClearHTTPAuthProxyUsers() error
ClearHTTPAuthProxyUsers remove the records from harbor_users to delete all user imported via HTTP Auth Proxy
func ClearTable ¶
ClearTable is the shortcut for test cases, it should be called only in test cases.
func CountRobot ¶ added in v1.8.0
func CountRobot(query *models.RobotQuery) (int64, error)
CountRobot ...
func CreateOrUpdateJobLog ¶ added in v1.7.0
CreateOrUpdateJobLog ...
func CreatePagination ¶ added in v1.6.0
func CreatePagination(query *models.ProjectQueryParam, sql string, params []interface{}) (string, []interface{})
CreatePagination ...
func DeleteJobLogsBefore ¶ added in v1.7.0
DeleteJobLogsBefore ...
func DeleteLabelsOfResource ¶ added in v1.5.0
DeleteLabelsOfResource removes all labels of the resource
func DeleteProjectMetadata ¶
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 DeleteResourceLabel ¶ added in v1.5.0
DeleteResourceLabel ...
func DeleteResourceLabelByLabel ¶ added in v1.5.0
DeleteResourceLabelByLabel delete the mapping relationship by label ID
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
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
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 GetLabelsOfResource ¶ added in v1.5.0
GetLabelsOfResource returns the label list of the resource Get the labels by ResourceID if rIDOrName is int, or get the labels by ResourceName
func GetOIDCUserByID ¶ added in v1.8.0
GetOIDCUserByID ...
func GetOIDCUserByUserID ¶ added in v1.8.0
GetOIDCUserByUserID ...
func GetProjectByName ¶
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 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 GetRobotByID ¶ added in v1.8.0
GetRobotByID ...
func GetRolesByGroupID ¶ added in v1.8.2
GetRolesByGroupID - Get Project roles of the specified group is a member of current project
func GetScanJobsByDigest ¶
GetScanJobsByDigest returns a list of scan jobs with given digest
func GetScanJobsByImage ¶
GetScanJobsByImage returns a list of scan jobs with given repository and tag
func GetScanJobsByStatus ¶
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 GetTop10AdminJobsOfName ¶ added in v1.7.0
GetTop10AdminJobsOfName ...
func GetTopRepos ¶
func GetTopRepos(projectIDs []int64, n int) ([]*models.RepoRecord, error)
GetTopRepos returns the most popular repositories whose project ID is in projectIDs
func GetTotalGroupProjects ¶ added in v1.6.0
func GetTotalGroupProjects(groupIDs []int, 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 GetTotalOfRepositories ¶
func GetTotalOfRepositories(query ...*models.RepositoryQuery) (int64, error)
GetTotalOfRepositories ...
func GetTotalOfUsers ¶
GetTotalOfUsers ...
func GetUserBySubIss ¶ added in v1.8.0
GetUserBySubIss ...
func GetUserProjectRoles ¶
GetUserProjectRoles returns roles that the user has according to the project.
func InitAndUpgradeDatabase ¶ added in v1.8.0
InitAndUpgradeDatabase - init database and upgrade when required
func InitDatabase ¶
InitDatabase registers the database
func IsAdminRole ¶
IsAdminRole returns whether the user is admin.
func IsSuperUser ¶
IsSuperUser checks if the user is super user(conventionally id == 1) of Harbor
func JoinNumberConditions ¶ added in v1.8.2
JoinNumberConditions - To join number condition into string,used in sql query
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 ListRobots ¶ added in v1.8.0
func ListRobots(query *models.RobotQuery) ([]*models.Robot, error)
ListRobots list robots according to the query conditions
func OnBoardOIDCUser ¶ added in v1.8.0
OnBoardOIDCUser onboard OIDC user For the api caller, should only care about the ErrDupUser. It could lead to http.StatusConflict.
func OnBoardUser ¶
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
PrepareTestData -- Clean and Create data
func PrepareTestForPostgresSQL ¶ added in v1.6.0
func PrepareTestForPostgresSQL()
PrepareTestForPostgresSQL is for test only.
func ProjectExistsByName ¶ added in v1.7.0
ProjectExistsByName returns whether the project exists according to its name.
func Register ¶
Register is used for user to register, the password is encrypted before the record is inserted into database.
func RepositoryExists ¶
RepositoryExists returns whether the repository exists according to its name.
func SaveConfigEntries ¶
func SaveConfigEntries(entries []models.ConfigEntry) error
SaveConfigEntries Save configuration to database.
func SetAdminJobUUID ¶ added in v1.6.0
SetAdminJobUUID ...
func SetClairVulnTimestamp ¶
SetClairVulnTimestamp update the last_update of a namespace. If there's no record for this namespace, one will be created.
func SetScanJobForImg ¶
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
SetScanJobUUID set UUID to the record so it associates with the job in job service.
func ToggleUserAdminRole ¶
ToggleUserAdminRole gives a user admin role.
func UpdateAdminJobStatus ¶ added in v1.6.0
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 UpdateOIDCUser ¶ added in v1.8.0
UpdateOIDCUser updates the OIDCUser based on the input parm, only the column "secret" and "token" can be updated
func UpdateOIDCUserSecret ¶ added in v1.8.0
UpdateOIDCUserSecret updates the secret of the OIDC User. The secret in the input parm should be encrypted before calling this func
func UpdateProjectMetadata ¶
func UpdateProjectMetadata(meta *models.ProjectMetadata) error
UpdateProjectMetadata updates metadata of a project
func UpdateScanJobStatus ¶
UpdateScanJobStatus updates the status of a scan job.
func UpgradeSchema ¶ added in v1.6.0
UpgradeSchema will call the internal migrator to upgrade schema based on the setting of database.
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