2020-12-20 19:00:59 +01:00
|
|
|
package sql
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
)
|
2020-12-20 19:00:59 +01:00
|
|
|
|
|
|
|
func (d *SqlDb) GetEnvironment(projectID int, environmentID int) (db.Environment, error) {
|
|
|
|
var environment db.Environment
|
2021-05-13 21:45:54 +02:00
|
|
|
err := d.getObject(projectID, db.EnvironmentProps, environmentID, &environment)
|
2020-12-20 19:00:59 +01:00
|
|
|
return environment, err
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
func (d *SqlDb) GetEnvironmentRefs(projectID int, environmentID int) (db.ObjectReferrers, error) {
|
|
|
|
return d.getObjectRefs(projectID, db.EnvironmentProps, environmentID)
|
|
|
|
}
|
|
|
|
|
2020-12-20 19:00:59 +01:00
|
|
|
func (d *SqlDb) GetEnvironments(projectID int, params db.RetrieveQueryParams) ([]db.Environment, error) {
|
|
|
|
var environment []db.Environment
|
2021-05-13 21:45:54 +02:00
|
|
|
err := d.getObjects(projectID, db.EnvironmentProps, params, &environment)
|
2020-12-20 19:00:59 +01:00
|
|
|
return environment, err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) UpdateEnvironment(env db.Environment) error {
|
2021-11-02 20:30:45 +01:00
|
|
|
err := env.Validate()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = d.exec(
|
2022-06-24 12:19:52 +02:00
|
|
|
"update project__environment set name=?, json=?, env=? where id=?",
|
2020-12-20 19:00:59 +01:00
|
|
|
env.Name,
|
|
|
|
env.JSON,
|
2022-06-24 12:19:52 +02:00
|
|
|
env.ENV,
|
2020-12-20 19:00:59 +01:00
|
|
|
env.ID)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) CreateEnvironment(env db.Environment) (newEnv db.Environment, err error) {
|
2021-11-02 20:30:45 +01:00
|
|
|
err = env.Validate()
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-24 19:52:35 +02:00
|
|
|
insertID, err := d.insert(
|
|
|
|
"id",
|
2022-06-29 19:27:14 +02:00
|
|
|
"insert into project__environment (project_id, name, json, env, password) values (?, ?, ?, ?, ?)",
|
2020-12-20 19:00:59 +01:00
|
|
|
env.ProjectID,
|
|
|
|
env.Name,
|
|
|
|
env.JSON,
|
2022-06-24 12:19:52 +02:00
|
|
|
env.ENV,
|
2020-12-20 19:00:59 +01:00
|
|
|
env.Password)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newEnv = env
|
2021-08-24 19:52:35 +02:00
|
|
|
newEnv.ID = insertID
|
2020-12-20 19:00:59 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) DeleteEnvironment(projectID int, environmentID int) error {
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.deleteObject(projectID, db.EnvironmentProps, environmentID)
|
2020-12-20 19:00:59 +01:00
|
|
|
}
|