Semaphore/db/sql/inventory.go

61 lines
1.6 KiB
Go
Raw Normal View History

package sql
import "github.com/ansible-semaphore/semaphore/db"
func (d *SqlDb) GetInventory(projectID int, inventoryID int) (inventory db.Inventory, err error) {
2024-01-10 07:14:12 +01:00
err = d.getObject(projectID, db.InventoryProps, inventoryID, &inventory)
if err != nil {
return
}
err = db.FillInventory(d, &inventory)
return
}
func (d *SqlDb) GetInventories(projectID int, params db.RetrieveQueryParams) ([]db.Inventory, error) {
var inventories []db.Inventory
err := d.getObjects(projectID, db.InventoryProps, params, &inventories)
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)
}
2022-02-03 08:05:13 +01:00
func (d *SqlDb) DeleteInventory(projectID int, inventoryID int) error {
return d.deleteObject(projectID, db.InventoryProps, inventoryID)
}
func (d *SqlDb) UpdateInventory(inventory db.Inventory) error {
2021-08-24 17:20:34 +02:00
_, err := d.exec(
2021-09-17 12:10:36 +02:00
"update project__inventory set name=?, type=?, ssh_key_id=?, inventory=?, become_key_id=? where id=?",
inventory.Name,
inventory.Type,
inventory.SSHKeyID,
inventory.Inventory,
2021-09-17 12:10:36 +02:00
inventory.BecomeKeyID,
inventory.ID)
return err
}
func (d *SqlDb) CreateInventory(inventory db.Inventory) (newInventory db.Inventory, err error) {
insertID, err := d.insert(
"id",
2021-09-17 12:10:36 +02:00
"insert into project__inventory (project_id, name, type, ssh_key_id, inventory, become_key_id) values (?, ?, ?, ?, ?, ?)",
inventory.ProjectID,
inventory.Name,
inventory.Type,
inventory.SSHKeyID,
2021-09-17 12:10:36 +02:00
inventory.Inventory,
inventory.BecomeKeyID)
if err != nil {
return
}
newInventory = inventory
newInventory.ID = insertID
return
}