2023-08-27 18:02:51 +02:00
|
|
|
package bolt
|
|
|
|
|
2023-08-29 00:51:04 +02:00
|
|
|
import (
|
2024-10-13 00:56:45 +02:00
|
|
|
"encoding/base64"
|
|
|
|
|
2023-08-29 00:51:04 +02:00
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
2024-10-13 00:56:45 +02:00
|
|
|
"github.com/gorilla/securecookie"
|
|
|
|
"go.etcd.io/bbolt"
|
2023-08-29 00:51:04 +02:00
|
|
|
)
|
2023-08-27 18:02:51 +02:00
|
|
|
|
|
|
|
func (d *BoltDb) GetRunner(projectID int, runnerID int) (runner db.Runner, err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) GetRunners(projectID int) (runners []db.Runner, err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteRunner(projectID int, runnerID int) (err error) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-09-29 11:57:02 +02:00
|
|
|
func (d *BoltDb) GetGlobalRunnerByToken(token string) (runner db.Runner, err error) {
|
|
|
|
|
|
|
|
runners := make([]db.Runner, 0)
|
|
|
|
|
|
|
|
err = d.getObjects(0, db.GlobalRunnerProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
|
|
|
|
r := i.(db.Runner)
|
|
|
|
return r.Token == token
|
|
|
|
}, &runners)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(runners) == 0 {
|
|
|
|
err = db.ErrNotFound
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
runner = runners[0]
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-08-27 18:02:51 +02:00
|
|
|
func (d *BoltDb) GetGlobalRunner(runnerID int) (runner db.Runner, err error) {
|
2023-09-11 01:02:10 +02:00
|
|
|
err = d.getObject(0, db.GlobalRunnerProps, intObjectID(runnerID), &runner)
|
2023-08-29 00:51:04 +02:00
|
|
|
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-09-26 14:52:31 +02:00
|
|
|
func (d *BoltDb) GetGlobalRunners(activeOnly bool) (runners []db.Runner, err error) {
|
|
|
|
err = d.getObjects(0, db.GlobalRunnerProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
|
2024-10-13 00:56:45 +02:00
|
|
|
runner := i.(db.Runner)
|
2024-09-26 14:52:31 +02:00
|
|
|
if activeOnly {
|
|
|
|
return runner.Active
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}, &runners)
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteGlobalRunner(runnerID int) (err error) {
|
2024-10-13 00:56:45 +02:00
|
|
|
return d.db.Update(func(tx *bbolt.Tx) error {
|
|
|
|
return d.deleteObject(0, db.GlobalRunnerProps, intObjectID(runnerID), tx)
|
|
|
|
})
|
2023-08-27 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) UpdateRunner(runner db.Runner) (err error) {
|
2024-10-13 16:31:38 +02:00
|
|
|
return d.updateObject(0, db.GlobalRunnerProps, runner)
|
2023-08-27 18:02:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) CreateRunner(runner db.Runner) (newRunner db.Runner, err error) {
|
2024-10-13 00:56:45 +02:00
|
|
|
runner.Token = base64.StdEncoding.EncodeToString(securecookie.GenerateRandomKey(32))
|
2023-08-29 00:51:04 +02:00
|
|
|
|
2023-09-11 01:02:10 +02:00
|
|
|
res, err := d.createObject(0, db.GlobalRunnerProps, runner)
|
2023-08-29 00:51:04 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newRunner = res.(db.Runner)
|
2023-08-27 18:02:51 +02:00
|
|
|
return
|
|
|
|
}
|