2018-05-15 20:11:32 +00:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/influxdata/platform"
|
2018-05-22 17:28:04 +00:00
|
|
|
"github.com/influxdata/platform/query/id"
|
2018-05-15 20:11:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// FromBucketService wraps an platform.BucketService in the BucketLookup interface.
|
|
|
|
func FromBucketService(srv platform.BucketService) *BucketLookup {
|
|
|
|
return &BucketLookup{
|
|
|
|
BucketService: srv,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// BucketLookup converts IFQL bucket lookups into platform.BucketService calls.
|
|
|
|
type BucketLookup struct {
|
|
|
|
BucketService platform.BucketService
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup returns the bucket id and its existence given an org id and bucket name.
|
|
|
|
func (b *BucketLookup) Lookup(orgID id.ID, name string) (id.ID, bool) {
|
|
|
|
oid := platform.ID(orgID)
|
|
|
|
filter := platform.BucketFilter{
|
|
|
|
OrganizationID: &oid,
|
|
|
|
Name: &name,
|
|
|
|
}
|
|
|
|
bucket, err := b.BucketService.FindBucket(context.Background(), filter)
|
|
|
|
if err != nil {
|
|
|
|
return nil, false
|
|
|
|
}
|
|
|
|
return id.ID(bucket.ID), true
|
|
|
|
}
|