diff --git a/models/checks.go b/models/checks.go index d7a91225..7bcda987 100644 --- a/models/checks.go +++ b/models/checks.go @@ -25,7 +25,11 @@ var CheckHealthStatuses = []CheckHealthStatus{ CheckStatusUnhealthy, } -var _ types.ResourceSelectable = Check{} +// Ensure interface compliance +var ( + _ types.ResourceSelectable = Check{} + _ LabelableModel = Check{} +) type Check struct { ID uuid.UUID `json:"id" gorm:"default:generate_ulid()"` @@ -94,6 +98,10 @@ func (c Check) TableName() string { return "checks" } +func (t Check) GetLabels() map[string]string { + return t.Labels +} + func (c Check) ToString() string { return fmt.Sprintf("%s-%s-%s", c.Name, c.Type, c.Description) } diff --git a/models/common.go b/models/common.go index 06a9b4b9..a74ba03e 100644 --- a/models/common.go +++ b/models/common.go @@ -166,3 +166,11 @@ type ABACAttribute struct { Config ConfigItem Check Check } + +type TaggableModel interface { + GetTags() map[string]string +} + +type LabelableModel interface { + GetLabels() map[string]string +} diff --git a/models/components.go b/models/components.go index 3615413b..c061eb8c 100644 --- a/models/components.go +++ b/models/components.go @@ -30,6 +30,12 @@ var AllowedColumnFieldsInComponents = []string{ "type", // Deprecated. Use resource_selector.types instead } +// Ensure interface compliance +var ( + _ types.ResourceSelectable = Component{} + _ LabelableModel = Component{} +) + type Component struct { ID uuid.UUID `json:"id,omitempty" gorm:"default:generate_ulid()"` //nolint TopologyID *uuid.UUID `json:"topology_id,omitempty"` @@ -137,6 +143,10 @@ func (c Component) TableName() string { return "components" } +func (t Component) GetLabels() map[string]string { + return t.Labels +} + func DeleteAllComponents(db *gorm.DB, components ...Component) error { ids := lo.Map(components, func(c Component, _ int) string { return c.ID.String() }) if err := db.Exec("DELETE from component_relationships WHERE component_id in (?) or relationship_id in (?)", ids, ids).Error; err != nil { diff --git a/models/config.go b/models/config.go index edd713f0..3d2f4661 100644 --- a/models/config.go +++ b/models/config.go @@ -81,6 +81,8 @@ const ( var ( _ types.ResourceSelectable = ConfigItem{} _ types.TagsMatchable = ConfigItem{} + _ TaggableModel = ConfigItem{} + _ LabelableModel = ConfigItem{} ) // ConfigItem represents the config item database table @@ -170,6 +172,14 @@ func (ConfigItem) TableName() string { return "config_items" } +func (t ConfigItem) GetTags() map[string]string { + return t.Tags +} + +func (t ConfigItem) GetLabels() map[string]string { + return lo.FromPtr(t.Labels) +} + func (ci *ConfigItem) SetParent(parent *ConfigItem) { ci.ParentID = &parent.ID ci.Path = parent.Path + "." + ci.ID.String()