don't store references to internal buckets (#789)

* add types to bucket service tests

* add type to bucket cmd interface

* bucket type needs to be defined in json for POST creations

* rip out bucket type stuff

* remove type from bucket tests

* add InternalBucketID helper fn

* remove more code

* remove org from internal bucket ID
pull/10616/head
Jade McGough 2018-09-14 09:26:59 -07:00 committed by GitHub
parent fd1ac9d365
commit 0b70dc99c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 8 additions and 125 deletions

View File

@ -169,12 +169,6 @@ func filterBucketsFn(filter platform.BucketFilter) func(b *platform.Bucket) bool
}
}
if filter.Type != 0 {
return func(b *platform.Bucket) bool {
return b.Type == filter.Type
}
}
return func(b *platform.Bucket) bool { return true }
}
@ -244,10 +238,6 @@ func (c *Client) findBuckets(ctx context.Context, tx *bolt.Tx, filter platform.B
// CreateBucket creates a platform bucket and sets b.ID.
func (c *Client) CreateBucket(ctx context.Context, b *platform.Bucket) error {
if b.Type == 0 {
b.Type = platform.BucketTypeUser
}
return c.db.Update(func(tx *bolt.Tx) error {
if len(b.OrganizationID) == 0 {
o, err := c.findOrganizationByName(ctx, tx, b.Organization)
@ -264,17 +254,7 @@ func (c *Client) CreateBucket(ctx context.Context, b *platform.Bucket) error {
return fmt.Errorf("bucket with name %s already exists", b.Name)
}
if b.Type == platform.BucketTypeUser {
b.ID = c.IDGenerator.ID()
} else {
idstr := fmt.Sprintf("%s%d", b.OrganizationID, b.Type)
id, err := platform.IDFromString(idstr)
if err != nil {
return err
}
b.ID = *id
}
b.ID = c.IDGenerator.ID()
return c.putBucket(ctx, tx, b)
})
}

View File

@ -2,14 +2,14 @@ package platform
import (
"context"
"fmt"
"time"
)
type BucketType int
const (
BucketTypeUser = BucketType(iota + 10)
BucketTypeLogs
BucketTypeLogs = BucketType(iota + 10)
)
// Bucket is a bucket. 🎉
@ -20,7 +20,6 @@ type Bucket struct {
Name string `json:"name"`
RetentionPolicyName string `json:"rp,omitempty"` // This to support v1 sources
RetentionPeriod time.Duration `json:"retentionPeriod"`
Type BucketType `json:"-"` // Only user buckets will be visible over HTTP
}
// BucketService represents a service for managing bucket data.
@ -59,7 +58,6 @@ type BucketFilter struct {
Name *string
OrganizationID *ID
Organization *string
Type BucketType
}
// FindOptions represents options passed to all find methods with multiple results.
@ -69,3 +67,8 @@ type FindOptions struct {
SortBy string
Descending bool
}
// InternalBucketID returns the ID for an organization's specified internal bucket
func InternalBucketID(t BucketType) (*ID, error) {
return IDFromString(fmt.Sprintf("%d", t))
}

View File

@ -64,7 +64,6 @@ func bucketCreateF(cmd *cobra.Command, args []string) {
b := &platform.Bucket{
Name: bucketCreateFlags.name,
RetentionPeriod: bucketCreateFlags.retention,
Type: platform.BucketTypeUser,
}
if bucketCreateFlags.org != "" {

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"time"
"github.com/influxdata/platform"
"github.com/influxdata/platform/cmd/influx/internal"
@ -59,12 +58,6 @@ func organizationCreateF(cmd *cobra.Command, args []string) {
os.Exit(1)
}
_, err := createInternalBucket(o)
if err != nil {
fmt.Printf("Failed to create system bucket: %v\n", err)
os.Exit(1)
}
w := internal.NewTabWriter(os.Stdout)
w.WriteHeaders(
"ID",
@ -77,26 +70,6 @@ func organizationCreateF(cmd *cobra.Command, args []string) {
w.Flush()
}
func createInternalBucket(o *platform.Organization) (*platform.Bucket, error) {
bucketS := &http.BucketService{
Addr: flags.host,
Token: flags.token,
}
bucket := &platform.Bucket{
OrganizationID: o.ID,
Name: "task-logs",
RetentionPeriod: time.Hour * 24 * 7,
Type: platform.BucketTypeLogs,
}
if err := bucketS.CreateBucket(context.Background(), bucket); err != nil {
return nil, err
}
return bucket, nil
}
// Find Command
type OrganizationFindFlags struct {
name string

View File

@ -106,7 +106,6 @@ func decodePostBucketRequest(ctx context.Context, r *http.Request) (*postBucketR
if err := json.NewDecoder(r.Body).Decode(b); err != nil {
return nil, err
}
b.Type = platform.BucketTypeUser
b.Organization = orgName
return &postBucketRequest{
@ -361,9 +360,6 @@ func (s *BucketService) FindBucketByID(ctx context.Context, id platform.ID) (*pl
// FindBucket returns the first bucket that matches filter.
func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFilter) (*platform.Bucket, error) {
// don't expose internal buckets
filter.Type = platform.BucketTypeUser
bs, n, err := s.FindBuckets(ctx, filter)
if err != nil {
return nil, err
@ -379,9 +375,6 @@ func (s *BucketService) FindBucket(ctx context.Context, filter platform.BucketFi
// FindBuckets returns a list of buckets that match filter and the total count of matching buckets.
// Additional options provide pagination & sorting.
func (s *BucketService) FindBuckets(ctx context.Context, filter platform.BucketFilter, opt ...platform.FindOptions) ([]*platform.Bucket, int, error) {
// don't expose internal buckets
filter.Type = platform.BucketTypeUser
u, err := newURL(s.Addr, bucketPath)
if err != nil {
return nil, 0, err

View File

@ -7,7 +7,6 @@ import (
"fmt"
"net/http"
"path"
"time"
"github.com/influxdata/platform"
kerrors "github.com/influxdata/platform/kit/errors"
@ -86,20 +85,6 @@ func (h *OrgHandler) handlePostOrg(w http.ResponseWriter, r *http.Request) {
return
}
// create internal org bucket
systemBucket := &platform.Bucket{
OrganizationID: req.Org.ID,
Name: "task-logs",
RetentionPeriod: time.Hour * 24 * 7,
Type: platform.BucketTypeLogs,
}
// TODO(jm): if this fails, revert org creation
if err := h.BucketService.CreateBucket(ctx, systemBucket); err != nil {
EncodeError(ctx, fmt.Errorf("Failed to create system bucket"), w)
return
}
if err := encodeResponse(ctx, w, http.StatusCreated, newOrgResponse(req.Org)); err != nil {
EncodeError(ctx, err, w)
return

View File

@ -136,56 +136,6 @@ func CreateBucket(
},
},
},
{
name: "create system bucket",
fields: BucketFields{
IDGenerator: &mock.IDGenerator{
IDFn: func() platform.ID {
return idFromString(t, bucketTwoID)
},
},
Buckets: []*platform.Bucket{
{
ID: idFromString(t, bucketOneID),
Name: "bucket1",
OrganizationID: idFromString(t, orgOneID),
},
},
Organizations: []*platform.Organization{
{
Name: "theorg",
ID: idFromString(t, orgOneID),
},
{
Name: "otherorg",
ID: idFromString(t, orgTwoID),
},
},
},
args: args{
bucket: &platform.Bucket{
Name: "bucket2",
OrganizationID: idFromString(t, orgTwoID),
Type: platform.BucketTypeLogs,
},
},
wants: wants{
buckets: []*platform.Bucket{
{
ID: idFromString(t, bucketOneID),
Name: "bucket1",
Organization: "theorg",
OrganizationID: idFromString(t, orgOneID),
},
{
ID: idFromString(t, fmt.Sprintf("%s%d", orgTwoID, platform.BucketTypeLogs)),
Name: "bucket2",
Organization: "otherorg",
OrganizationID: idFromString(t, orgTwoID),
},
},
},
},
{
name: "basic create bucket using org name",
fields: BucketFields{