2021-05-07 12:08:34 +02:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ansible-semaphore/semaphore/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func (d *BoltDb) GetInventory(projectID int, inventoryID int) (inventory db.Inventory, err error) {
|
2021-05-13 21:45:54 +02:00
|
|
|
err = d.getObject(projectID, db.InventoryProps, intObjectID(inventoryID), &inventory)
|
2021-05-07 12:08:34 +02:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-05-08 19:25:00 +02:00
|
|
|
if inventory.KeyID != nil {
|
|
|
|
inventory.Key, err = d.GetAccessKey(projectID, *inventory.KeyID)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if inventory.SSHKeyID != nil {
|
|
|
|
inventory.SSHKey, err = d.GetAccessKey(projectID, *inventory.SSHKeyID)
|
|
|
|
}
|
2021-05-07 12:08:34 +02:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) GetInventories(projectID int, params db.RetrieveQueryParams) (inventories []db.Inventory, err error) {
|
2021-05-14 13:47:32 +02:00
|
|
|
err = d.getObjects(projectID, db.InventoryProps, params, nil, &inventories)
|
2021-05-08 22:25:31 +02:00
|
|
|
return
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteInventory(projectID int, inventoryID int) error {
|
2021-05-15 13:27:42 +02:00
|
|
|
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.deleteObject(projectID, db.InventoryProps, intObjectID(inventoryID))
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteInventorySoft(projectID int, inventoryID int) error {
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.deleteObjectSoft(projectID, db.InventoryProps, intObjectID(inventoryID))
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) UpdateInventory(inventory db.Inventory) error {
|
2021-05-13 21:45:54 +02:00
|
|
|
return d.updateObject(inventory.ProjectID, db.InventoryProps, inventory)
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:25:31 +02:00
|
|
|
func (d *BoltDb) CreateInventory(inventory db.Inventory) (db.Inventory, error) {
|
2021-05-13 21:45:54 +02:00
|
|
|
newInventory, err := d.createObject(inventory.ProjectID, db.InventoryProps, inventory)
|
2021-05-08 22:25:31 +02:00
|
|
|
return newInventory.(db.Inventory), err
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|