Use orgID when to function reports its write buckets. (#11363)

* Use orgID when to function reports its write buckets.

fixes #11231
pull/11413/head
Lyon Hill 2019-01-22 14:13:50 -07:00 committed by GitHub
parent ba9e365aca
commit c4e71bf412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -173,6 +173,12 @@ func (ToOpSpec) Kind() flux.OperationKind {
// BucketsAccessed returns the buckets accessed by the spec.
func (o *ToOpSpec) BucketsAccessed() (readBuckets, writeBuckets []platform.BucketFilter) {
bf := platform.BucketFilter{Name: &o.Bucket, Organization: &o.Org}
if o.OrgID != "" {
id, err := platform.IDFromString(o.OrgID)
if err == nil {
bf.OrganizationID = id
}
}
writeBuckets = append(writeBuckets, bf)
return readBuckets, writeBuckets
}

View File

@ -88,6 +88,7 @@ func TestToOpSpec_BucketsAccessed(t *testing.T) {
t.Skip("https://github.com/influxdata/flux/issues/114")
bucketName := "my_bucket"
orgName := "my_org"
id := platform.ID(1)
tests := []querytest.BucketAwareQueryTestCase{
{
Name: "from() with bucket and to with org and bucket",
@ -95,6 +96,12 @@ func TestToOpSpec_BucketsAccessed(t *testing.T) {
WantReadBuckets: &[]platform.BucketFilter{{Name: &bucketName}},
WantWriteBuckets: &[]platform.BucketFilter{{Name: &bucketName, Organization: &orgName}},
},
{
Name: "from() with bucket and to with orgID and bucket",
Raw: `from(bucket:"my_bucket") |> to(bucket:"my_bucket", orgID:"0000000000000001")`,
WantReadBuckets: &[]platform.BucketFilter{{Name: &bucketName}},
WantWriteBuckets: &[]platform.BucketFilter{{Name: &bucketName, OrganizationID: &id}},
},
}
for _, tc := range tests {