influxdb/bucket.go

120 lines
3.5 KiB
Go
Raw Normal View History

package influxdb
import (
"context"
"strings"
"time"
)
const (
2019-08-30 19:47:06 +00:00
// 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)
)
2018-10-18 19:09:25 +00:00
// InfiniteRetention is default infinite retention period.
const InfiniteRetention = 0
// Bucket is a bucket. 🎉
type Bucket struct {
2018-08-02 20:55:51 +00:00
ID ID `json:"id,omitempty"`
2019-04-10 21:16:35 +00:00
OrgID ID `json:"orgID,omitempty"`
2018-08-02 20:55:51 +00:00
Name string `json:"name"`
2019-04-22 18:51:37 +00:00
Description string `json:"description"`
2018-08-02 20:55:51 +00:00
RetentionPolicyName string `json:"rp,omitempty"` // This to support v1 sources
RetentionPeriod time.Duration `json:"retentionPeriod"`
CRUDLog
}
// ops for buckets error and buckets op logs.
var (
OpFindBucketByID = "FindBucketByID"
OpFindBucket = "FindBucket"
OpFindBuckets = "FindBuckets"
OpCreateBucket = "CreateBucket"
OpUpdateBucket = "UpdateBucket"
OpDeleteBucket = "DeleteBucket"
)
// BucketService represents a service for managing bucket data.
type BucketService interface {
// FindBucketByID returns a single bucket by ID.
FindBucketByID(ctx context.Context, id ID) (*Bucket, error)
// FindBucket returns the first bucket that matches filter.
FindBucket(ctx context.Context, filter BucketFilter) (*Bucket, error)
// FindBuckets returns a list of buckets that match filter and the total count of matching buckets.
// Additional options provide pagination & sorting.
FindBuckets(ctx context.Context, filter BucketFilter, opt ...FindOptions) ([]*Bucket, int, error)
// CreateBucket creates a new bucket and sets b.ID with the new identifier.
CreateBucket(ctx context.Context, b *Bucket) error
// UpdateBucket updates a single bucket with changeset.
// Returns the new bucket state after update.
UpdateBucket(ctx context.Context, id ID, upd BucketUpdate) (*Bucket, error)
// DeleteBucket removes a bucket by ID.
DeleteBucket(ctx context.Context, id ID) error
}
// BucketUpdate represents updates to a bucket.
// Only fields which are set are updated.
type BucketUpdate struct {
Name *string `json:"name,omitempty"`
2019-04-22 18:51:37 +00:00
Description *string `json:"description,omitempty"`
RetentionPeriod *time.Duration `json:"retentionPeriod,omitempty"`
}
// BucketFilter represents a set of filter that restrict the returned results.
type BucketFilter struct {
ID *ID
Name *string
feat(platform): add boltdb implementation of services feat(platform): add id to authorization feat(platform): add user arg to CreateAuthorization method on auth svc migrate(platform): move idp command to platform directory This comit did not move the ifql command as it depends on the query service which has yet to be migrated. feat(platform): add optional user name to authorization struct feat(platform): add organization name to bucket struct Additionally allow filtering buckets by organization name. feat(prom): ensure that prom auth svc implement base interface feat(prometheus): add user to create authorization method feat(prom): drop user string from create authorization feat(zap): ensure that zap auth svc implements base service interface feat(zap): add user to create authorization method feat(zap): drop user string from create authorization feat(http): add ids to authorization service feat(http): ensure that http authoriztaion service implements auth svc interface feat(http): use authorization ids in authorization handler squash(http): add check for http status accepted in authorization service feat(http): clean up authorization service and handlers feat(http): drop user string from create authorization fix(http): normalize the http authorization service feat(http): normalize bucket service and handler methods Additonally, we added support for DELETE bucket feat(http): add delete user handler Additionally, there was a bit of general cleanup feat(http): add delete route for organization handler and service Did a bit of additional cleanup of the http code. test(testing): add service conformance tests test(testing): add organization service conformance tests test(testing): add conformance test for orgs service Additionally, there was a bit of cleanup in the users service tests test(testing): add conformance test for authorizations service test(testing): update auth tests to validate that user exists test(testing): update authorization conformance tests with user name test(testing): update bucket conformance tests to include organizations feat(bolt): add bolt implementation services feat(bolt): add bolt implementation of organization service feat(bolt): add bolt implementation of users service feat(bolt): add bolt implementation of authorization service feat(bolt): add user to create authorization method feat(bolt): drop user string from create authorization fix(bolt): set user name on authorization after put feat(bolt): update bucket servie to include organizations feat(bolt): add dependent destroy of resources feat(cmd/idpd): use bolt services in platform server feat(cmd/idpd): use bolt organization service in platform server feat(cmd/idpd): use bolt users service in plaform server feat(cmd/idpd): use bolt client as authorization service feat(cmd/idp): show user name in output of auth sub command feat(cmd/idp): clean up bucket subcommand of idp command fix(cmd/idp): normalize idp command output for users fix(cmd/idp): normalize auth subcommand output feat(cmd/idp): add support for delete organiztion command migrate(idp): move ifql subcommand of idp to platform
2018-05-16 18:59:35 +00:00
OrganizationID *ID
2019-04-09 21:26:54 +00:00
Org *string
}
2018-12-09 15:25:35 +00:00
// QueryParams Converts BucketFilter fields to url query params.
func (f BucketFilter) QueryParams() map[string][]string {
qp := map[string][]string{}
if f.ID != nil {
qp["id"] = []string{f.ID.String()}
}
if f.Name != nil {
qp["name"] = []string{*f.Name}
}
if f.OrganizationID != nil {
qp["orgID"] = []string{f.OrganizationID.String()}
}
2019-04-09 21:26:54 +00:00
if f.Org != nil {
qp["org"] = []string{*f.Org}
2018-12-09 15:25:35 +00:00
}
return qp
}
// String returns a human-readable string of the BucketFilter,
// particularly useful for error messages.
func (f BucketFilter) String() string {
// There should always be exactly 2 fields set, but if it's somehow more, that's fine.
parts := make([]string, 0, 2)
if f.ID != nil {
parts = append(parts, "Bucket ID: "+f.ID.String())
}
if f.Name != nil {
parts = append(parts, "Bucket Name: "+*f.Name)
}
if f.OrganizationID != nil {
parts = append(parts, "Org ID: "+f.OrganizationID.String())
}
2019-04-09 21:26:54 +00:00
if f.Org != nil {
parts = append(parts, "Org Name: "+*f.Org)
}
return "[" + strings.Join(parts, ", ") + "]"
}