2020-12-01 20:06:49 +01:00
|
|
|
package db
|
|
|
|
|
|
|
|
import (
|
2020-12-03 14:51:15 +01:00
|
|
|
"errors"
|
2020-12-01 20:06:49 +01:00
|
|
|
"github.com/ansible-semaphore/semaphore/models"
|
|
|
|
"github.com/go-gorp/gorp/v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type RetrieveQueryParams struct {
|
|
|
|
Offset int
|
|
|
|
Count int
|
|
|
|
SortBy string
|
|
|
|
SortInverted bool
|
|
|
|
}
|
|
|
|
|
2020-12-03 14:51:15 +01:00
|
|
|
var ErrNotFound = errors.New("sql: no rows in result set")
|
2020-12-04 17:29:37 +01:00
|
|
|
var ErrInvalidOperation = errors.New("sql: no rows in result set")
|
2020-12-01 20:06:49 +01:00
|
|
|
|
|
|
|
type Store interface {
|
|
|
|
Connect() error
|
|
|
|
Close() error
|
|
|
|
Migrate() error
|
|
|
|
|
2020-12-03 14:51:15 +01:00
|
|
|
GetEnvironment(projectID int, environmentID int) (models.Environment, error)
|
|
|
|
GetEnvironments(projectID int, params RetrieveQueryParams) ([]models.Environment, error)
|
|
|
|
UpdateEnvironment(env models.Environment) error
|
2020-12-04 17:29:37 +01:00
|
|
|
CreateEnvironment(env models.Environment) (models.Environment, error)
|
|
|
|
DeleteEnvironment(projectID int, templateID int) error
|
|
|
|
DeleteEnvironmentSoft(projectID int, templateID int) error
|
2020-12-03 14:51:15 +01:00
|
|
|
|
2020-12-01 20:06:49 +01:00
|
|
|
GetUsers(params RetrieveQueryParams) ([]models.User, error)
|
|
|
|
CreateUser(user models.User) (models.User, error)
|
|
|
|
DeleteUser(userID int) error
|
2020-12-03 14:51:15 +01:00
|
|
|
UpdateUser(user models.User) error
|
2020-12-01 20:06:49 +01:00
|
|
|
SetUserPassword(userID int, password string) error
|
2020-12-03 14:51:15 +01:00
|
|
|
GetUser(userID int) (models.User, error)
|
2020-12-01 20:06:49 +01:00
|
|
|
|
|
|
|
CreateProject(project models.Project) (models.Project, error)
|
|
|
|
//DeleteProject(projectId int) error
|
|
|
|
//UpdateProject(project Project) error
|
|
|
|
//GetProjectById(projectId int) (Project, error)
|
|
|
|
//GetProjects(userId int) ([]Project, error)
|
|
|
|
//
|
2020-12-03 14:51:15 +01:00
|
|
|
|
|
|
|
GetTemplates(projectID int, params RetrieveQueryParams) ([]models.Template, error)
|
|
|
|
CreateTemplate(template models.Template) (models.Template, error)
|
|
|
|
UpdateTemplate(template models.Template) error
|
|
|
|
GetTemplate(projectID int, templateID int) (models.Template, error)
|
|
|
|
DeleteTemplate(projectID int, templateID int) error
|
|
|
|
|
2020-12-01 20:06:49 +01:00
|
|
|
CreateProjectUser(projectUser models.ProjectUser) (models.ProjectUser, error)
|
|
|
|
DeleteProjectUser(projectID, userID int) error
|
2020-12-03 14:51:15 +01:00
|
|
|
|
2020-12-01 20:06:49 +01:00
|
|
|
CreateEvent(event models.Event) (models.Event, error)
|
|
|
|
|
2020-12-03 14:51:15 +01:00
|
|
|
GetAPITokens(userID int) ([]models.APIToken, error)
|
2020-12-01 20:06:49 +01:00
|
|
|
CreateAPIToken(token models.APIToken) (models.APIToken, error)
|
2020-12-03 14:51:15 +01:00
|
|
|
GetAPIToken(tokenID string) (models.APIToken, error)
|
|
|
|
ExpireAPIToken(userID int, tokenID string) error
|
|
|
|
|
|
|
|
GetSession(userID int, sessionID int) (models.Session, error)
|
|
|
|
ExpireSession(userID int, sessionID int) error
|
|
|
|
TouchSession(userID int, sessionID int) error
|
|
|
|
|
2020-12-01 20:06:49 +01:00
|
|
|
Sql() *gorp.DbMap
|
|
|
|
}
|