2016-11-15 01:07:38 +00:00
|
|
|
package canned
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
|
2019-01-08 00:37:16 +00:00
|
|
|
"github.com/influxdata/influxdb/chronograf"
|
2016-11-15 01:07:38 +00:00
|
|
|
)
|
|
|
|
|
2018-10-15 14:39:01 +00:00
|
|
|
//go:generate env GO111MODULE=on go run github.com/kevinburke/go-bindata/go-bindata -o bin_gen.go -tags assets -ignore README|apps|.sh|go -pkg canned .
|
2016-11-15 01:07:38 +00:00
|
|
|
|
2017-10-24 22:50:11 +00:00
|
|
|
// BinLayoutsStore represents a layout store using data generated by go-bindata
|
|
|
|
type BinLayoutsStore struct {
|
2016-11-15 01:07:38 +00:00
|
|
|
Logger chronograf.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
// All returns the set of all layouts
|
2017-10-24 22:50:11 +00:00
|
|
|
func (s *BinLayoutsStore) All(ctx context.Context) ([]chronograf.Layout, error) {
|
2016-11-15 01:07:38 +00:00
|
|
|
names := AssetNames()
|
|
|
|
layouts := make([]chronograf.Layout, len(names))
|
|
|
|
for i, name := range names {
|
|
|
|
octets, err := Asset(name)
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.
|
|
|
|
WithField("component", "apps").
|
|
|
|
WithField("name", name).
|
|
|
|
Error("Invalid Layout: ", err)
|
|
|
|
return nil, chronograf.ErrLayoutInvalid
|
|
|
|
}
|
|
|
|
|
|
|
|
var layout chronograf.Layout
|
|
|
|
if err = json.Unmarshal(octets, &layout); err != nil {
|
|
|
|
s.Logger.
|
|
|
|
WithField("component", "apps").
|
|
|
|
WithField("name", name).
|
|
|
|
Error("Unable to read layout:", err)
|
|
|
|
return nil, chronograf.ErrLayoutInvalid
|
|
|
|
}
|
|
|
|
layouts[i] = layout
|
|
|
|
}
|
|
|
|
|
|
|
|
return layouts, nil
|
|
|
|
}
|
|
|
|
|
2017-10-24 22:50:11 +00:00
|
|
|
// Add is not support by BinLayoutsStore
|
|
|
|
func (s *BinLayoutsStore) Add(ctx context.Context, layout chronograf.Layout) (chronograf.Layout, error) {
|
2018-11-21 14:22:35 +00:00
|
|
|
return chronograf.Layout{}, fmt.Errorf("add to BinLayoutsStore not supported")
|
2016-11-15 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
2017-10-24 22:50:11 +00:00
|
|
|
// Delete is not support by BinLayoutsStore
|
|
|
|
func (s *BinLayoutsStore) Delete(ctx context.Context, layout chronograf.Layout) error {
|
2018-11-21 14:22:35 +00:00
|
|
|
return fmt.Errorf("delete to BinLayoutsStore not supported")
|
2016-11-15 01:07:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get retrieves Layout if `ID` exists.
|
2017-10-24 22:50:11 +00:00
|
|
|
func (s *BinLayoutsStore) Get(ctx context.Context, ID string) (chronograf.Layout, error) {
|
2016-11-15 01:07:38 +00:00
|
|
|
layouts, err := s.All(ctx)
|
|
|
|
if err != nil {
|
|
|
|
s.Logger.
|
|
|
|
WithField("component", "apps").
|
|
|
|
WithField("name", ID).
|
|
|
|
Error("Invalid Layout: ", err)
|
|
|
|
return chronograf.Layout{}, chronograf.ErrLayoutInvalid
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, layout := range layouts {
|
|
|
|
if layout.ID == ID {
|
|
|
|
return layout, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.Logger.
|
|
|
|
WithField("component", "apps").
|
|
|
|
WithField("name", ID).
|
|
|
|
Error("Layout not found")
|
|
|
|
return chronograf.Layout{}, chronograf.ErrLayoutNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update not supported
|
2017-10-24 22:50:11 +00:00
|
|
|
func (s *BinLayoutsStore) Update(ctx context.Context, layout chronograf.Layout) error {
|
2018-11-21 14:22:35 +00:00
|
|
|
return fmt.Errorf("update to BinLayoutsStore not supported")
|
2016-11-15 01:07:38 +00:00
|
|
|
}
|