2020-12-20 19:00:59 +01:00
|
|
|
package sql
|
|
|
|
|
|
|
|
import "github.com/ansible-semaphore/semaphore/db"
|
|
|
|
|
2021-05-06 10:32:13 +02:00
|
|
|
func (d *SqlDb) GetInventory(projectID int, inventoryID int) (inventory db.Inventory, err error) {
|
2021-05-13 21:45:54 +02:00
|
|
|
err = d.getObject(projectID, db.InventoryProps, inventoryID, &inventory)
|
2021-05-06 10:32:13 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-09-01 21:17:28 +02:00
|
|
|
err = db.FillInventory(d, &inventory)
|
2021-05-06 10:32:13 +02:00
|
|
|
return
|
2020-12-20 19:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) GetInventories(projectID int, params db.RetrieveQueryParams) ([]db.Inventory, error) {
|
|
|
|
var inventories []db.Inventory
|
2024-01-28 12:24:37 +01:00
|
|
|
err := d.getProjectObjects(projectID, db.InventoryProps, params, &inventories)
|
2020-12-20 19:00:59 +01:00
|
|
|
return inventories, err
|
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
func (d *SqlDb) GetInventoryRefs(projectID int, inventoryID int) (db.ObjectReferrers, error) {
|
|
|
|
return d.getObjectRefs(projectID, db.InventoryProps, inventoryID)
|
2020-12-20 19:00:59 +01:00
|
|
|
}
|
|
|
|
|
2022-02-03 08:05:13 +01:00
|
|
|
func (d *SqlDb) DeleteInventory(projectID int, inventoryID int) error {
|
|
|
|
return d.deleteObject(projectID, db.InventoryProps, inventoryID)
|
2020-12-20 19:00:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) UpdateInventory(inventory db.Inventory) error {
|
2021-08-24 17:20:34 +02:00
|
|
|
_, err := d.exec(
|
2024-03-10 13:13:44 +01:00
|
|
|
"update project__inventory set name=?, type=?, ssh_key_id=?, inventory=?, become_key_id=?, holder_id=? where id=?",
|
2020-12-20 19:00:59 +01:00
|
|
|
inventory.Name,
|
|
|
|
inventory.Type,
|
|
|
|
inventory.SSHKeyID,
|
|
|
|
inventory.Inventory,
|
2021-09-17 12:10:36 +02:00
|
|
|
inventory.BecomeKeyID,
|
2024-03-10 13:13:44 +01:00
|
|
|
inventory.HolderID,
|
2020-12-20 19:00:59 +01:00
|
|
|
inventory.ID)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *SqlDb) CreateInventory(inventory db.Inventory) (newInventory db.Inventory, err error) {
|
2021-08-24 19:52:35 +02:00
|
|
|
insertID, err := d.insert(
|
|
|
|
"id",
|
2024-03-10 13:13:44 +01:00
|
|
|
"insert into project__inventory (project_id, name, type, ssh_key_id, inventory, become_key_id, holder_id) values "+
|
|
|
|
"(?, ?, ?, ?, ?, ?, ?)",
|
2020-12-20 19:00:59 +01:00
|
|
|
inventory.ProjectID,
|
|
|
|
inventory.Name,
|
|
|
|
inventory.Type,
|
|
|
|
inventory.SSHKeyID,
|
2021-09-17 12:10:36 +02:00
|
|
|
inventory.Inventory,
|
2024-03-10 13:13:44 +01:00
|
|
|
inventory.BecomeKeyID,
|
|
|
|
inventory.HolderID)
|
2020-12-20 19:00:59 +01:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
newInventory = inventory
|
2021-08-24 19:52:35 +02:00
|
|
|
newInventory.ID = insertID
|
2020-12-20 19:00:59 +01:00
|
|
|
return
|
|
|
|
}
|