2021-05-08 22:25:31 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import "github.com/ansible-semaphore/semaphore/db"
|
|
|
|
|
|
|
|
func (d *BoltDb) GetEnvironment(projectID int, environmentID int) (environment db.Environment, err error) {
|
2021-05-13 21:45:54 +02:00
|
|
|
err = d.getObject(projectID, db.EnvironmentProps, intObjectID(environmentID), &environment)
|
2021-05-08 22:25:31 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
func (d *BoltDb) GetEnvironmentRefs(projectID int, environmentID int) (db.ObjectReferrers, error) {
|
|
|
|
return d.getObjectRefs(projectID, db.EnvironmentProps, environmentID)
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:25:31 +02:00
|
|
|
func (d *BoltDb) GetEnvironments(projectID int, params db.RetrieveQueryParams) (environment []db.Environment, err error) {
|
2021-05-13 21:45:54 +02:00
|
|
|
err = d.getObjects(projectID, db.EnvironmentProps, params, nil, &environment)
|
2021-05-08 22:25:31 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) UpdateEnvironment(env db.Environment) error {
|
2021-11-02 20:30:45 +01:00
|
|
|
err := env.Validate()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-05-14 13:47:32 +02:00
|
|
|
return d.updateObject(env.ProjectID, db.EnvironmentProps, env)
|
2021-05-08 22:25:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) CreateEnvironment(env db.Environment) (db.Environment, error) {
|
2021-11-02 20:30:45 +01:00
|
|
|
err := env.Validate()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return db.Environment{}, err
|
|
|
|
}
|
|
|
|
|
2021-05-13 21:45:54 +02:00
|
|
|
newEnv, err := d.createObject(env.ProjectID, db.EnvironmentProps, env)
|
2021-05-08 22:25:31 +02:00
|
|
|
return newEnv.(db.Environment), err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteEnvironment(projectID int, environmentID int) error {
|
2022-01-31 23:16:00 +01:00
|
|
|
return d.deleteObject(projectID, db.EnvironmentProps, intObjectID(environmentID), nil)
|
2021-05-08 22:25:31 +02:00
|
|
|
}
|
2024-07-02 19:26:59 +02:00
|
|
|
|
|
|
|
func (d *BoltDb) GetEnvironmentSecrets(projectID int, environmentID int) ([]db.AccessKey, error) {
|
|
|
|
var keys []db.AccessKey
|
|
|
|
err := d.getObjects(projectID, db.AccessKeyProps, db.RetrieveQueryParams{}, func(i interface{}) bool {
|
|
|
|
k := i.(db.AccessKey)
|
|
|
|
return k.EnvironmentID != nil && *k.EnvironmentID == environmentID
|
|
|
|
}, &keys)
|
|
|
|
return keys, err
|
|
|
|
}
|