feat(bolt): add bucket service to source on retrieval

Co-authored-by: Andrew Watkins <andrew.watkinz@gmail.com>
Co-authored-by: Michael Desa <mjdesa@gmail.com>
pull/10616/head
Michael Desa 2018-07-30 14:37:17 -04:00
parent 503be5b0ef
commit 6dbe11b318
1 changed files with 37 additions and 1 deletions

View File

@ -8,6 +8,9 @@ import (
"github.com/coreos/bbolt"
"github.com/influxdata/platform"
"github.com/influxdata/platform/http"
"github.com/influxdata/platform/http/influxdb"
"go.uber.org/zap"
)
var (
@ -18,7 +21,7 @@ var (
var DefaultSource = platform.Source{
Default: true,
Name: "autogen",
Type: "v2",
Type: platform.SelfSourceType,
}
func init() {
@ -104,6 +107,9 @@ func (c *Client) findSourceByID(ctx context.Context, tx *bolt.Tx, id platform.ID
if err := json.Unmarshal(v, &s); err != nil {
return nil, err
}
if err := c.setServices(ctx, &s); err != nil {
c.Logger.Debug("could not set services on source", zap.Error(err))
}
return &s, nil
}
@ -181,6 +187,9 @@ func (c *Client) forEachSource(ctx context.Context, tx *bolt.Tx, fn func(*platfo
if err := json.Unmarshal(v, s); err != nil {
return err
}
if err := c.setServices(ctx, s); err != nil {
c.Logger.Debug("could not set services on source", zap.Error(err))
}
if !fn(s) {
break
}
@ -218,6 +227,10 @@ func (c *Client) updateSource(ctx context.Context, tx *bolt.Tx, id platform.ID,
return nil, err
}
if err := c.setServices(ctx, s); err != nil {
c.Logger.Debug("could not set services on source", zap.Error(err))
}
return s, nil
}
@ -238,3 +251,26 @@ func (c *Client) deleteSource(ctx context.Context, tx *bolt.Tx, id platform.ID)
}
return tx.Bucket(sourceBucket).Delete(id)
}
func (c *Client) setServices(ctx context.Context, s *platform.Source) error {
switch s.Type {
case platform.SelfSourceType:
s.BucketService = c
case platform.V2SourceType:
s.BucketService = &http.BucketService{
Addr: s.URL,
InsecureSkipVerify: s.InsecureSkipVerify,
Token: s.Token,
}
case platform.V1SourceType:
s.BucketService = &influxdb.BucketService{
Addr: s.URL,
InsecureSkipVerify: s.InsecureSkipVerify,
Username: s.Username,
Password: s.Password,
}
default:
return fmt.Errorf("unsupported source type %s", s.Type)
}
return nil
}