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-09 22:08:10 +02:00
|
|
|
err = d.getObject(projectID, db.InventoryObject, 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-08 22:25:31 +02:00
|
|
|
err = d.getObjects(projectID, db.AccessKeyObject, params, &inventories)
|
|
|
|
return
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteInventory(projectID int, inventoryID int) error {
|
2021-05-09 22:08:10 +02:00
|
|
|
return d.deleteObject(projectID, db.InventoryObject, intObjectID(inventoryID))
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) DeleteInventorySoft(projectID int, inventoryID int) error {
|
2021-05-09 22:08:10 +02:00
|
|
|
return d.deleteObjectSoft(projectID, db.InventoryObject, intObjectID(inventoryID))
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (d *BoltDb) UpdateInventory(inventory db.Inventory) error {
|
2021-05-08 22:25:31 +02:00
|
|
|
return d.updateObject(inventory.ProjectID, db.InventoryObject, 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) {
|
|
|
|
newInventory, err := d.createObject(inventory.ProjectID, db.InventoryObject, inventory)
|
|
|
|
return newInventory.(db.Inventory), err
|
2021-05-07 12:08:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|