2018-02-20 00:24:10 +02:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-21 15:02:17 +02:00
|
|
|
//
|
2018-02-20 00:24:10 +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
|
2018-03-21 15:02:17 +02:00
|
|
|
//
|
2018-02-20 00:24:10 +02:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-21 15:02:17 +02:00
|
|
|
//
|
2018-02-20 00:24:10 +02: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-22 01:14:02 +02:00
|
|
|
package store
|
|
|
|
|
2022-09-01 01:19:49 +02:00
|
|
|
//go:generate go install github.com/vektra/mockery/v2@latest
|
|
|
|
//go:generate mockery --name Store --output mocks --case underscore
|
|
|
|
|
2016-03-25 21:54:16 +02:00
|
|
|
import (
|
2021-10-12 09:25:13 +02:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
2016-03-25 21:54:16 +02:00
|
|
|
)
|
|
|
|
|
2021-11-13 21:18:06 +02:00
|
|
|
// TODO: CreateX func should return new object to not indirect let storage change an existing object (alter ID etc...)
|
|
|
|
|
2015-10-22 01:14:02 +02:00
|
|
|
type Store interface {
|
2022-01-06 08:44:14 +02:00
|
|
|
// Users
|
2016-03-25 21:54:16 +02:00
|
|
|
// GetUser gets a user by unique ID.
|
|
|
|
GetUser(int64) (*model.User, error)
|
2023-05-11 05:19:35 +02:00
|
|
|
// GetUserRemoteID gets a user by remote ID with fallback to login name.
|
|
|
|
GetUserRemoteID(model.ForgeRemoteID, string) (*model.User, error)
|
2016-03-25 21:54:16 +02: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 03:40:13 +02:00
|
|
|
GetUserList(p *model.ListOptions) ([]*model.User, error)
|
2016-03-25 21:54:16 +02:00
|
|
|
// GetUserCount gets a count of all users in the system.
|
2021-11-13 21:18:06 +02:00
|
|
|
GetUserCount() (int64, error)
|
2016-03-25 21:54:16 +02: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 08:44:14 +02:00
|
|
|
// Repos
|
2016-03-25 21:54:16 +02:00
|
|
|
// GetRepo gets a repo by unique ID.
|
|
|
|
GetRepo(int64) (*model.Repo, error)
|
2022-11-05 01:35:06 +02:00
|
|
|
// GetRepoForgeID gets a repo by its forge ID.
|
2022-11-15 16:01:23 +02:00
|
|
|
GetRepoForgeID(model.ForgeRemoteID) (*model.Repo, error)
|
2022-11-05 01:35:06 +02:00
|
|
|
// GetRepoNameFallback gets the repo by its forge ID and if this doesn't exist by its full name.
|
2022-11-15 16:01:23 +02:00
|
|
|
GetRepoNameFallback(remoteID model.ForgeRemoteID, fullName string) (*model.Repo, error)
|
2016-03-25 21:54:16 +02: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 21:18:06 +02:00
|
|
|
GetRepoCount() (int64, error)
|
2016-03-25 21:54:16 +02: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 17:08:51 +02: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 03:24:12 +02: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 03:40:13 +02: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 03:24:12 +02: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 17:38:53 +02:00
|
|
|
// CreatePipeline creates a new pipeline and steps.
|
|
|
|
CreatePipeline(*model.Pipeline, ...*model.Step) error
|
2022-10-18 03:24:12 +02:00
|
|
|
// UpdatePipeline updates a pipeline.
|
|
|
|
UpdatePipeline(*model.Pipeline) error
|
2016-03-25 21:54:16 +02:00
|
|
|
|
2022-01-06 08:44:14 +02:00
|
|
|
// Feeds
|
2017-07-14 21:58:38 +02:00
|
|
|
UserFeed(*model.User) ([]*model.Feed, error)
|
|
|
|
|
2022-09-05 17:08:51 +02:00
|
|
|
// Repositories
|
2023-04-30 03:40:13 +02:00
|
|
|
RepoList(user *model.User, owned, active bool) ([]*model.Repo, error)
|
2021-11-13 21:18:06 +02:00
|
|
|
RepoListLatest(*model.User) ([]*model.Feed, error)
|
2017-07-14 21:58:38 +02:00
|
|
|
|
2022-01-06 08:44:14 +02:00
|
|
|
// Permissions
|
2017-07-14 21:58:38 +02:00
|
|
|
PermFind(user *model.User, repo *model.Repo) (*model.Perm, error)
|
|
|
|
PermUpsert(perm *model.Perm) error
|
|
|
|
PermDelete(perm *model.Perm) error
|
2017-07-16 19:37:16 +02:00
|
|
|
PermFlush(user *model.User, before int64) error
|
2017-07-14 21:58:38 +02:00
|
|
|
|
2022-01-06 08:44:14 +02:00
|
|
|
// Configs
|
2022-10-18 03:24:12 +02:00
|
|
|
ConfigsForPipeline(pipelineID int64) ([]*model.Config, error)
|
2021-11-13 21:18:06 +02:00
|
|
|
ConfigFindIdentical(repoID int64, hash string) (*model.Config, error)
|
2017-05-05 20:05:42 +02:00
|
|
|
ConfigFindApproved(*model.Config) (bool, error)
|
|
|
|
ConfigCreate(*model.Config) error
|
2022-10-18 03:24:12 +02:00
|
|
|
PipelineConfigCreate(*model.PipelineConfig) error
|
2017-05-05 18:59:37 +02:00
|
|
|
|
2022-01-06 08:44:14 +02:00
|
|
|
// Secrets
|
2017-04-11 19:06:45 +02:00
|
|
|
SecretFind(*model.Repo, string) (*model.Secret, error)
|
2023-04-30 03:40:13 +02:00
|
|
|
SecretList(*model.Repo, bool, *model.ListOptions) ([]*model.Secret, error)
|
2023-01-12 21:59:07 +02:00
|
|
|
SecretListAll() ([]*model.Secret, error)
|
2017-04-11 19:06:45 +02:00
|
|
|
SecretCreate(*model.Secret) error
|
|
|
|
SecretUpdate(*model.Secret) error
|
|
|
|
SecretDelete(*model.Secret) error
|
2022-08-14 13:48:53 +02:00
|
|
|
OrgSecretFind(string, string) (*model.Secret, error)
|
2023-04-30 03:40:13 +02:00
|
|
|
OrgSecretList(string, *model.ListOptions) ([]*model.Secret, error)
|
2022-08-14 13:48:53 +02:00
|
|
|
GlobalSecretFind(string) (*model.Secret, error)
|
2023-04-30 03:40:13 +02:00
|
|
|
GlobalSecretList(*model.ListOptions) ([]*model.Secret, error)
|
2016-05-11 23:37:56 +02:00
|
|
|
|
2022-11-09 09:12:17 +02:00
|
|
|
// Registries
|
2017-04-06 14:51:01 +02:00
|
|
|
RegistryFind(*model.Repo, string) (*model.Registry, error)
|
2023-04-30 03:40:13 +02:00
|
|
|
RegistryList(*model.Repo, *model.ListOptions) ([]*model.Registry, error)
|
2017-04-06 14:51:01 +02:00
|
|
|
RegistryCreate(*model.Registry) error
|
|
|
|
RegistryUpdate(*model.Registry) error
|
2021-11-25 20:04:36 +02:00
|
|
|
RegistryDelete(repo *model.Repo, addr string) error
|
2017-03-28 10:53:06 +02:00
|
|
|
|
2022-10-28 17:38:53 +02:00
|
|
|
// Steps
|
|
|
|
StepLoad(int64) (*model.Step, error)
|
|
|
|
StepFind(*model.Pipeline, int) (*model.Step, error)
|
2023-06-06 09:52:08 +02:00
|
|
|
StepByUUID(string) (*model.Step, error)
|
2022-10-28 17:38:53 +02:00
|
|
|
StepChild(*model.Pipeline, int, string) (*model.Step, error)
|
|
|
|
StepList(*model.Pipeline) ([]*model.Step, error)
|
|
|
|
StepCreate([]*model.Step) error
|
|
|
|
StepUpdate(*model.Step) error
|
|
|
|
StepClear(*model.Pipeline) error
|
2017-03-28 10:53:06 +02:00
|
|
|
|
2022-01-06 08:44:14 +02:00
|
|
|
// Logs
|
2023-06-06 09:52:08 +02: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 11:34:37 +02:00
|
|
|
|
2022-01-06 08:44:14 +02:00
|
|
|
// Tasks
|
2021-11-13 21:18:06 +02:00
|
|
|
// TaskList TODO: paginate & opt filter
|
2017-04-14 13:32:36 +02:00
|
|
|
TaskList() ([]*model.Task, error)
|
|
|
|
TaskInsert(*model.Task) error
|
|
|
|
TaskDelete(string) error
|
2017-10-05 23:17:27 +02:00
|
|
|
|
2022-06-01 20:06:27 +02:00
|
|
|
// ServerConfig
|
|
|
|
ServerConfigGet(string) (string, error)
|
|
|
|
ServerConfigSet(string, string) error
|
2023-01-12 21:59:07 +02:00
|
|
|
ServerConfigDelete(string) error
|
2022-06-01 20:06:27 +02:00
|
|
|
|
2022-09-01 00:36:32 +02:00
|
|
|
// Cron
|
|
|
|
CronCreate(*model.Cron) error
|
|
|
|
CronFind(*model.Repo, int64) (*model.Cron, error)
|
2023-04-30 03:40:13 +02:00
|
|
|
CronList(*model.Repo, *model.ListOptions) ([]*model.Cron, error)
|
2022-09-01 00:36:32 +02: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 15:13:04 +02:00
|
|
|
// Agent
|
|
|
|
AgentCreate(*model.Agent) error
|
|
|
|
AgentFind(int64) (*model.Agent, error)
|
|
|
|
AgentFindByToken(string) (*model.Agent, error)
|
2023-04-30 03:40:13 +02:00
|
|
|
AgentList(p *model.ListOptions) ([]*model.Agent, error)
|
2023-01-28 15:13:04 +02:00
|
|
|
AgentUpdate(*model.Agent) error
|
|
|
|
AgentDelete(*model.Agent) error
|
|
|
|
|
2022-01-06 08:44:14 +02:00
|
|
|
// Store operations
|
2017-10-05 23:17:27 +02:00
|
|
|
Ping() error
|
2021-11-13 21:18:06 +02:00
|
|
|
Close() error
|
|
|
|
Migrate() error
|
2016-03-25 21:54:16 +02:00
|
|
|
}
|