2018-02-19 22:24:10 +00:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00: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
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// 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-10-21 23:14:02 +00:00
|
|
|
package store
|
|
|
|
|
2022-08-31 23:19:49 +00:00
|
|
|
//go:generate go install github.com/vektra/mockery/v2@latest
|
|
|
|
//go:generate mockery --name Store --output mocks --case underscore
|
|
|
|
|
2016-03-25 19:54:16 +00:00
|
|
|
import (
|
2023-11-07 07:04:33 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/server/model"
|
2016-03-25 19:54:16 +00:00
|
|
|
)
|
|
|
|
|
2021-11-13 19:18:06 +00:00
|
|
|
// TODO: CreateX func should return new object to not indirect let storage change an existing object (alter ID etc...)
|
|
|
|
|
2015-10-21 23:14:02 +00:00
|
|
|
type Store interface {
|
2022-01-06 06:44:14 +00:00
|
|
|
// Users
|
2016-03-25 19:54:16 +00:00
|
|
|
// GetUser gets a user by unique ID.
|
|
|
|
GetUser(int64) (*model.User, error)
|
2023-05-11 03:19:35 +00:00
|
|
|
// GetUserRemoteID gets a user by remote ID with fallback to login name.
|
|
|
|
GetUserRemoteID(model.ForgeRemoteID, string) (*model.User, error)
|
2016-03-25 19:54:16 +00:00
|
|
|
// GetUserLogin gets a user by unique Login name.
|
|
|
|
GetUserLogin(string) (*model.User, error)
|
|
|
|
// GetUserList gets a list of all users in the system.
|
2023-04-30 01:40:13 +00:00
|
|
|
GetUserList(p *model.ListOptions) ([]*model.User, error)
|
2016-03-25 19:54:16 +00:00
|
|
|
// GetUserCount gets a count of all users in the system.
|
2021-11-13 19:18:06 +00:00
|
|
|
GetUserCount() (int64, error)
|
2016-03-25 19:54:16 +00:00
|
|
|
// CreateUser creates a new user account.
|
|
|
|
CreateUser(*model.User) error
|
|
|
|
// UpdateUser updates a user account.
|
|
|
|
UpdateUser(*model.User) error
|
|
|
|
// DeleteUser deletes a user account.
|
|
|
|
DeleteUser(*model.User) error
|
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Repos
|
2016-03-25 19:54:16 +00:00
|
|
|
// GetRepo gets a repo by unique ID.
|
|
|
|
GetRepo(int64) (*model.Repo, error)
|
2022-11-04 23:35:06 +00:00
|
|
|
// GetRepoForgeID gets a repo by its forge ID.
|
2022-11-15 14:01:23 +00:00
|
|
|
GetRepoForgeID(model.ForgeRemoteID) (*model.Repo, error)
|
2022-11-04 23:35:06 +00:00
|
|
|
// GetRepoNameFallback gets the repo by its forge ID and if this doesn't exist by its full name.
|
2022-11-15 14:01:23 +00:00
|
|
|
GetRepoNameFallback(remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error)
|
2016-03-25 19:54:16 +00:00
|
|
|
// GetRepoName gets a repo by its full name.
|
|
|
|
GetRepoName(string) (*model.Repo, error)
|
|
|
|
// GetRepoCount gets a count of all repositories in the system.
|
2021-11-13 19:18:06 +00:00
|
|
|
GetRepoCount() (int64, error)
|
2016-03-25 19:54:16 +00:00
|
|
|
// CreateRepo creates a new repository.
|
|
|
|
CreateRepo(*model.Repo) error
|
|
|
|
// UpdateRepo updates a user repository.
|
|
|
|
UpdateRepo(*model.Repo) error
|
|
|
|
// DeleteRepo deletes a user repository.
|
|
|
|
DeleteRepo(*model.Repo) error
|
|
|
|
|
2022-09-05 15:08:51 +00:00
|
|
|
// Redirections
|
|
|
|
// GetRedirection returns the redirection for the given full repo name
|
|
|
|
GetRedirection(string) (*model.Redirection, error)
|
|
|
|
// CreateRedirection creates a redirection
|
|
|
|
CreateRedirection(redirection *model.Redirection) error
|
|
|
|
// HasRedirectionForRepo checks if there's a redirection for the given repo and full name
|
|
|
|
HasRedirectionForRepo(int64, string) (bool, error)
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
// Pipelines
|
|
|
|
// GetPipeline gets a pipeline by unique ID.
|
|
|
|
GetPipeline(int64) (*model.Pipeline, error)
|
|
|
|
// GetPipelineNumber gets a pipeline by number.
|
|
|
|
GetPipelineNumber(*model.Repo, int64) (*model.Pipeline, error)
|
|
|
|
// GetPipelineRef gets a pipeline by its ref.
|
|
|
|
GetPipelineRef(*model.Repo, string) (*model.Pipeline, error)
|
|
|
|
// GetPipelineCommit gets a pipeline by its commit sha.
|
|
|
|
GetPipelineCommit(*model.Repo, string, string) (*model.Pipeline, error)
|
|
|
|
// GetPipelineLast gets the last pipeline for the branch.
|
|
|
|
GetPipelineLast(*model.Repo, string) (*model.Pipeline, error)
|
|
|
|
// GetPipelineLastBefore gets the last pipeline before pipeline number N.
|
|
|
|
GetPipelineLastBefore(*model.Repo, string, int64) (*model.Pipeline, error)
|
|
|
|
// GetPipelineList gets a list of pipelines for the repository
|
2023-04-30 01:40:13 +00:00
|
|
|
GetPipelineList(*model.Repo, *model.ListOptions) ([]*model.Pipeline, error)
|
|
|
|
// GetActivePipelineList gets a list of the active pipelines for the repository
|
|
|
|
GetActivePipelineList(repo *model.Repo) ([]*model.Pipeline, error)
|
2022-10-18 01:24:12 +00:00
|
|
|
// GetPipelineQueue gets a list of pipelines in queue.
|
|
|
|
GetPipelineQueue() ([]*model.Feed, error)
|
|
|
|
// GetPipelineCount gets a count of all pipelines in the system.
|
|
|
|
GetPipelineCount() (int64, error)
|
2022-10-28 15:38:53 +00:00
|
|
|
// CreatePipeline creates a new pipeline and steps.
|
|
|
|
CreatePipeline(*model.Pipeline, ...*model.Step) error
|
2022-10-18 01:24:12 +00:00
|
|
|
// UpdatePipeline updates a pipeline.
|
|
|
|
UpdatePipeline(*model.Pipeline) error
|
2016-03-25 19:54:16 +00:00
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Feeds
|
2017-07-14 19:58:38 +00:00
|
|
|
UserFeed(*model.User) ([]*model.Feed, error)
|
|
|
|
|
2022-09-05 15:08:51 +00:00
|
|
|
// Repositories
|
2023-04-30 01:40:13 +00:00
|
|
|
RepoList(user *model.User, owned, active bool) ([]*model.Repo, error)
|
2021-11-13 19:18:06 +00:00
|
|
|
RepoListLatest(*model.User) ([]*model.Feed, error)
|
2023-09-08 10:26:20 +00:00
|
|
|
RepoListAll(active bool, p *model.ListOptions) ([]*model.Repo, error)
|
2017-07-14 19:58:38 +00:00
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Permissions
|
2017-07-14 19:58:38 +00:00
|
|
|
PermFind(user *model.User, repo *model.Repo) (*model.Perm, error)
|
|
|
|
PermUpsert(perm *model.Perm) error
|
|
|
|
PermDelete(perm *model.Perm) error
|
2017-07-16 17:37:16 +00:00
|
|
|
PermFlush(user *model.User, before int64) error
|
2017-07-14 19:58:38 +00:00
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Configs
|
2022-10-18 01:24:12 +00:00
|
|
|
ConfigsForPipeline(pipelineID int64) ([]*model.Config, error)
|
2021-11-13 19:18:06 +00:00
|
|
|
ConfigFindIdentical(repoID int64, hash string) (*model.Config, error)
|
2017-05-05 18:05:42 +00:00
|
|
|
ConfigFindApproved(*model.Config) (bool, error)
|
|
|
|
ConfigCreate(*model.Config) error
|
2022-10-18 01:24:12 +00:00
|
|
|
PipelineConfigCreate(*model.PipelineConfig) error
|
2017-05-05 16:59:37 +00:00
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Secrets
|
2017-04-11 17:06:45 +00:00
|
|
|
SecretFind(*model.Repo, string) (*model.Secret, error)
|
2023-04-30 01:40:13 +00:00
|
|
|
SecretList(*model.Repo, bool, *model.ListOptions) ([]*model.Secret, error)
|
2023-01-12 19:59:07 +00:00
|
|
|
SecretListAll() ([]*model.Secret, error)
|
2017-04-11 17:06:45 +00:00
|
|
|
SecretCreate(*model.Secret) error
|
|
|
|
SecretUpdate(*model.Secret) error
|
|
|
|
SecretDelete(*model.Secret) error
|
2023-07-21 17:45:32 +00:00
|
|
|
OrgSecretFind(int64, string) (*model.Secret, error)
|
|
|
|
OrgSecretList(int64, *model.ListOptions) ([]*model.Secret, error)
|
2022-08-14 11:48:53 +00:00
|
|
|
GlobalSecretFind(string) (*model.Secret, error)
|
2023-04-30 01:40:13 +00:00
|
|
|
GlobalSecretList(*model.ListOptions) ([]*model.Secret, error)
|
2016-05-11 21:37:56 +00:00
|
|
|
|
2022-11-09 07:12:17 +00:00
|
|
|
// Registries
|
2017-04-06 12:51:01 +00:00
|
|
|
RegistryFind(*model.Repo, string) (*model.Registry, error)
|
2023-04-30 01:40:13 +00:00
|
|
|
RegistryList(*model.Repo, *model.ListOptions) ([]*model.Registry, error)
|
2017-04-06 12:51:01 +00:00
|
|
|
RegistryCreate(*model.Registry) error
|
|
|
|
RegistryUpdate(*model.Registry) error
|
2021-11-25 18:04:36 +00:00
|
|
|
RegistryDelete(repo *model.Repo, addr string) error
|
2017-03-28 08:53:06 +00:00
|
|
|
|
2022-10-28 15:38:53 +00:00
|
|
|
// Steps
|
|
|
|
StepLoad(int64) (*model.Step, error)
|
|
|
|
StepFind(*model.Pipeline, int) (*model.Step, error)
|
2023-06-06 07:52:08 +00:00
|
|
|
StepByUUID(string) (*model.Step, error)
|
2022-10-28 15:38:53 +00:00
|
|
|
StepChild(*model.Pipeline, int, string) (*model.Step, error)
|
|
|
|
StepList(*model.Pipeline) ([]*model.Step, error)
|
|
|
|
StepUpdate(*model.Step) error
|
2023-06-27 16:01:18 +00:00
|
|
|
StepListFromWorkflowFind(*model.Workflow) ([]*model.Step, error)
|
2017-03-28 08:53:06 +00:00
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Logs
|
2023-06-06 07:52:08 +00:00
|
|
|
LogFind(*model.Step) ([]*model.LogEntry, error)
|
|
|
|
LogSave(*model.Step, []*model.LogEntry) error
|
|
|
|
LogAppend(logEntry *model.LogEntry) error
|
|
|
|
LogDelete(*model.Step) error
|
2017-04-03 09:34:37 +00:00
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Tasks
|
2021-11-13 19:18:06 +00:00
|
|
|
// TaskList TODO: paginate & opt filter
|
2017-04-14 11:32:36 +00:00
|
|
|
TaskList() ([]*model.Task, error)
|
|
|
|
TaskInsert(*model.Task) error
|
|
|
|
TaskDelete(string) error
|
2017-10-05 21:17:27 +00:00
|
|
|
|
2022-06-01 18:06:27 +00:00
|
|
|
// ServerConfig
|
|
|
|
ServerConfigGet(string) (string, error)
|
|
|
|
ServerConfigSet(string, string) error
|
2023-01-12 19:59:07 +00:00
|
|
|
ServerConfigDelete(string) error
|
2022-06-01 18:06:27 +00:00
|
|
|
|
2022-08-31 22:36:32 +00:00
|
|
|
// Cron
|
|
|
|
CronCreate(*model.Cron) error
|
|
|
|
CronFind(*model.Repo, int64) (*model.Cron, error)
|
2023-04-30 01:40:13 +00:00
|
|
|
CronList(*model.Repo, *model.ListOptions) ([]*model.Cron, error)
|
2022-08-31 22:36:32 +00:00
|
|
|
CronUpdate(*model.Repo, *model.Cron) error
|
|
|
|
CronDelete(*model.Repo, int64) error
|
|
|
|
CronListNextExecute(int64, int64) ([]*model.Cron, error)
|
|
|
|
CronGetLock(*model.Cron, int64) (bool, error)
|
|
|
|
|
2023-01-28 13:13:04 +00:00
|
|
|
// Agent
|
|
|
|
AgentCreate(*model.Agent) error
|
|
|
|
AgentFind(int64) (*model.Agent, error)
|
|
|
|
AgentFindByToken(string) (*model.Agent, error)
|
2023-04-30 01:40:13 +00:00
|
|
|
AgentList(p *model.ListOptions) ([]*model.Agent, error)
|
2023-01-28 13:13:04 +00:00
|
|
|
AgentUpdate(*model.Agent) error
|
|
|
|
AgentDelete(*model.Agent) error
|
|
|
|
|
2023-06-27 16:01:18 +00:00
|
|
|
// Workflow
|
|
|
|
WorkflowGetTree(*model.Pipeline) ([]*model.Workflow, error)
|
|
|
|
WorkflowsCreate([]*model.Workflow) error
|
|
|
|
WorkflowLoad(int64) (*model.Workflow, error)
|
|
|
|
WorkflowUpdate(*model.Workflow) error
|
|
|
|
|
2023-07-21 17:45:32 +00:00
|
|
|
// Org
|
|
|
|
OrgCreate(*model.Org) error
|
|
|
|
OrgGet(int64) (*model.Org, error)
|
|
|
|
OrgFindByName(string) (*model.Org, error)
|
|
|
|
OrgUpdate(*model.Org) error
|
|
|
|
OrgDelete(int64) error
|
2023-08-28 09:15:16 +00:00
|
|
|
OrgList(*model.ListOptions) ([]*model.Org, error)
|
2023-07-21 17:45:32 +00:00
|
|
|
|
|
|
|
// Org repos
|
|
|
|
OrgRepoList(*model.Org, *model.ListOptions) ([]*model.Repo, error)
|
|
|
|
|
2022-01-06 06:44:14 +00:00
|
|
|
// Store operations
|
2017-10-05 21:17:27 +00:00
|
|
|
Ping() error
|
2021-11-13 19:18:06 +00:00
|
|
|
Close() error
|
2023-11-28 09:31:54 +00:00
|
|
|
Migrate(bool) error
|
2016-03-25 19:54:16 +00:00
|
|
|
}
|