Merge pull request #13315 from influxdata/filter-label-org

feat(http): filter label response by organization
pull/13351/head
Jade McGough 2019-04-12 02:07:33 -07:00 committed by GitHub
commit b5f6effda4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 267 additions and 301 deletions

View File

@ -87,7 +87,7 @@ func (s *LabelService) FindLabelByID(ctx context.Context, id influxdb.ID) (*infl
return nil, err return nil, err
} }
if err := authorizeReadLabel(ctx, l.OrganizationID, id); err != nil { if err := authorizeReadLabel(ctx, l.OrgID, id); err != nil {
return nil, err return nil, err
} }
@ -107,7 +107,7 @@ func (s *LabelService) FindLabels(ctx context.Context, filter influxdb.LabelFilt
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating // https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
labels := ls[:0] labels := ls[:0]
for _, l := range ls { for _, l := range ls {
err := authorizeReadLabel(ctx, l.OrganizationID, l.ID) err := authorizeReadLabel(ctx, l.OrgID, l.ID)
if err != nil && if err != nil &&
influxdb.ErrorCode(err) != influxdb.EUnauthorized && influxdb.ErrorCode(err) != influxdb.EUnauthorized &&
influxdb.ErrorCode(err) != influxdb.EInvalid { influxdb.ErrorCode(err) != influxdb.EInvalid {
@ -139,7 +139,7 @@ func (s *LabelService) FindResourceLabels(ctx context.Context, filter influxdb.L
labels := ls[:0] labels := ls[:0]
for _, l := range ls { for _, l := range ls {
err := authorizeReadLabel(ctx, l.OrganizationID, l.ID) err := authorizeReadLabel(ctx, l.OrgID, l.ID)
if err != nil && influxdb.ErrorCode(err) != influxdb.EUnauthorized { if err != nil && influxdb.ErrorCode(err) != influxdb.EUnauthorized {
return nil, err return nil, err
} }
@ -156,7 +156,7 @@ func (s *LabelService) FindResourceLabels(ctx context.Context, filter influxdb.L
// CreateLabel checks to see if the authorizer on context has read access to the new label's org. // CreateLabel checks to see if the authorizer on context has read access to the new label's org.
func (s *LabelService) CreateLabel(ctx context.Context, l *influxdb.Label) error { func (s *LabelService) CreateLabel(ctx context.Context, l *influxdb.Label) error {
if err := authorizeReadOrg(ctx, l.OrganizationID); err != nil { if err := authorizeReadOrg(ctx, l.OrgID); err != nil {
return err return err
} }
@ -170,7 +170,7 @@ func (s *LabelService) CreateLabelMapping(ctx context.Context, m *influxdb.Label
return err return err
} }
if err := authorizeWriteLabel(ctx, l.OrganizationID, m.LabelID); err != nil { if err := authorizeWriteLabel(ctx, l.OrgID, m.LabelID); err != nil {
return err return err
} }
@ -188,7 +188,7 @@ func (s *LabelService) UpdateLabel(ctx context.Context, id influxdb.ID, upd infl
return nil, err return nil, err
} }
if err := authorizeWriteLabel(ctx, l.OrganizationID, id); err != nil { if err := authorizeWriteLabel(ctx, l.OrgID, id); err != nil {
return nil, err return nil, err
} }
@ -202,7 +202,7 @@ func (s *LabelService) DeleteLabel(ctx context.Context, id influxdb.ID) error {
return err return err
} }
if err := authorizeWriteLabel(ctx, l.OrganizationID, id); err != nil { if err := authorizeWriteLabel(ctx, l.OrgID, id); err != nil {
return err return err
} }
@ -216,7 +216,7 @@ func (s *LabelService) DeleteLabelMapping(ctx context.Context, m *influxdb.Label
return err return err
} }
if err := authorizeWriteLabel(ctx, l.OrganizationID, m.LabelID); err != nil { if err := authorizeWriteLabel(ctx, l.OrgID, m.LabelID); err != nil {
return err return err
} }

View File

@ -55,8 +55,8 @@ func TestLabelService_FindLabelByID(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: id, ID: id,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
}, },
@ -81,8 +81,8 @@ func TestLabelService_FindLabelByID(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: id, ID: id,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
}, },
@ -144,16 +144,16 @@ func TestLabelService_FindLabels(t *testing.T) {
FindLabelsFn: func(ctx context.Context, filter influxdb.LabelFilter) ([]*influxdb.Label, error) { FindLabelsFn: func(ctx context.Context, filter influxdb.LabelFilter) ([]*influxdb.Label, error) {
return []*influxdb.Label{ return []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, nil }, nil
}, },
@ -170,16 +170,16 @@ func TestLabelService_FindLabels(t *testing.T) {
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, },
}, },
@ -191,16 +191,16 @@ func TestLabelService_FindLabels(t *testing.T) {
FindLabelsFn: func(ctx context.Context, filter influxdb.LabelFilter) ([]*influxdb.Label, error) { FindLabelsFn: func(ctx context.Context, filter influxdb.LabelFilter) ([]*influxdb.Label, error) {
return []*influxdb.Label{ return []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, nil }, nil
}, },
@ -218,8 +218,8 @@ func TestLabelService_FindLabels(t *testing.T) {
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, },
}, },
@ -231,16 +231,16 @@ func TestLabelService_FindLabels(t *testing.T) {
FindLabelsFn: func(ctx context.Context, filter influxdb.LabelFilter) ([]*influxdb.Label, error) { FindLabelsFn: func(ctx context.Context, filter influxdb.LabelFilter) ([]*influxdb.Label, error) {
return []*influxdb.Label{ return []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, nil }, nil
}, },
@ -302,14 +302,14 @@ func TestLabelService_UpdateLabel(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
UpdateLabelFn: func(ctx context.Context, id influxdb.ID, upd influxdb.LabelUpdate) (*influxdb.Label, error) { UpdateLabelFn: func(ctx context.Context, id influxdb.ID, upd influxdb.LabelUpdate) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
}, },
@ -336,14 +336,14 @@ func TestLabelService_UpdateLabel(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
UpdateLabelFn: func(ctx context.Context, id influxdb.ID, upd influxdb.LabelUpdate) (*influxdb.Label, error) { UpdateLabelFn: func(ctx context.Context, id influxdb.ID, upd influxdb.LabelUpdate) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
}, },
@ -406,8 +406,8 @@ func TestLabelService_DeleteLabel(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
DeleteLabelFn: func(ctx context.Context, id influxdb.ID) error { DeleteLabelFn: func(ctx context.Context, id influxdb.ID) error {
@ -438,8 +438,8 @@ func TestLabelService_DeleteLabel(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
DeleteLabelFn: func(ctx context.Context, id influxdb.ID) error { DeleteLabelFn: func(ctx context.Context, id influxdb.ID) error {
@ -554,7 +554,7 @@ func TestLabelService_CreateLabel(t *testing.T) {
ctx := context.Background() ctx := context.Background()
ctx = influxdbcontext.SetAuthorizer(ctx, &Authorizer{[]influxdb.Permission{tt.args.permission}}) ctx = influxdbcontext.SetAuthorizer(ctx, &Authorizer{[]influxdb.Permission{tt.args.permission}})
err := s.CreateLabel(ctx, &influxdb.Label{Name: "name", OrganizationID: influxdbtesting.MustIDBase16(orgOneID)}) err := s.CreateLabel(ctx, &influxdb.Label{Name: "name", OrgID: influxdbtesting.MustIDBase16(orgOneID)})
influxdbtesting.ErrorsEqual(t, err, tt.wants.err) influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
}) })
} }
@ -585,16 +585,16 @@ func TestLabelService_FindResourceLabels(t *testing.T) {
FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) { FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) {
return []*influxdb.Label{ return []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, nil }, nil
}, },
@ -625,16 +625,16 @@ func TestLabelService_FindResourceLabels(t *testing.T) {
err: nil, err: nil,
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, },
}, },
@ -646,16 +646,16 @@ func TestLabelService_FindResourceLabels(t *testing.T) {
FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) { FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) {
return []*influxdb.Label{ return []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, nil }, nil
}, },
@ -687,8 +687,8 @@ func TestLabelService_FindResourceLabels(t *testing.T) {
err: nil, err: nil,
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, },
}, },
@ -700,16 +700,16 @@ func TestLabelService_FindResourceLabels(t *testing.T) {
FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) { FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) {
return []*influxdb.Label{ return []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, nil }, nil
}, },
@ -741,16 +741,16 @@ func TestLabelService_FindResourceLabels(t *testing.T) {
FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) { FindResourceLabelsFn: func(ctx context.Context, f influxdb.LabelMappingFilter) ([]*influxdb.Label, error) {
return []*influxdb.Label{ return []*influxdb.Label{
{ {
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 2, ID: 2,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
{ {
ID: 3, ID: 3,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, },
}, nil }, nil
}, },
@ -820,8 +820,8 @@ func TestLabelService_CreateLabelMapping(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
CreateLabelMappingFn: func(ctx context.Context, lm *influxdb.LabelMapping) error { CreateLabelMappingFn: func(ctx context.Context, lm *influxdb.LabelMapping) error {
@ -861,8 +861,8 @@ func TestLabelService_CreateLabelMapping(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
CreateLabelMappingFn: func(ctx context.Context, lm *influxdb.LabelMapping) error { CreateLabelMappingFn: func(ctx context.Context, lm *influxdb.LabelMapping) error {
@ -898,8 +898,8 @@ func TestLabelService_CreateLabelMapping(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
CreateLabelMappingFn: func(ctx context.Context, lm *influxdb.LabelMapping) error { CreateLabelMappingFn: func(ctx context.Context, lm *influxdb.LabelMapping) error {
@ -968,8 +968,8 @@ func TestLabelService_DeleteLabelMapping(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
DeleteLabelMappingFn: func(ctx context.Context, m *influxdb.LabelMapping) error { DeleteLabelMappingFn: func(ctx context.Context, m *influxdb.LabelMapping) error {
@ -1009,8 +1009,8 @@ func TestLabelService_DeleteLabelMapping(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
DeleteLabelMappingFn: func(ctx context.Context, m *influxdb.LabelMapping) error { DeleteLabelMappingFn: func(ctx context.Context, m *influxdb.LabelMapping) error {
@ -1046,8 +1046,8 @@ func TestLabelService_DeleteLabelMapping(t *testing.T) {
LabelService: &mock.LabelService{ LabelService: &mock.LabelService{
FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) { FindLabelByIDFn: func(ctc context.Context, id influxdb.ID) (*influxdb.Label, error) {
return &influxdb.Label{ return &influxdb.Label{
ID: 1, ID: 1,
OrganizationID: influxdbtesting.MustIDBase16(orgOneID), OrgID: influxdbtesting.MustIDBase16(orgOneID),
}, nil }, nil
}, },
DeleteLabelMappingFn: func(ctx context.Context, m *influxdb.LabelMapping) error { DeleteLabelMappingFn: func(ctx context.Context, m *influxdb.LabelMapping) error {

View File

@ -1,44 +0,0 @@
package bolt_test
import (
"context"
"testing"
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/bolt"
platformtesting "github.com/influxdata/influxdb/testing"
)
func initLabelService(f platformtesting.LabelFields, t *testing.T) (platform.LabelService, string, func()) {
c, closeFn, err := NewTestClient()
if err != nil {
t.Fatalf("failed to create new bolt client: %v", err)
}
c.IDGenerator = f.IDGenerator
ctx := context.Background()
for _, l := range f.Labels {
if err := c.PutLabel(ctx, l); err != nil {
t.Fatalf("failed to populate labels: %v", err)
}
}
for _, m := range f.Mappings {
if err := c.PutLabelMapping(ctx, m); err != nil {
t.Fatalf("failed to populate label mappings: %v", err)
}
}
return c, bolt.OpPrefix, func() {
defer closeFn()
for _, l := range f.Labels {
if err := c.DeleteLabel(ctx, l.ID); err != nil {
t.Logf("failed to remove label: %v", err)
}
}
}
}
func TestLabelService_LabelService(t *testing.T) {
platformtesting.LabelService(initLabelService, t)
}

View File

@ -10,7 +10,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
platform "github.com/influxdata/influxdb" influxdb "github.com/influxdata/influxdb"
"github.com/julienschmidt/httprouter" "github.com/julienschmidt/httprouter"
) )
@ -20,7 +20,7 @@ type LabelHandler struct {
Logger *zap.Logger Logger *zap.Logger
LabelService platform.LabelService LabelService influxdb.LabelService
} }
const ( const (
@ -29,7 +29,7 @@ const (
) )
// NewLabelHandler returns a new instance of LabelHandler // NewLabelHandler returns a new instance of LabelHandler
func NewLabelHandler(s platform.LabelService) *LabelHandler { func NewLabelHandler(s influxdb.LabelService) *LabelHandler {
h := &LabelHandler{ h := &LabelHandler{
Router: NewRouter(), Router: NewRouter(),
Logger: zap.NewNop(), Logger: zap.NewNop(),
@ -68,19 +68,19 @@ func (h *LabelHandler) handlePostLabel(w http.ResponseWriter, r *http.Request) {
} }
type postLabelRequest struct { type postLabelRequest struct {
Label *platform.Label Label *influxdb.Label
} }
func (b postLabelRequest) Validate() error { func (b postLabelRequest) Validate() error {
if b.Label.Name == "" { if b.Label.Name == "" {
return &platform.Error{ return &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "label requires a name", Msg: "label requires a name",
} }
} }
if !b.Label.OrganizationID.Valid() { if !b.Label.OrgID.Valid() {
return &platform.Error{ return &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "label requires a valid orgID", Msg: "label requires a valid orgID",
} }
} }
@ -89,10 +89,10 @@ func (b postLabelRequest) Validate() error {
// TODO(jm): ensure that the specified org actually exists // TODO(jm): ensure that the specified org actually exists
func decodePostLabelRequest(ctx context.Context, r *http.Request) (*postLabelRequest, error) { func decodePostLabelRequest(ctx context.Context, r *http.Request) (*postLabelRequest, error) {
l := &platform.Label{} l := &influxdb.Label{}
if err := json.NewDecoder(r.Body).Decode(l); err != nil { if err := json.NewDecoder(r.Body).Decode(l); err != nil {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "unable to decode label request", Msg: "unable to decode label request",
Err: err, Err: err,
} }
@ -109,7 +109,13 @@ func decodePostLabelRequest(ctx context.Context, r *http.Request) (*postLabelReq
func (h *LabelHandler) handleGetLabels(w http.ResponseWriter, r *http.Request) { func (h *LabelHandler) handleGetLabels(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
labels, err := h.LabelService.FindLabels(ctx, platform.LabelFilter{}) req, err := decodeGetLabelsRequest(ctx, r)
if err != nil {
EncodeError(ctx, err, w)
return
}
labels, err := h.LabelService.FindLabels(ctx, req.filter)
if err != nil { if err != nil {
EncodeError(ctx, err, w) EncodeError(ctx, err, w)
return return
@ -122,6 +128,25 @@ func (h *LabelHandler) handleGetLabels(w http.ResponseWriter, r *http.Request) {
} }
} }
type getLabelsRequest struct {
filter influxdb.LabelFilter
}
func decodeGetLabelsRequest(ctx context.Context, r *http.Request) (*getLabelsRequest, error) {
qp := r.URL.Query()
req := &getLabelsRequest{}
if orgID := qp.Get("orgID"); orgID != "" {
id, err := influxdb.IDFromString(orgID)
if err != nil {
return nil, err
}
req.filter.OrgID = id
}
return req, nil
}
// handleGetLabel is the HTTP handler for the GET /api/v2/labels/id route. // handleGetLabel is the HTTP handler for the GET /api/v2/labels/id route.
func (h *LabelHandler) handleGetLabel(w http.ResponseWriter, r *http.Request) { func (h *LabelHandler) handleGetLabel(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
@ -145,20 +170,20 @@ func (h *LabelHandler) handleGetLabel(w http.ResponseWriter, r *http.Request) {
} }
type getLabelRequest struct { type getLabelRequest struct {
LabelID platform.ID LabelID influxdb.ID
} }
func decodeGetLabelRequest(ctx context.Context, r *http.Request) (*getLabelRequest, error) { func decodeGetLabelRequest(ctx context.Context, r *http.Request) (*getLabelRequest, error) {
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "label id is not valid", Msg: "label id is not valid",
} }
} }
var i platform.ID var i influxdb.ID
if err := i.DecodeFromString(id); err != nil { if err := i.DecodeFromString(id); err != nil {
return nil, err return nil, err
} }
@ -188,20 +213,20 @@ func (h *LabelHandler) handleDeleteLabel(w http.ResponseWriter, r *http.Request)
} }
type deleteLabelRequest struct { type deleteLabelRequest struct {
LabelID platform.ID LabelID influxdb.ID
} }
func decodeDeleteLabelRequest(ctx context.Context, r *http.Request) (*deleteLabelRequest, error) { func decodeDeleteLabelRequest(ctx context.Context, r *http.Request) (*deleteLabelRequest, error) {
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "url missing id", Msg: "url missing id",
} }
} }
var i platform.ID var i influxdb.ID
if err := i.DecodeFromString(id); err != nil { if err := i.DecodeFromString(id); err != nil {
return nil, err return nil, err
} }
@ -235,26 +260,26 @@ func (h *LabelHandler) handlePatchLabel(w http.ResponseWriter, r *http.Request)
} }
type patchLabelRequest struct { type patchLabelRequest struct {
Update platform.LabelUpdate Update influxdb.LabelUpdate
LabelID platform.ID LabelID influxdb.ID
} }
func decodePatchLabelRequest(ctx context.Context, r *http.Request) (*patchLabelRequest, error) { func decodePatchLabelRequest(ctx context.Context, r *http.Request) (*patchLabelRequest, error) {
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "url missing id", Msg: "url missing id",
} }
} }
var i platform.ID var i influxdb.ID
if err := i.DecodeFromString(id); err != nil { if err := i.DecodeFromString(id); err != nil {
return nil, err return nil, err
} }
upd := &platform.LabelUpdate{} upd := &influxdb.LabelUpdate{}
if err := json.NewDecoder(r.Body).Decode(upd); err != nil { if err := json.NewDecoder(r.Body).Decode(upd); err != nil {
return nil, err return nil, err
} }
@ -276,10 +301,10 @@ type LabelService struct {
type labelResponse struct { type labelResponse struct {
Links map[string]string `json:"links"` Links map[string]string `json:"links"`
Label platform.Label `json:"label"` Label influxdb.Label `json:"label"`
} }
func newLabelResponse(l *platform.Label) *labelResponse { func newLabelResponse(l *influxdb.Label) *labelResponse {
return &labelResponse{ return &labelResponse{
Links: map[string]string{ Links: map[string]string{
"self": fmt.Sprintf("/api/v2/labels/%s", l.ID), "self": fmt.Sprintf("/api/v2/labels/%s", l.ID),
@ -290,10 +315,10 @@ func newLabelResponse(l *platform.Label) *labelResponse {
type labelsResponse struct { type labelsResponse struct {
Links map[string]string `json:"links"` Links map[string]string `json:"links"`
Labels []*platform.Label `json:"labels"` Labels []*influxdb.Label `json:"labels"`
} }
func newLabelsResponse(ls []*platform.Label) *labelsResponse { func newLabelsResponse(ls []*influxdb.Label) *labelsResponse {
return &labelsResponse{ return &labelsResponse{
Links: map[string]string{ Links: map[string]string{
"self": fmt.Sprintf("/api/v2/labels"), "self": fmt.Sprintf("/api/v2/labels"),
@ -306,8 +331,8 @@ func newLabelsResponse(ls []*platform.Label) *labelsResponse {
// label handlers. // label handlers.
type LabelBackend struct { type LabelBackend struct {
Logger *zap.Logger Logger *zap.Logger
LabelService platform.LabelService LabelService influxdb.LabelService
ResourceType platform.ResourceType ResourceType influxdb.ResourceType
} }
// newGetLabelsHandler returns a handler func for a GET to /labels endpoints // newGetLabelsHandler returns a handler func for a GET to /labels endpoints
@ -315,7 +340,7 @@ func newGetLabelsHandler(b *LabelBackend) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context() ctx := r.Context()
req, err := decodeGetLabelsRequest(ctx, r, b.ResourceType) req, err := decodeGetLabelMappingsRequest(ctx, r, b.ResourceType)
if err != nil { if err != nil {
EncodeError(ctx, err, w) EncodeError(ctx, err, w)
return return
@ -334,23 +359,23 @@ func newGetLabelsHandler(b *LabelBackend) http.HandlerFunc {
} }
} }
type getLabelsRequest struct { type getLabelMappingsRequest struct {
filter platform.LabelMappingFilter filter influxdb.LabelMappingFilter
} }
func decodeGetLabelsRequest(ctx context.Context, r *http.Request, rt platform.ResourceType) (*getLabelsRequest, error) { func decodeGetLabelMappingsRequest(ctx context.Context, r *http.Request, rt influxdb.ResourceType) (*getLabelMappingsRequest, error) {
req := &getLabelsRequest{} req := &getLabelMappingsRequest{}
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "url missing id", Msg: "url missing id",
} }
} }
var i platform.ID var i influxdb.ID
if err := i.DecodeFromString(id); err != nil { if err := i.DecodeFromString(id); err != nil {
return nil, err return nil, err
} }
@ -395,28 +420,28 @@ func newPostLabelHandler(b *LabelBackend) http.HandlerFunc {
} }
type postLabelMappingRequest struct { type postLabelMappingRequest struct {
Mapping platform.LabelMapping Mapping influxdb.LabelMapping
} }
func decodePostLabelMappingRequest(ctx context.Context, r *http.Request, rt platform.ResourceType) (*postLabelMappingRequest, error) { func decodePostLabelMappingRequest(ctx context.Context, r *http.Request, rt influxdb.ResourceType) (*postLabelMappingRequest, error) {
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "url missing id", Msg: "url missing id",
} }
} }
var rid platform.ID var rid influxdb.ID
if err := rid.DecodeFromString(id); err != nil { if err := rid.DecodeFromString(id); err != nil {
return nil, err return nil, err
} }
mapping := &platform.LabelMapping{} mapping := &influxdb.LabelMapping{}
if err := json.NewDecoder(r.Body).Decode(mapping); err != nil { if err := json.NewDecoder(r.Body).Decode(mapping); err != nil {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "Invalid post label map request", Msg: "Invalid post label map request",
} }
} }
@ -446,7 +471,7 @@ func newDeleteLabelHandler(b *LabelBackend) http.HandlerFunc {
return return
} }
mapping := &platform.LabelMapping{ mapping := &influxdb.LabelMapping{
LabelID: req.LabelID, LabelID: req.LabelID,
ResourceID: req.ResourceID, ResourceID: req.ResourceID,
ResourceType: b.ResourceType, ResourceType: b.ResourceType,
@ -462,34 +487,34 @@ func newDeleteLabelHandler(b *LabelBackend) http.HandlerFunc {
} }
type deleteLabelMappingRequest struct { type deleteLabelMappingRequest struct {
ResourceID platform.ID ResourceID influxdb.ID
LabelID platform.ID LabelID influxdb.ID
} }
func decodeDeleteLabelMappingRequest(ctx context.Context, r *http.Request) (*deleteLabelMappingRequest, error) { func decodeDeleteLabelMappingRequest(ctx context.Context, r *http.Request) (*deleteLabelMappingRequest, error) {
params := httprouter.ParamsFromContext(ctx) params := httprouter.ParamsFromContext(ctx)
id := params.ByName("id") id := params.ByName("id")
if id == "" { if id == "" {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "url missing resource id", Msg: "url missing resource id",
} }
} }
var rid platform.ID var rid influxdb.ID
if err := rid.DecodeFromString(id); err != nil { if err := rid.DecodeFromString(id); err != nil {
return nil, err return nil, err
} }
id = params.ByName("lid") id = params.ByName("lid")
if id == "" { if id == "" {
return nil, &platform.Error{ return nil, &influxdb.Error{
Code: platform.EInvalid, Code: influxdb.EInvalid,
Msg: "label id is missing", Msg: "label id is missing",
} }
} }
var lid platform.ID var lid influxdb.ID
if err := lid.DecodeFromString(id); err != nil { if err := lid.DecodeFromString(id); err != nil {
return nil, err return nil, err
} }
@ -500,12 +525,12 @@ func decodeDeleteLabelMappingRequest(ctx context.Context, r *http.Request) (*del
}, nil }, nil
} }
func labelIDPath(id platform.ID) string { func labelIDPath(id influxdb.ID) string {
return path.Join(labelsPath, id.String()) return path.Join(labelsPath, id.String())
} }
// FindLabelByID returns a single label by ID. // FindLabelByID returns a single label by ID.
func (s *LabelService) FindLabelByID(ctx context.Context, id platform.ID) (*platform.Label, error) { func (s *LabelService) FindLabelByID(ctx context.Context, id influxdb.ID) (*influxdb.Label, error) {
u, err := newURL(s.Addr, labelIDPath(id)) u, err := newURL(s.Addr, labelIDPath(id))
if err != nil { if err != nil {
return nil, err return nil, err
@ -535,12 +560,12 @@ func (s *LabelService) FindLabelByID(ctx context.Context, id platform.ID) (*plat
return &lr.Label, nil return &lr.Label, nil
} }
func (s *LabelService) FindLabels(ctx context.Context, filter platform.LabelFilter, opt ...platform.FindOptions) ([]*platform.Label, error) { func (s *LabelService) FindLabels(ctx context.Context, filter influxdb.LabelFilter, opt ...influxdb.FindOptions) ([]*influxdb.Label, error) {
return nil, nil return nil, nil
} }
// FindResourceLabels returns a list of labels, derived from a label mapping filter. // FindResourceLabels returns a list of labels, derived from a label mapping filter.
func (s *LabelService) FindResourceLabels(ctx context.Context, filter platform.LabelMappingFilter) ([]*platform.Label, error) { func (s *LabelService) FindResourceLabels(ctx context.Context, filter influxdb.LabelMappingFilter) ([]*influxdb.Label, error) {
url, err := newURL(s.Addr, resourceIDPath(s.BasePath, filter.ResourceID)) url, err := newURL(s.Addr, resourceIDPath(s.BasePath, filter.ResourceID))
if err != nil { if err != nil {
return nil, err return nil, err
@ -574,7 +599,7 @@ func (s *LabelService) FindResourceLabels(ctx context.Context, filter platform.L
} }
// CreateLabel creates a new label. // CreateLabel creates a new label.
func (s *LabelService) CreateLabel(ctx context.Context, l *platform.Label) error { func (s *LabelService) CreateLabel(ctx context.Context, l *influxdb.Label) error {
u, err := newURL(s.Addr, labelsPath) u, err := newURL(s.Addr, labelsPath)
if err != nil { if err != nil {
return err return err
@ -614,7 +639,7 @@ func (s *LabelService) CreateLabel(ctx context.Context, l *platform.Label) error
return nil return nil
} }
func (s *LabelService) CreateLabelMapping(ctx context.Context, m *platform.LabelMapping) error { func (s *LabelService) CreateLabelMapping(ctx context.Context, m *influxdb.LabelMapping) error {
if err := m.Validate(); err != nil { if err := m.Validate(); err != nil {
return err return err
} }
@ -657,7 +682,7 @@ func (s *LabelService) CreateLabelMapping(ctx context.Context, m *platform.Label
} }
// UpdateLabel updates a label and returns the updated label. // UpdateLabel updates a label and returns the updated label.
func (s *LabelService) UpdateLabel(ctx context.Context, id platform.ID, upd platform.LabelUpdate) (*platform.Label, error) { func (s *LabelService) UpdateLabel(ctx context.Context, id influxdb.ID, upd influxdb.LabelUpdate) (*influxdb.Label, error) {
u, err := newURL(s.Addr, labelIDPath(id)) u, err := newURL(s.Addr, labelIDPath(id))
if err != nil { if err != nil {
return nil, err return nil, err
@ -696,7 +721,7 @@ func (s *LabelService) UpdateLabel(ctx context.Context, id platform.ID, upd plat
} }
// DeleteLabel removes a label by ID. // DeleteLabel removes a label by ID.
func (s *LabelService) DeleteLabel(ctx context.Context, id platform.ID) error { func (s *LabelService) DeleteLabel(ctx context.Context, id influxdb.ID) error {
u, err := newURL(s.Addr, labelIDPath(id)) u, err := newURL(s.Addr, labelIDPath(id))
if err != nil { if err != nil {
return err return err
@ -718,7 +743,7 @@ func (s *LabelService) DeleteLabel(ctx context.Context, id platform.ID) error {
return CheckError(resp) return CheckError(resp)
} }
func (s *LabelService) DeleteLabelMapping(ctx context.Context, m *platform.LabelMapping) error { func (s *LabelService) DeleteLabelMapping(ctx context.Context, m *influxdb.LabelMapping) error {
url, err := newURL(s.Addr, labelNamePath(s.BasePath, m.ResourceID, m.LabelID)) url, err := newURL(s.Addr, labelNamePath(s.BasePath, m.ResourceID, m.LabelID))
if err != nil { if err != nil {
return err return err
@ -740,6 +765,6 @@ func (s *LabelService) DeleteLabelMapping(ctx context.Context, m *platform.Label
return CheckError(resp) return CheckError(resp)
} }
func labelNamePath(basePath string, resourceID platform.ID, labelID platform.ID) string { func labelNamePath(basePath string, resourceID influxdb.ID, labelID influxdb.ID) string {
return path.Join(basePath, resourceID.String(), "labels", labelID.String()) return path.Join(basePath, resourceID.String(), "labels", labelID.String())
} }

View File

@ -282,8 +282,8 @@ func TestService_handlePostLabel(t *testing.T) {
}, },
args: args{ args: args{
label: &platform.Label{ label: &platform.Label{
Name: "mylabel", Name: "mylabel",
OrganizationID: platformtesting.MustIDBase16("020f755c3c082008"), OrgID: platformtesting.MustIDBase16("020f755c3c082008"),
}, },
}, },
wants: wants{ wants: wants{

View File

@ -1820,6 +1820,13 @@ paths:
tags: tags:
- Labels - Labels
summary: Create a label summary: Create a label
parameters:
- $ref: '#/components/parameters/TraceSpan'
- in: query
name: orgID
description: return only labels that belong to the specified organization
schema:
type: string
requestBody: requestBody:
description: label to create description: label to create
required: true required: true

View File

@ -1,33 +0,0 @@
package inmem
import (
"context"
"testing"
platform "github.com/influxdata/influxdb"
platformtesting "github.com/influxdata/influxdb/testing"
)
func initLabelService(f platformtesting.LabelFields, t *testing.T) (platform.LabelService, string, func()) {
s := NewService()
s.IDGenerator = f.IDGenerator
ctx := context.Background()
for _, l := range f.Labels {
if err := s.PutLabel(ctx, l); err != nil {
t.Fatalf("failed to populate labels")
}
}
for _, m := range f.Mappings {
if err := s.CreateLabelMapping(ctx, m); err != nil {
t.Fatalf("failed to populate label mappings")
}
}
return s, OpPrefix, func() {}
}
func TestLabelService(t *testing.T) {
t.Parallel()
platformtesting.LabelService(initLabelService, t)
}

View File

@ -85,7 +85,8 @@ func (s *Service) findLabelByID(ctx context.Context, tx Tx, id influxdb.ID) (*in
func filterLabelsFn(filter influxdb.LabelFilter) func(l *influxdb.Label) bool { func filterLabelsFn(filter influxdb.LabelFilter) func(l *influxdb.Label) bool {
return func(label *influxdb.Label) bool { return func(label *influxdb.Label) bool {
return (filter.Name == "" || (filter.Name == label.Name)) return (filter.Name == "" || (filter.Name == label.Name)) &&
((filter.OrgID == nil) || (filter.OrgID != nil && *filter.OrgID == label.OrgID))
} }
} }
@ -286,7 +287,7 @@ func (s *Service) createLabelUserResourceMappings(ctx context.Context, tx Tx, l
ms, err := s.findUserResourceMappings(ctx, tx, influxdb.UserResourceMappingFilter{ ms, err := s.findUserResourceMappings(ctx, tx, influxdb.UserResourceMappingFilter{
ResourceType: influxdb.OrgsResourceType, ResourceType: influxdb.OrgsResourceType,
ResourceID: l.OrganizationID, ResourceID: l.OrgID,
}) })
if err != nil { if err != nil {
return &influxdb.Error{ return &influxdb.Error{

View File

@ -47,10 +47,10 @@ type LabelService interface {
// Label is a tag set on a resource, typically used for filtering on a UI. // Label is a tag set on a resource, typically used for filtering on a UI.
type Label struct { type Label struct {
ID ID `json:"id,omitempty"` ID ID `json:"id,omitempty"`
OrganizationID ID `json:"orgID,omitempty"` OrgID ID `json:"orgID,omitempty"`
Name string `json:"name"` Name string `json:"name"`
Properties map[string]string `json:"properties,omitempty"` Properties map[string]string `json:"properties,omitempty"`
} }
// Validate returns an error if the label is invalid. // Validate returns an error if the label is invalid.
@ -62,10 +62,10 @@ func (l *Label) Validate() error {
} }
} }
if !l.OrganizationID.Valid() { if !l.OrgID.Valid() {
return &Error{ return &Error{
Code: EInvalid, Code: EInvalid,
Msg: "organization ID is required", Msg: "orgID is required",
} }
} }

View File

@ -47,8 +47,8 @@ func TestLabelValidate(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
m := platform.Label{ m := platform.Label{
Name: tt.fields.Name, Name: tt.fields.Name,
OrganizationID: tt.fields.OrgID, OrgID: tt.fields.OrgID,
} }
if err := m.Validate(); (err != nil) != tt.wantErr { if err := m.Validate(); (err != nil) != tt.wantErr {
t.Errorf("Label.Validate() error = %v, wantErr %v", err, tt.wantErr) t.Errorf("Label.Validate() error = %v, wantErr %v", err, tt.wantErr)

View File

@ -12,8 +12,9 @@ import (
) )
const ( const (
labelOneID = "41a9f7288d4e2d64" labelOneID = "41a9f7288d4e2d64"
labelTwoID = "b7c5355e1134b11c" labelTwoID = "b7c5355e1134b11c"
labelThreeID = "c8d6466f2245c22d"
) )
var labelCmpOptions = cmp.Options{ var labelCmpOptions = cmp.Options{
@ -23,7 +24,7 @@ var labelCmpOptions = cmp.Options{
cmp.Transformer("Sort", func(in []*influxdb.Label) []*influxdb.Label { cmp.Transformer("Sort", func(in []*influxdb.Label) []*influxdb.Label {
out := append([]*influxdb.Label(nil), in...) // Copy input to avoid mutating it out := append([]*influxdb.Label(nil), in...) // Copy input to avoid mutating it
sort.Slice(out, func(i, j int) bool { sort.Slice(out, func(i, j int) bool {
return out[i].Name < out[j].Name return out[i].ID.String() > out[j].ID.String()
}) })
return out return out
}), }),
@ -206,25 +207,34 @@ func FindLabels(
fields: LabelFields{ fields: LabelFields{
Labels: []*influxdb.Label{ Labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
Name: "Tag1", Name: "Tag1",
OrgID: MustIDBase16(orgOneID),
}, },
{ {
ID: MustIDBase16(labelTwoID), ID: MustIDBase16(labelTwoID),
Name: "Tag2", Name: "Tag2",
OrgID: MustIDBase16(orgOneID),
},
{
ID: MustIDBase16(labelThreeID),
Name: "Tag1",
OrgID: MustIDBase16(orgTwoID),
}, },
}, },
}, },
args: args{ args: args{
filter: influxdb.LabelFilter{ filter: influxdb.LabelFilter{
Name: "Tag1", Name: "Tag1",
OrgID: idPtr(MustIDBase16(orgOneID)),
}, },
}, },
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
Name: "Tag1", Name: "Tag1",
OrgID: MustIDBase16(orgOneID),
}, },
}, },
}, },
@ -345,9 +355,9 @@ func UpdateLabel(
fields: LabelFields{ fields: LabelFields{
Labels: []*influxdb.Label{ Labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
}, },
}, },
}, },
@ -360,9 +370,9 @@ func UpdateLabel(
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "NotTag1", Name: "NotTag1",
}, },
}, },
}, },
@ -372,9 +382,9 @@ func UpdateLabel(
fields: LabelFields{ fields: LabelFields{
Labels: []*influxdb.Label{ Labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
}, },
}, },
}, },
@ -389,9 +399,9 @@ func UpdateLabel(
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
Properties: map[string]string{ Properties: map[string]string{
"color": "fff000", "color": "fff000",
}, },
@ -404,9 +414,9 @@ func UpdateLabel(
fields: LabelFields{ fields: LabelFields{
Labels: []*influxdb.Label{ Labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
Properties: map[string]string{ Properties: map[string]string{
"color": "fff000", "color": "fff000",
"description": "description", "description": "description",
@ -425,9 +435,9 @@ func UpdateLabel(
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
Properties: map[string]string{ Properties: map[string]string{
"color": "abc123", "color": "abc123",
"description": "description", "description": "description",
@ -441,9 +451,9 @@ func UpdateLabel(
fields: LabelFields{ fields: LabelFields{
Labels: []*influxdb.Label{ Labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
Properties: map[string]string{ Properties: map[string]string{
"color": "fff000", "color": "fff000",
"description": "description", "description": "description",
@ -462,9 +472,9 @@ func UpdateLabel(
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
Properties: map[string]string{ Properties: map[string]string{
"color": "fff000", "color": "fff000",
}, },
@ -538,14 +548,14 @@ func DeleteLabel(
fields: LabelFields{ fields: LabelFields{
Labels: []*influxdb.Label{ Labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
}, },
{ {
ID: MustIDBase16(labelTwoID), ID: MustIDBase16(labelTwoID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag2", Name: "Tag2",
}, },
}, },
}, },
@ -555,9 +565,9 @@ func DeleteLabel(
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelTwoID), ID: MustIDBase16(labelTwoID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag2", Name: "Tag2",
}, },
}, },
}, },
@ -567,9 +577,9 @@ func DeleteLabel(
fields: LabelFields{ fields: LabelFields{
Labels: []*influxdb.Label{ Labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
}, },
}, },
}, },
@ -579,9 +589,9 @@ func DeleteLabel(
wants: wants{ wants: wants{
labels: []*influxdb.Label{ labels: []*influxdb.Label{
{ {
ID: MustIDBase16(labelOneID), ID: MustIDBase16(labelOneID),
OrganizationID: MustIDBase16(orgOneID), OrgID: MustIDBase16(orgOneID),
Name: "Tag1", Name: "Tag1",
}, },
}, },
err: &influxdb.Error{ err: &influxdb.Error{