fix(label): add organizationID to labels
parent
243f1ea511
commit
950e496748
|
@ -1638,7 +1638,7 @@ paths:
|
|||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/Label"
|
||||
$ref: "#/components/schemas/LabelCreateRequest"
|
||||
responses:
|
||||
'201':
|
||||
description: Added label
|
||||
|
@ -7693,6 +7693,22 @@ components:
|
|||
id:
|
||||
readOnly: true
|
||||
type: string
|
||||
orgID:
|
||||
readOnly: true
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
properties:
|
||||
type: object
|
||||
additionalProperties:
|
||||
type: string
|
||||
description: Key/Value pairs associated with this label. Keys can be removed by sending an update with an empty value.
|
||||
example: {"color": "ffb3b3", "description": "this is a description"}
|
||||
LabelCreateRequest:
|
||||
type: object
|
||||
properties:
|
||||
orgID:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
properties:
|
||||
|
|
17
label.go
17
label.go
|
@ -47,9 +47,10 @@ type LabelService interface {
|
|||
|
||||
// Label is a tag set on a resource, typically used for filtering on a UI.
|
||||
type Label struct {
|
||||
ID ID `json:"id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Properties map[string]string `json:"properties,omitempty"`
|
||||
ID ID `json:"id,omitempty"`
|
||||
OrganizationID ID `json:"orgID,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Properties map[string]string `json:"properties,omitempty"`
|
||||
}
|
||||
|
||||
// Validate returns an error if the label is invalid.
|
||||
|
@ -61,6 +62,13 @@ func (l *Label) Validate() error {
|
|||
}
|
||||
}
|
||||
|
||||
if l.OrganizationID == 0 {
|
||||
return &Error{
|
||||
Code: EInvalid,
|
||||
Msg: "organization ID is required",
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -105,7 +113,8 @@ type LabelUpdate struct {
|
|||
|
||||
// LabelFilter represents a set of filters that restrict the returned results.
|
||||
type LabelFilter struct {
|
||||
Name string
|
||||
Name string
|
||||
OrgID *ID
|
||||
}
|
||||
|
||||
// LabelMappingFilter represents a set of filters that restrict the returned results.
|
||||
|
|
|
@ -3,13 +3,19 @@ package influxdb_test
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/influxdb"
|
||||
platform "github.com/influxdata/influxdb"
|
||||
influxtest "github.com/influxdata/influxdb/testing"
|
||||
)
|
||||
|
||||
const (
|
||||
orgOneID = "020f755c3c083000"
|
||||
)
|
||||
|
||||
func TestLabelValidate(t *testing.T) {
|
||||
type fields struct {
|
||||
ResourceID platform.ID
|
||||
Name string
|
||||
Name string
|
||||
OrgID influxdb.ID
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -19,19 +25,30 @@ func TestLabelValidate(t *testing.T) {
|
|||
{
|
||||
name: "valid label",
|
||||
fields: fields{
|
||||
Name: "iot",
|
||||
Name: "iot",
|
||||
OrgID: influxtest.MustIDBase16(orgOneID),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "label requires a name",
|
||||
fields: fields{},
|
||||
name: "label requires a name",
|
||||
fields: fields{
|
||||
OrgID: influxtest.MustIDBase16(orgOneID),
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "label requires an organization ID",
|
||||
fields: fields{
|
||||
Name: "iot",
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := platform.Label{
|
||||
Name: tt.fields.Name,
|
||||
Name: tt.fields.Name,
|
||||
OrganizationID: tt.fields.OrgID,
|
||||
}
|
||||
if err := m.Validate(); (err != nil) != tt.wantErr {
|
||||
t.Errorf("Label.Validate() error = %v, wantErr %v", err, tt.wantErr)
|
||||
|
|
|
@ -345,8 +345,9 @@ func UpdateLabel(
|
|||
fields: LabelFields{
|
||||
Labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -359,8 +360,9 @@ func UpdateLabel(
|
|||
wants: wants{
|
||||
labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "NotTag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "NotTag1",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -370,8 +372,9 @@ func UpdateLabel(
|
|||
fields: LabelFields{
|
||||
Labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -386,8 +389,9 @@ func UpdateLabel(
|
|||
wants: wants{
|
||||
labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
Properties: map[string]string{
|
||||
"color": "fff000",
|
||||
},
|
||||
|
@ -400,8 +404,9 @@ func UpdateLabel(
|
|||
fields: LabelFields{
|
||||
Labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
Properties: map[string]string{
|
||||
"color": "fff000",
|
||||
"description": "description",
|
||||
|
@ -420,8 +425,9 @@ func UpdateLabel(
|
|||
wants: wants{
|
||||
labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
Properties: map[string]string{
|
||||
"color": "abc123",
|
||||
"description": "description",
|
||||
|
@ -435,8 +441,9 @@ func UpdateLabel(
|
|||
fields: LabelFields{
|
||||
Labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
Properties: map[string]string{
|
||||
"color": "fff000",
|
||||
"description": "description",
|
||||
|
@ -455,8 +462,9 @@ func UpdateLabel(
|
|||
wants: wants{
|
||||
labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
Properties: map[string]string{
|
||||
"color": "fff000",
|
||||
},
|
||||
|
@ -530,12 +538,14 @@ func DeleteLabel(
|
|||
fields: LabelFields{
|
||||
Labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
},
|
||||
{
|
||||
ID: MustIDBase16(labelTwoID),
|
||||
Name: "Tag2",
|
||||
ID: MustIDBase16(labelTwoID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag2",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -545,8 +555,9 @@ func DeleteLabel(
|
|||
wants: wants{
|
||||
labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelTwoID),
|
||||
Name: "Tag2",
|
||||
ID: MustIDBase16(labelTwoID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag2",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -556,8 +567,9 @@ func DeleteLabel(
|
|||
fields: LabelFields{
|
||||
Labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -567,8 +579,9 @@ func DeleteLabel(
|
|||
wants: wants{
|
||||
labels: []*influxdb.Label{
|
||||
{
|
||||
ID: MustIDBase16(labelOneID),
|
||||
Name: "Tag1",
|
||||
ID: MustIDBase16(labelOneID),
|
||||
OrganizationID: MustIDBase16(orgOneID),
|
||||
Name: "Tag1",
|
||||
},
|
||||
},
|
||||
err: &influxdb.Error{
|
||||
|
|
Loading…
Reference in New Issue