Merge pull request #19548 from influxdata/yq-issue-19547
chore: remove hardcoded constants for idspull/19503/head
commit
99bb1bba4d
|
@ -90,11 +90,6 @@ func authorize(ctx context.Context, a influxdb.Action, rt influxdb.ResourceType,
|
|||
}
|
||||
|
||||
func authorizeReadSystemBucket(ctx context.Context, bid, oid influxdb.ID) (influxdb.Authorizer, influxdb.Permission, error) {
|
||||
// HACK: remove once system buckets are migrated away from hard coded values
|
||||
if !oid.Valid() && (bid == influxdb.TasksSystemBucketID || bid == influxdb.MonitoringSystemBucketID) {
|
||||
a, _ := icontext.GetAuthorizer(ctx)
|
||||
return a, influxdb.Permission{}, nil
|
||||
}
|
||||
return AuthorizeReadOrg(ctx, oid)
|
||||
}
|
||||
|
||||
|
|
|
@ -8,11 +8,6 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// TasksSystemBucketID is the fixed ID for our tasks system bucket
|
||||
TasksSystemBucketID = ID(10)
|
||||
// MonitoringSystemBucketID is the fixed ID for our monitoring system bucket
|
||||
MonitoringSystemBucketID = ID(11)
|
||||
|
||||
// BucketTypeUser is a user created bucket
|
||||
BucketTypeUser = BucketType(0)
|
||||
// BucketTypeSystem is an internally created bucket that cannot be deleted/renamed.
|
||||
|
|
65
kv/bucket.go
65
kv/bucket.go
|
@ -179,30 +179,9 @@ func (s *Service) findBucketByName(ctx context.Context, tx Tx, orgID influxdb.ID
|
|||
|
||||
buf, err := idx.Get(key)
|
||||
if IsNotFound(err) {
|
||||
switch n {
|
||||
case influxdb.TasksSystemBucketName:
|
||||
return &influxdb.Bucket{
|
||||
ID: influxdb.TasksSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: influxdb.TasksSystemBucketName,
|
||||
RetentionPeriod: influxdb.TasksSystemBucketRetention,
|
||||
Description: "System bucket for task logs",
|
||||
OrgID: orgID,
|
||||
}, nil
|
||||
case influxdb.MonitoringSystemBucketName:
|
||||
return &influxdb.Bucket{
|
||||
ID: influxdb.MonitoringSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: influxdb.MonitoringSystemBucketName,
|
||||
RetentionPeriod: influxdb.MonitoringSystemBucketRetention,
|
||||
Description: "System bucket for monitoring logs",
|
||||
OrgID: orgID,
|
||||
}, nil
|
||||
default:
|
||||
return nil, &influxdb.Error{
|
||||
Code: influxdb.ENotFound,
|
||||
Msg: fmt.Sprintf("bucket %q not found", n),
|
||||
}
|
||||
return nil, &influxdb.Error{
|
||||
Code: influxdb.ENotFound,
|
||||
Msg: fmt.Sprintf("bucket %q not found", n),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,6 +322,10 @@ func (s *Service) FindBuckets(ctx context.Context, filter influxdb.BucketFilter,
|
|||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
// Don't append system buckets if Name is set. Users who don't have real
|
||||
// system buckets won't get mocked buckets if they query for a bucket by name
|
||||
// without the orgID, but this is a vanishing small number of users and has
|
||||
|
@ -351,40 +334,6 @@ func (s *Service) FindBuckets(ctx context.Context, filter influxdb.BucketFilter,
|
|||
return bs, len(bs), nil
|
||||
}
|
||||
|
||||
needsSystemBuckets := true
|
||||
for _, b := range bs {
|
||||
if b.Type == influxdb.BucketTypeSystem {
|
||||
needsSystemBuckets = false
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if needsSystemBuckets {
|
||||
tb := &influxdb.Bucket{
|
||||
ID: influxdb.TasksSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: influxdb.TasksSystemBucketName,
|
||||
RetentionPeriod: influxdb.TasksSystemBucketRetention,
|
||||
Description: "System bucket for task logs",
|
||||
}
|
||||
|
||||
bs = append(bs, tb)
|
||||
|
||||
mb := &influxdb.Bucket{
|
||||
ID: influxdb.MonitoringSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: influxdb.MonitoringSystemBucketName,
|
||||
RetentionPeriod: influxdb.MonitoringSystemBucketRetention,
|
||||
Description: "System bucket for monitoring logs",
|
||||
}
|
||||
|
||||
bs = append(bs, mb)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
return bs, len(bs), nil
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ func NewBucketService() *BucketService {
|
|||
FindBucketByIDFn: func(context.Context, platform.ID) (*platform.Bucket, error) { return nil, nil },
|
||||
FindBucketByNameFn: func(context.Context, platform.ID, string) (*platform.Bucket, error) {
|
||||
return &platform.Bucket{
|
||||
ID: platform.TasksSystemBucketID,
|
||||
ID: platform.ID(10),
|
||||
Type: platform.BucketTypeSystem,
|
||||
Name: "_tasks",
|
||||
RetentionPeriod: time.Hour * 24 * 3,
|
||||
|
|
|
@ -102,7 +102,7 @@ func TestDeduplicateRuns(t *testing.T) {
|
|||
metaClient := meta.NewClient(meta.NewConfig(), store)
|
||||
require.NoError(t, metaClient.Open())
|
||||
|
||||
_, err := metaClient.CreateDatabase(influxdb.TasksSystemBucketID.String())
|
||||
_, err := metaClient.CreateDatabase(influxdb.ID(10).String())
|
||||
require.NoError(t, err)
|
||||
|
||||
ab := newAnalyticalBackend(t, ts.OrganizationService, ts.BucketService, metaClient)
|
||||
|
|
|
@ -117,28 +117,7 @@ func (s *Store) GetBucketByName(ctx context.Context, tx kv.Tx, orgID influxdb.ID
|
|||
|
||||
// allow for hard coded bucket names that dont exist in the system
|
||||
if kv.IsNotFound(err) {
|
||||
switch n {
|
||||
case influxdb.TasksSystemBucketName:
|
||||
return &influxdb.Bucket{
|
||||
ID: influxdb.TasksSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: influxdb.TasksSystemBucketName,
|
||||
RetentionPeriod: influxdb.TasksSystemBucketRetention,
|
||||
Description: "System bucket for task logs",
|
||||
OrgID: orgID,
|
||||
}, nil
|
||||
case influxdb.MonitoringSystemBucketName:
|
||||
return &influxdb.Bucket{
|
||||
ID: influxdb.MonitoringSystemBucketID,
|
||||
Type: influxdb.BucketTypeSystem,
|
||||
Name: influxdb.MonitoringSystemBucketName,
|
||||
RetentionPeriod: influxdb.MonitoringSystemBucketRetention,
|
||||
Description: "System bucket for monitoring logs",
|
||||
OrgID: orgID,
|
||||
}, nil
|
||||
default:
|
||||
return nil, ErrBucketNotFoundByName(n)
|
||||
}
|
||||
return nil, ErrBucketNotFoundByName(n)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue