/
applicationInventory.go
68 lines (61 loc) · 1.59 KB
/
applicationInventory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package models
import (
"github.com/jinzhu/gorm"
)
type ApplicationInventory struct {
gorm.Model
IsActive bool
Application Application
ApplicationID uint
Inventory Inventory
InventoryID uint
Name string `gorm:"type:text"`
ApplicationUrls string `gorm:"type:text"`
ExtraVariables string `gorm:"type:text"`
Playbook string `gorm:"type:text"`
Key SshKey
KeyID uint
VaultKey SshKey
VaultKeyID uint
}
func GetApplicationInventories() ([]*ApplicationInventory, error) {
applicationInventories := make([]*ApplicationInventory, 0)
err := GetDB().
Order("id asc").
Preload("Application").
Preload("Inventory").
Find(&applicationInventories).Error
if err != nil {
return nil, err
}
return applicationInventories, nil
}
func GetApplicationInventory(id uint) *ApplicationInventory {
var applicationInventory ApplicationInventory
err := GetDB().Preload("Application").Preload("Inventory").First(&applicationInventory, id).Error
if err != nil {
return nil
}
return &applicationInventory
}
func SaveApplicationInventory(applicationInventory *ApplicationInventory) error {
if GetDB().NewRecord(applicationInventory) {
err := GetDB().Create(applicationInventory).Error
if err != nil {
return err
}
} else {
err := GetDB().Omit("created_at").Save(applicationInventory).Error
if err != nil {
return err
}
}
return nil
}
func DeleteApplicationInventory(applicationInventory *ApplicationInventory) error {
err := GetDB().Delete(applicationInventory).Error
if err != nil {
return err
}
return nil
}