2023-08-27 18:02:51 +02:00
|
|
|
package sql
|
|
|
|
|
2023-09-11 01:02:10 +02:00
|
|
|
import (
|
|
|
|
"encoding/base64"
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
"github.com/gorilla/securecookie"
|
|
|
|
)
|
2023-08-27 18:02:51 +02:00
|
|
|
|
|
|
|
func (d *SqlDb) GetRunner(projectID int, runnerID int) (runner db.Runner, err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) GetRunners(projectID int) (runners []db.Runner, err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) DeleteRunner(projectID int, runnerID int) (err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) GetGlobalRunner(runnerID int) (runner db.Runner, err error) {
|
2023-09-11 01:02:10 +02:00
|
|
|
err = d.getObject(0, db.GlobalRunnerProps, runnerID, &runner)
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) GetGlobalRunners() (runners []db.Runner, err error) {
|
2024-01-28 12:24:37 +01:00
|
|
|
err = d.getProjectObjects(0, db.GlobalRunnerProps, db.RetrieveQueryParams{}, &runners)
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) DeleteGlobalRunner(runnerID int) (err error) {
|
2023-09-11 01:02:10 +02:00
|
|
|
err = d.deleteObject(0, db.GlobalRunnerProps, runnerID)
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) UpdateRunner(runner db.Runner) (err error) {
|
2023-09-11 01:02:10 +02:00
|
|
|
_, err = d.exec(
|
|
|
|
"update runner set webhook=?, max_parallel_tasks=? where id=?",
|
|
|
|
runner.Webhook,
|
|
|
|
runner.MaxParallelTasks,
|
|
|
|
runner.ID)
|
|
|
|
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) CreateRunner(runner db.Runner) (newRunner db.Runner, err error) {
|
2023-09-11 01:02:10 +02:00
|
|
|
token := base64.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
|
|
|
|
|
|
|
|
insertID, err := d.insert(
|
|
|
|
"id",
|
|
|
|
"insert into runner (project_id, token, webhook, max_parallel_tasks) values (?, ?, ?, ?)",
|
|
|
|
runner.ProjectID,
|
|
|
|
token,
|
|
|
|
runner.Webhook,
|
|
|
|
runner.MaxParallelTasks)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newRunner = runner
|
|
|
|
newRunner.ID = insertID
|
|
|
|
newRunner.Token = token
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|