Skip to content

Commit

Permalink
Merge pull request #13411 from influxdata/telegraf_rename_orgID
Browse files Browse the repository at this point in the history
fix(influxdb): rename telegraf orgID
  • Loading branch information
kelwang authored Jun 3, 2019
2 parents 27fd7ec + 7a40d92 commit 3a07e7f
Show file tree
Hide file tree
Showing 22 changed files with 330 additions and 335 deletions.
10 changes: 5 additions & 5 deletions authorizer/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (s *TelegrafConfigService) FindTelegrafConfigByID(ctx context.Context, id i
return nil, err
}

if err := authorizeReadTelegraf(ctx, tc.OrganizationID, id); err != nil {
if err := authorizeReadTelegraf(ctx, tc.OrgID, id); err != nil {
return nil, err
}

Expand All @@ -80,7 +80,7 @@ func (s *TelegrafConfigService) FindTelegrafConfigs(ctx context.Context, filter
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
telegrafs := ts[:0]
for _, tc := range ts {
err := authorizeReadTelegraf(ctx, tc.OrganizationID, tc.ID)
err := authorizeReadTelegraf(ctx, tc.OrgID, tc.ID)
if err != nil && influxdb.ErrorCode(err) != influxdb.EUnauthorized {
return nil, 0, err
}
Expand All @@ -97,7 +97,7 @@ func (s *TelegrafConfigService) FindTelegrafConfigs(ctx context.Context, filter

// CreateTelegrafConfig checks to see if the authorizer on context has write access to the global telegraf config resource.
func (s *TelegrafConfigService) CreateTelegrafConfig(ctx context.Context, tc *influxdb.TelegrafConfig, userID influxdb.ID) error {
p, err := influxdb.NewPermission(influxdb.WriteAction, influxdb.TelegrafsResourceType, tc.OrganizationID)
p, err := influxdb.NewPermission(influxdb.WriteAction, influxdb.TelegrafsResourceType, tc.OrgID)
if err != nil {
return err
}
Expand All @@ -116,7 +116,7 @@ func (s *TelegrafConfigService) UpdateTelegrafConfig(ctx context.Context, id inf
return nil, err
}

if err := authorizeWriteTelegraf(ctx, tc.OrganizationID, id); err != nil {
if err := authorizeWriteTelegraf(ctx, tc.OrgID, id); err != nil {
return nil, err
}

Expand All @@ -130,7 +130,7 @@ func (s *TelegrafConfigService) DeleteTelegrafConfig(ctx context.Context, id inf
return err
}

if err := authorizeWriteTelegraf(ctx, tc.OrganizationID, id); err != nil {
if err := authorizeWriteTelegraf(ctx, tc.OrgID, id); err != nil {
return err
}

Expand Down
78 changes: 39 additions & 39 deletions authorizer/telegraf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ func TestTelegrafConfigStore_FindTelegrafConfigByID(t *testing.T) {
TelegrafConfigStore: &mock.TelegrafConfigStore{
FindTelegrafConfigByIDF: func(ctx context.Context, id influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: id,
OrganizationID: 10,
ID: id,
OrgID: 10,
}, nil
},
},
Expand All @@ -77,8 +77,8 @@ func TestTelegrafConfigStore_FindTelegrafConfigByID(t *testing.T) {
TelegrafConfigStore: &mock.TelegrafConfigStore{
FindTelegrafConfigByIDF: func(ctx context.Context, id influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: id,
OrganizationID: 10,
ID: id,
OrgID: 10,
}, nil
},
},
Expand Down Expand Up @@ -140,16 +140,16 @@ func TestTelegrafConfigStore_FindTelegrafConfigs(t *testing.T) {
FindTelegrafConfigsF: func(ctx context.Context, filter influxdb.TelegrafConfigFilter, opt ...influxdb.FindOptions) ([]*influxdb.TelegrafConfig, int, error) {
return []*influxdb.TelegrafConfig{
{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
},
{
ID: 2,
OrganizationID: 10,
ID: 2,
OrgID: 10,
},
{
ID: 3,
OrganizationID: 11,
ID: 3,
OrgID: 11,
},
}, 3, nil
},
Expand All @@ -166,16 +166,16 @@ func TestTelegrafConfigStore_FindTelegrafConfigs(t *testing.T) {
wants: wants{
telegrafs: []*influxdb.TelegrafConfig{
{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
},
{
ID: 2,
OrganizationID: 10,
ID: 2,
OrgID: 10,
},
{
ID: 3,
OrganizationID: 11,
ID: 3,
OrgID: 11,
},
},
},
Expand All @@ -187,16 +187,16 @@ func TestTelegrafConfigStore_FindTelegrafConfigs(t *testing.T) {
FindTelegrafConfigsF: func(ctx context.Context, filter influxdb.TelegrafConfigFilter, opt ...influxdb.FindOptions) ([]*influxdb.TelegrafConfig, int, error) {
return []*influxdb.TelegrafConfig{
{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
},
{
ID: 2,
OrganizationID: 10,
ID: 2,
OrgID: 10,
},
{
ID: 3,
OrganizationID: 11,
ID: 3,
OrgID: 11,
},
}, 3, nil
},
Expand All @@ -214,12 +214,12 @@ func TestTelegrafConfigStore_FindTelegrafConfigs(t *testing.T) {
wants: wants{
telegrafs: []*influxdb.TelegrafConfig{
{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
},
{
ID: 2,
OrganizationID: 10,
ID: 2,
OrgID: 10,
},
},
},
Expand Down Expand Up @@ -267,14 +267,14 @@ func TestTelegrafConfigStore_UpdateTelegrafConfig(t *testing.T) {
TelegrafConfigStore: &mock.TelegrafConfigStore{
FindTelegrafConfigByIDF: func(ctc context.Context, id influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
}, nil
},
UpdateTelegrafConfigF: func(ctx context.Context, id influxdb.ID, upd *influxdb.TelegrafConfig, userID influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
}, nil
},
},
Expand Down Expand Up @@ -308,14 +308,14 @@ func TestTelegrafConfigStore_UpdateTelegrafConfig(t *testing.T) {
TelegrafConfigStore: &mock.TelegrafConfigStore{
FindTelegrafConfigByIDF: func(ctc context.Context, id influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
}, nil
},
UpdateTelegrafConfigF: func(ctx context.Context, id influxdb.ID, upd *influxdb.TelegrafConfig, userID influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
}, nil
},
},
Expand Down Expand Up @@ -378,8 +378,8 @@ func TestTelegrafConfigStore_DeleteTelegrafConfig(t *testing.T) {
TelegrafConfigStore: &mock.TelegrafConfigStore{
FindTelegrafConfigByIDF: func(ctc context.Context, id influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
}, nil
},
DeleteTelegrafConfigF: func(ctx context.Context, id influxdb.ID) error {
Expand Down Expand Up @@ -416,8 +416,8 @@ func TestTelegrafConfigStore_DeleteTelegrafConfig(t *testing.T) {
TelegrafConfigStore: &mock.TelegrafConfigStore{
FindTelegrafConfigByIDF: func(ctc context.Context, id influxdb.ID) (*influxdb.TelegrafConfig, error) {
return &influxdb.TelegrafConfig{
ID: 1,
OrganizationID: 10,
ID: 1,
OrgID: 10,
}, nil
},
DeleteTelegrafConfigF: func(ctx context.Context, id influxdb.ID) error {
Expand Down Expand Up @@ -535,7 +535,7 @@ func TestTelegrafConfigStore_CreateTelegrafConfig(t *testing.T) {
ctx := context.Background()
ctx = influxdbcontext.SetAuthorizer(ctx, &Authorizer{[]influxdb.Permission{tt.args.permission}})

err := s.CreateTelegrafConfig(ctx, &influxdb.TelegrafConfig{OrganizationID: tt.args.orgID}, influxdb.ID(1))
err := s.CreateTelegrafConfig(ctx, &influxdb.TelegrafConfig{OrgID: tt.args.orgID}, influxdb.ID(1))
influxdbtesting.ErrorsEqual(t, err, tt.wants.err)
})
}
Expand Down
4 changes: 2 additions & 2 deletions bolt/lookup_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func TestClient_Name(t *testing.T) {
},
init: func(ctx context.Context, s *bolt.Client) error {
return s.CreateTelegrafConfig(ctx, &platform.TelegrafConfig{
OrganizationID: platformtesting.MustIDBase16("0000000000000009"),
Name: "telegraf1",
OrgID: platformtesting.MustIDBase16("0000000000000009"),
Name: "telegraf1",
}, testID)
},
},
Expand Down
2 changes: 1 addition & 1 deletion bolt/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ func (c *Client) FindResourceOrganizationID(ctx context.Context, rt influxdb.Res
if err != nil {
return influxdb.InvalidID(), err
}
return r.OrganizationID, nil
return r.OrgID, nil
case influxdb.VariablesResourceType:
r, err := c.FindVariableByID(ctx, id)
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions bolt/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (c *Client) findTelegrafConfigs(ctx context.Context, tx *bolt.Tx, filter pl
}
if tc != nil {
// Restrict results by organization ID, if it has been provided
if filter.OrganizationID != nil && filter.OrganizationID.Valid() && tc.OrganizationID != *filter.OrganizationID {
if filter.OrgID != nil && filter.OrgID.Valid() && tc.OrgID != *filter.OrgID {
continue
}
tcs = append(tcs, tc)
Expand Down Expand Up @@ -119,10 +119,10 @@ func (c *Client) putTelegrafConfig(ctx context.Context, tx *bolt.Tx, tc *platfor
Err: err,
}
}
if !tc.OrganizationID.Valid() {
if !tc.OrgID.Valid() {
return &platform.Error{
Code: platform.EEmptyValue,
Msg: platform.ErrTelegrafConfigInvalidOrganizationID,
Msg: platform.ErrTelegrafConfigInvalidOrgID,
}
}
err = tx.Bucket(telegrafBucket).Put(encodedID, v)
Expand Down Expand Up @@ -172,8 +172,8 @@ func (c *Client) UpdateTelegrafConfig(ctx context.Context, id platform.ID, tc *p
return err
}
tc.ID = id
// OrganizationID can not be updated
tc.OrganizationID = current.OrganizationID
// OrgID can not be updated
tc.OrgID = current.OrgID
pErr = c.putTelegrafConfig(ctx, tx, tc)
if pErr != nil {
return &platform.Error{
Expand Down
2 changes: 1 addition & 1 deletion http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7381,7 +7381,7 @@ components:
type: array
items:
$ref: "#/components/schemas/TelegrafRequestPlugin"
organizationID:
orgID:
type: string
TelegrafRequestPlugin:
oneOf:
Expand Down
34 changes: 17 additions & 17 deletions http/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,26 @@ func (r *telegrafResponse) MarshalJSON() ([]byte, error) {

// telegrafConfigEncode is the helper struct for json encoding.
type telegrafConfigEncode struct {
ID platform.ID `json:"id"`
OrganizationID platform.ID `json:"organizationID,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Agent platform.TelegrafAgentConfig `json:"agent"`
Plugins []telegrafPluginEncode `json:"plugins"`
Labels []platform.Label `json:"labels"`
Links telegrafLinks `json:"links"`
ID platform.ID `json:"id"`
OrgID platform.ID `json:"OrgID,omitempty"`
Name string `json:"name"`
Description string `json:"description"`
Agent platform.TelegrafAgentConfig `json:"agent"`
Plugins []telegrafPluginEncode `json:"plugins"`
Labels []platform.Label `json:"labels"`
Links telegrafLinks `json:"links"`
}

tce := new(telegrafConfigEncode)
*tce = telegrafConfigEncode{
ID: r.ID,
OrganizationID: r.OrganizationID,
Name: r.Name,
Description: r.Description,
Agent: r.Agent,
Plugins: make([]telegrafPluginEncode, len(r.Plugins)),
Labels: r.Labels,
Links: r.Links,
ID: r.ID,
OrgID: r.OrgID,
Name: r.Name,
Description: r.Description,
Agent: r.Agent,
Plugins: make([]telegrafPluginEncode, len(r.Plugins)),
Labels: r.Labels,
Links: r.Links,
}

for k, p := range r.Plugins {
Expand Down Expand Up @@ -303,7 +303,7 @@ func decodeTelegrafConfigFilter(ctx context.Context, r *http.Request) (*platform
Err: err,
}
}
f.OrganizationID = orgID
f.OrgID = orgID
} else if orgNameStr := q.Get("org"); orgNameStr != "" {
*f.Organization = orgNameStr
}
Expand Down
Loading

0 comments on commit 3a07e7f

Please sign in to comment.