Skip to content

Commit

Permalink
feat: rename config_type to config_class
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Apr 28, 2023
1 parent 713531d commit e1740e9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 56 deletions.
10 changes: 5 additions & 5 deletions config_type_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,29 @@ var _ = ginkgo.Describe("Check config_type_summary view", ginkgo.Ordered, func()
Expect(configTypeSummaries).To(HaveLen(5))
Expect(configTypeSummaries).To(Equal([]configTypeSummary{
{
configType: models.ConfigTypeCluster,
configType: models.ConfigClassCluster,
totalConfigs: 2,
changes: ptr(2),
},
{
configType: models.ConfigTypeDatabase,
configType: models.ConfigClassDatabase,
totalConfigs: 1,
analysis: map[string]any{
"security": float64(1),
},
},
{
configType: models.ConfigTypeDeployment,
configType: models.ConfigClassDeployment,
totalConfigs: 3,
},
{
configType: models.ConfigTypeNode,
configType: models.ConfigClassNode,
totalConfigs: 2,
changes: ptr(1),
cp30d: ptr(2.5),
},
{
configType: models.ConfigTypeVirtualMachine,
configType: models.ConfigClassVirtualMachine,
totalConfigs: 2,
analysis: map[string]any{
"security": float64(1),
Expand Down
36 changes: 18 additions & 18 deletions fixtures/dummy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,55 +6,55 @@ import (
)

var EKSCluster = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeCluster,
ID: uuid.New(),
ConfigClass: models.ConfigClassCluster,
}

var KubernetesCluster = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeCluster,
ID: uuid.New(),
ConfigClass: models.ConfigClassCluster,
}

var KubernetesNodeA = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeNode,
ConfigClass: models.ConfigClassNode,
CostTotal30d: 1,
}

var KubernetesNodeB = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeNode,
ConfigClass: models.ConfigClassNode,
CostTotal30d: 1.5,
}

var EC2InstanceA = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeVirtualMachine,
ID: uuid.New(),
ConfigClass: models.ConfigClassVirtualMachine,
}

var EC2InstanceB = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeVirtualMachine,
ID: uuid.New(),
ConfigClass: models.ConfigClassVirtualMachine,
}

var LogisticsAPIDeployment = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeDeployment,
ID: uuid.New(),
ConfigClass: models.ConfigClassDeployment,
}

var LogisticsUIDeployment = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeDeployment,
ID: uuid.New(),
ConfigClass: models.ConfigClassDeployment,
}

var LogisticsWorkerDeployment = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeDeployment,
ID: uuid.New(),
ConfigClass: models.ConfigClassDeployment,
}

var LogisticsDBRDS = models.ConfigItem{
ID: uuid.New(),
ConfigType: models.ConfigTypeDatabase,
ID: uuid.New(),
ConfigClass: models.ConfigClassDatabase,
}

