Skip to content

Commit

Permalink
chore(pkger): refactor name and display name with type
Browse files Browse the repository at this point in the history
  • Loading branch information
jsteenb2 committed Mar 19, 2020
1 parent a5c9305 commit cb99c7f
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 307 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

1. [17232](https://github.com/influxdata/influxdb/pull/17232): Allow dashboards to optionally be displayed in light mode
1. [17273](https://github.com/influxdata/influxdb/pull/17273): Add shell completions command for the influx cli
1. [17353](https://github.com/influxdata/influxdb/pull/17353): Make all pkg resources unique by metadata.name field

### Bug Fixes

Expand Down
157 changes: 37 additions & 120 deletions pkger/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,22 @@ type SummaryVariable struct {
LabelAssociations []SummaryLabel `json:"labelAssociations"`
}

type identity struct {
name *references
displayName *references
}

func (i *identity) Name() string {
if displayName := i.displayName.String(); displayName != "" {
return displayName
}
return i.name.String()
}

func (i *identity) PkgName() string {
return i.name.String()
}

const (
fieldAPIVersion = "apiVersion"
fieldAssociations = "associations"
Expand Down Expand Up @@ -781,11 +797,11 @@ const (
const bucketNameMinLength = 2

type bucket struct {
identity

id influxdb.ID
OrgID influxdb.ID
Description string
name *references
displayName *references
RetentionRules retentionRules
labels sortedLabels

Expand All @@ -806,17 +822,6 @@ func (b *bucket) Labels() []*label {
return b.labels
}

func (b *bucket) Name() string {
if displayName := b.displayName.String(); displayName != "" {
return displayName
}
return b.name.String()
}

func (b *bucket) PkgName() string {
return b.name.String()
}

func (b *bucket) ResourceType() influxdb.ResourceType {
return KindBucket.ResourceType()
}
Expand Down Expand Up @@ -950,11 +955,11 @@ const (
const checkNameMinLength = 1

type check struct {
identity

id influxdb.ID
orgID influxdb.ID
kind checkKind
name *references
displayName *references
description string
every time.Duration
level string
Expand Down Expand Up @@ -988,17 +993,6 @@ func (c *check) Labels() []*label {
return c.labels
}

func (c *check) Name() string {
if displayName := c.displayName.String(); displayName != "" {
return displayName
}
return c.name.String()
}

func (c *check) PkgName() string {
return c.name.String()
}

func (c *check) ResourceType() influxdb.ResourceType {
return KindCheck.ResourceType()
}
Expand Down Expand Up @@ -1251,10 +1245,10 @@ const (
const labelNameMinLength = 2

type label struct {
identity

id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
Color string
Description string
associationMapping
Expand All @@ -1265,17 +1259,6 @@ type label struct {
existing *influxdb.Label
}

func (l *label) Name() string {
if displayName := l.displayName.String(); displayName != "" {
return displayName
}
return l.name.String()
}

func (l *label) PkgName() string {
return l.name.String()
}

func (l *label) ID() influxdb.ID {
if l.existing != nil {
return l.existing.ID
Expand Down Expand Up @@ -1398,11 +1381,11 @@ const (
)

type notificationEndpoint struct {
identity

kind notificationKind
id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
description string
method string
password *references
Expand Down Expand Up @@ -1433,17 +1416,6 @@ func (n *notificationEndpoint) Labels() []*label {
return n.labels
}

func (n *notificationEndpoint) Name() string {
if displayName := n.displayName.String(); displayName != "" {
return displayName
}
return n.name.String()
}

func (n *notificationEndpoint) PkgName() string {
return n.name.String()
}

func (n *notificationEndpoint) ResourceType() influxdb.ResourceType {
return KindNotificationEndpointSlack.ResourceType()
}
Expand Down Expand Up @@ -1616,10 +1588,10 @@ const (
)

type notificationRule struct {
id influxdb.ID
orgID influxdb.ID
name *references
displayName *references
identity

id influxdb.ID
orgID influxdb.ID

channel string
description string
Expand Down Expand Up @@ -1649,17 +1621,6 @@ func (r *notificationRule) Labels() []*label {
return r.labels
}

func (r *notificationRule) Name() string {
if displayName := r.displayName.String(); displayName != "" {
return displayName
}
return r.name.String()
}

func (r *notificationRule) PkgName() string {
return r.name.String()
}

func (r *notificationRule) ResourceType() influxdb.ResourceType {
return KindNotificationRule.ResourceType()
}
Expand Down Expand Up @@ -1871,10 +1832,10 @@ const (
)

type task struct {
identity

id influxdb.ID
orgID influxdb.ID
name *references
displayName *references
cron string
description string
every time.Duration
Expand All @@ -1897,17 +1858,6 @@ func (t *task) Labels() []*label {
return t.labels
}

func (t *task) Name() string {
if displayName := t.displayName.String(); displayName != "" {
return displayName
}
return t.name.String()
}

func (t *task) PkgName() string {
return t.name.String()
}

func (t *task) ResourceType() influxdb.ResourceType {
return KindTask.ResourceType()
}
Expand Down Expand Up @@ -2020,9 +1970,9 @@ const (
)

type telegraf struct {
name *references
displayName *references
config influxdb.TelegrafConfig
identity

config influxdb.TelegrafConfig

labels sortedLabels
}
Expand All @@ -2035,17 +1985,6 @@ func (t *telegraf) Labels() []*label {
return t.labels
}

func (t *telegraf) Name() string {
if displayName := t.displayName.String(); displayName != "" {
return displayName
}
return t.name.String()
}

func (t *telegraf) PkgName() string {
return t.name.String()
}

func (t *telegraf) ResourceType() influxdb.ResourceType {
return KindTelegraf.ResourceType()
}
Expand Down Expand Up @@ -2098,10 +2037,10 @@ const (
)

type variable struct {
identity

id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
Description string
Type string
Query string
Expand Down Expand Up @@ -2129,17 +2068,6 @@ func (v *variable) Labels() []*label {
return v.labels
}

func (v *variable) Name() string {
if displayName := v.displayName.String(); displayName != "" {
return displayName
}
return v.name.String()
}

func (v *variable) PkgName() string {
return v.name.String()
}

func (v *variable) ResourceType() influxdb.ResourceType {
return KindVariable.ResourceType()
}
Expand Down Expand Up @@ -2237,10 +2165,10 @@ const (
const dashboardNameMinLength = 2

type dashboard struct {
identity

id influxdb.ID
OrgID influxdb.ID
name *references
displayName *references
Description string
Charts []chart

Expand All @@ -2255,17 +2183,6 @@ func (d *dashboard) Labels() []*label {
return d.labels
}

func (d *dashboard) Name() string {
if displayName := d.displayName.String(); displayName != "" {
return displayName
}
return d.name.String()
}

func (d *dashboard) PkgName() string {
return d.name.String()
}

func (d *dashboard) ResourceType() influxdb.ResourceType {
return KindDashboard.ResourceType()
}
Expand Down
14 changes: 7 additions & 7 deletions pkger/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ func TestPkg(t *testing.T) {
id: influxdb.ID(2),
OrgID: influxdb.ID(100),
Description: "desc2",
name: &references{val: "name2"},
identity: identity{name: &references{val: "name2"}},
RetentionRules: retentionRules{newRetentionRule(2 * time.Hour)},
},
"buck_1": {
id: influxdb.ID(1),
OrgID: influxdb.ID(100),
name: &references{val: "name1"},
identity: identity{name: &references{val: "name1"}},
Description: "desc1",
RetentionRules: retentionRules{newRetentionRule(time.Hour)},
},
Expand All @@ -51,14 +51,14 @@ func TestPkg(t *testing.T) {
"2": {
id: influxdb.ID(2),
OrgID: influxdb.ID(100),
name: &references{val: "name2"},
identity: identity{name: &references{val: "name2"}},
Description: "desc2",
Color: "blurple",
},
"1": {
id: influxdb.ID(1),
OrgID: influxdb.ID(100),
name: &references{val: "name1"},
identity: identity{name: &references{val: "name1"}},
Description: "desc1",
Color: "peru",
},
Expand All @@ -85,13 +85,13 @@ func TestPkg(t *testing.T) {

t.Run("label mappings returned in asc order by name", func(t *testing.T) {
bucket1 := &bucket{
id: influxdb.ID(20),
name: &references{val: "b1"},
id: influxdb.ID(20),
identity: identity{name: &references{val: "b1"}},
}
label1 := &label{
id: influxdb.ID(2),
OrgID: influxdb.ID(100),
name: &references{val: "name2"},
identity: identity{name: &references{val: "name2"}},
Description: "desc2",
Color: "blurple",
associationMapping: associationMapping{
Expand Down
Loading

0 comments on commit cb99c7f

Please sign in to comment.