var AllDummyConfigs = []models.ConfigItem{
Expand Down
48 changes: 29 additions & 19 deletions models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,41 @@ import (
"gorm.io/gorm/clause"
)

// Config classes
const (
ConfigClassCluster = "Cluster"
ConfigClassDatabase = "Database"
ConfigClassDeployment = "Deployment"
ConfigClassNamespace = "Namespace"
ConfigClassNode = "Node"
ConfigClassPod = "Pod"
ConfigClassVirtualMachine = "VirtualMachine"
)

// ConfigItem represents the config item database table
type ConfigItem struct {
ID uuid.UUID `gorm:"primaryKey;unique_index;not null;column:id" json:"id" faker:"uuid_hyphenated" `
ScraperID *string `gorm:"column:scraper_id;default:null" json:"scraper_id,omitempty" `
ConfigType string `gorm:"column:config_type;default:''" json:"config_type" faker:"oneof: File, EC2Instance, KubernetesPod" `
ExternalID pq.StringArray `gorm:"column:external_id;type:[]text" json:"external_id,omitempty" faker:"external_id" `
ExternalType *string `gorm:"column:external_type;default:null" json:"external_type,omitempty" faker:"oneof: File, EC2Instance, KubernetesPod" `
Name *string `gorm:"column:name;default:null" json:"name,omitempty" faker:"name" `
Namespace *string `gorm:"column:namespace;default:null" json:"namespace,omitempty" faker:"oneof: default, demo, prod, staging" `
Description *string `gorm:"column:description;default:null" json:"description,omitempty" `
Config *string `gorm:"column:config;default:null" json:"config,omitempty" `
Source *string `gorm:"column:source;default:null" json:"source,omitempty" `
ParentID *uuid.UUID `gorm:"column:parent_id;default:null" json:"parent_id,omitempty" faker:"-"`
Path string `gorm:"column:path;default:null" json:"path,omitempty" faker:"-"`
ID uuid.UUID `json:"id" faker:"uuid_hyphenated"`
ScraperID *string `json:"scraper_id,omitempty"`
ConfigClass string `json:"config_class" faker:"oneof:File,EC2Instance,KubernetesPod" `
ExternalID pq.StringArray `json:"external_id,omitempty"`
ExternalType *string `json:"external_type,omitempty"`
Name *string `json:"name,omitempty" faker:"name" `
Namespace *string `json:"namespace,omitempty" faker:"oneof: default, demo, prod, staging" `
Description *string `json:"description,omitempty"`
Config *string `json:"config,omitempty" `
Source *string `json:"source,omitempty" `
ParentID *uuid.UUID `json:"parent_id,omitempty" faker:"-"`
Path string `json:"path,omitempty" faker:"-"`
CostPerMinute float64 `gorm:"column:cost_per_minute;default:null" json:"cost_per_minute,omitempty"`
CostTotal1d float64 `gorm:"column:cost_total_1d;default:null" json:"cost_total_1d,omitempty"`
CostTotal7d float64 `gorm:"column:cost_total_7d;default:null" json:"cost_total_7d,omitempty"`
CostTotal30d float64 `gorm:"column:cost_total_30d;default:null" json:"cost_total_30d,omitempty"`
Tags *types.JSONStringMap `gorm:"column:tags;default:null" json:"tags,omitempty" faker:"tags"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at" `
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" `
Tags *types.JSONStringMap `json:"tags,omitempty" faker:"tags"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}

func (c ConfigItem) TableName() string {
func (ConfigItem) TableName() string {
return "config_items"
}

Expand All @@ -46,7 +57,7 @@ func (ci *ConfigItem) SetParent(parent *ConfigItem) {
}

func (ci ConfigItem) String() string {
return fmt.Sprintf("%s/%s", ci.ConfigType, ci.ID)
return fmt.Sprintf("%s/%s", ci.ConfigClass, ci.ID)
}

func (ci ConfigItem) ConfigJSONStringMap() (map[string]any, error) {
Expand All @@ -57,7 +68,7 @@ func (ci ConfigItem) ConfigJSONStringMap() (map[string]any, error) {

// ConfigScraper represents the config_scrapers database table
type ConfigScraper struct {
ID uuid.UUID `gorm:"primaryKey;unique_index;not null;column:id" json:"id"`
ID uuid.UUID `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Spec string `json:"spec,omitempty"`
Expand All @@ -75,7 +86,6 @@ func (cs *ConfigScraper) BeforeCreate(tx *gorm.DB) error {
if cs.ID == uuid.Nil {
cs.ID = uuid.New()
}

return nil
}

Expand Down
12 changes: 0 additions & 12 deletions models/config_items.go

This file was deleted.

4 changes: 2 additions & 2 deletions schema/config.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ table "config_items" {
null = true
type = uuid
}
column "config_type" {
column "config_class" {
null = false
type = text
}
column "external_id" {
null = true
type = sql("text[]")
}
column "external_type" {
column "config_type" {
null = true
type = text
}
Expand Down

0 comments on commit e1740e9

Please sign in to comment.